Corveloper
Corveloper

Reputation: 3

Not able to connect to PostgreSQL database in Linux Fedora via VS Code terminal

I’m having trouble connecting to the PostgreSQL server on my local machine (Linux Fedora). I gathered that this isn’t a Django/Python issue, but rather a specific PostgreSQL problem.

I went through 3 different similar Stack Overflow questions, which strongly suggested changing the pg_hfa.conf file from ident to either true or md5 which I did in both cases. After this, I reloaded PostgreSQL server with the following in my Linux terminal sudo service postgresql restart

This method did not work when I ran python manage.py migrate in my VS Code console and continue to get the error django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL: Ident authentication failed for user "postgres".

Here is my pg_hfa.conf with the modifications I made

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
# local   replication     all                                   peer 
# host    replication     all             127.0.0.1/32          ident   
# host    replication     all             ::1/128               ident

This may his help or not, but here are the most recent logs for PostgreSQL

2025-01-06 16:26:51.273 MST [5612] LOG:  database system was shut down in recovery at 2025-01-06 14:08:38 MST
2025-01-06 16:26:51.275 MST [5612] LOG:  database system was not properly shut down; automatic recovery in progress
2025-01-06 16:26:51.288 MST [5612] LOG:  redo starts at 0/37DB2C8
2025-01-06 16:26:51.288 MST [5612] LOG:  invalid record length at 0/37DB300: expected at least 24, got 0
2025-01-06 16:26:51.288 MST [5612] LOG:  redo done at 0/37DB2C8 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2025-01-06 16:26:51.298 MST [5720] LOG:  checkpoint starting: end-of-recovery immediate wait
2025-01-06 16:26:51.309 MST [5720] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.002 s, sync=0.002 s, total=0.013 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB; lsn=0/37DB300, redo lsn=0/37DB300
2025-01-06 16:27:06.387 MST [6596] ERROR:  canceling statement due to user request
2025-01-06 16:27:06.387 MST [6584] ERROR:  canceling statement due to user request
2025-01-06 16:27:06.399 MST [5720] LOG:  shutting down
2025-01-06 16:27:06.401 MST [5720] LOG:  checkpoint starting: shutdown immediate
2025-01-06 16:27:06.420 MST [5720] LOG:  checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.021 s; sync files=0, longest=0.000 s, average=0.000 s; distance=0 kB, estimate=0 kB; lsn=0/37DB3B0, redo lsn=0/37DB3B0

The SO links to the similar problems are provided below.

psql: FATAL: Ident authentication failed for user "postgres"

Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails

PostgreSQL - FATAL: Ident authentication failed for user

Please I need some kind of guidance, I’ve been stuck on this particular issue for days now and examined several other similar problems via Googling Stack Overflow.

Upvotes: 0

Views: 125

Answers (2)

Corveloper
Corveloper

Reputation: 3

I think I figured out why I'm not able to run python manage.py migrate successfully. I did some research via Google.

It turns out my problem lies in the pg_hba.conf file. I think I have to replace Ident with md5, just have to figure where specifically to add md5

Upvotes: 0

Wexxor
Wexxor

Reputation: 1909

PostgreSQL installers often default to a 'secure' installation, with no external network access enabled. If you can connect to the database with a local psql client, try connecting using the same credentials as in your program. If that fails, you have identified the problem, PostgreSQL is not listening on external networks. You can correct this a few ways:

  • Modify your code to use a local (localhost or unix-domain socket) connection, rather than the network connection you currently have.
  • Modify the PostgreSQL configuration to listen on network interfaces. This is usually unnecessary for dev instances.
  • Use a development server on the network; this does require you to have network access to the development server to do any actual work.

I listed these in what I think would be easiest-to-hardest order, your experience may differ.

Upvotes: 0

Related Questions