0

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.

18
  • You've got a lot of unnecessary details here and its hard to know whether you are talking about your production server or your local computer (or your USB flash drive?). Commented Jan 9 at 1:40
  • My apologies, I was trying to be as specific as I could. I'm talking about my local machine here, not my server. I just need some help with connecting to my PostgreSQL server database so that I migrate with Django. Commented Jan 9 at 1:59
  • AFAIK running your migrations in the console is a good way to go. Why do you need to "connect to my postgresql db and I need to do this before I run python manage.py migrate" Also, how are you connecting to your postgres DB? I assume you set up the connection information in your program using some kind of configuration ... did you do that? If so, what did you do? If not ... well ... needs doing. Commented Jan 9 at 2:17
  • @topsail. So I've been able to connect to and configure my postgres db before, but I was in WIndows OS, not Linux Fedora. Previously in Windows, I didn't use the CMD to connect to my postgres db, instead I took a shortcut by using pgAdmin, which I didn't like using. I prefer using the terminal with different CMD's, but was too complicated in the powershell. I agree though, this should be simple and quick fix. But I'm not familiar with Linux in general. I could go through the Fedora docs, but I would have to build another db, which is what I don't want to do. Commented Jan 9 at 2:27
  • You should probably start with the basics then: djangocentral.com/using-postgresql-with-django Assuming you have a running postgres server, it won't be all that different for Linux -- mostly you just need to provide the proper username / host / password and any other special connection properties (such as ports, encryption settings, or whatever else may be relevant). Commented Jan 9 at 2:32

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

7 Comments

I've come to the conclusion that I was incorrectly installing postgresql in VS Code when instead it should've been in the Linux terminal. My problem is that I'm not used to operating on a Linux, before I was on WIndows. The Fedora link I sent other person, I only copied/pasted the first two CMD. After that is where I get lost, since it's instructing the reader to create a new database. Whereas I already have an existing database.
Even installing Pycharm on Fedora is a headache. Fedora apparently doesn't support --collections or snap. Here is the full CMD $ sudo snap install pycharm-community --classic
@Corveloper a single line command at the terminal hardly sounds like a "headache". Let's show a little more grit here, what do you say? I use a debian based distro but at the end of the day you have to give yourself a little time to get used to the "linux way" and not complain that its not like Windows (likewise, I don't complain -- well, I try not to complain -- that Windows is not more like Linux! FWIW Jetbrains recommends using their toolbox app for all installs: Jetbrains-ToolboxApp
@topsail Not trying to complain here man. I was pointing the error I was getting when I ran the command in the Linux terminal. Here is the pasted error I get coreyj@syn-2600-6c67-107f-faf1-0000-0000-0000-15bc:~/Documents/Arborproject$ sudo dnf install pycharm-community --classic Unknown argument "--classic" for command "install". Add "--help" for more information about the arguments.. As you can see, I'm simply following the Fedora postgresql docs for installing postgresql and connecting to my db.
^ you said you are following the postgresql docs for installing postgres but your command is for installing pycharm? You didn't say there was an error before.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.