Doro's Python Life in Words Journal

Authentication error


After using the command python manage.py runserver in my Django blog application in the terminal, the terminal displays this error:

django.db.utils.OperationalError: connection failed: FATAL:  password authentication failed for user "blog"
connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "blog"

What is this error telling me?

This error indicates that the Django application is unable to authenticate with the PostgreSQL database because the credentials provided (username or password) are incorrect. Here's a breakdown of the error message:

    • django.db.utils.OperationalError
      This is a Django-specific error raised when there is an issue connecting to the database.

    • connection failed: FATAL: password authentication failed for user "blog"
      PostgreSQL is rejecting the connection attempt for the user "blog" because the password provided does not match the password configured for this user in the database.

    • connection to server at "127.0.0.1", port 5432
      The error occurred while attempting to connect to a PostgreSQL database running on the local machine (127.0.0.1) on port 5432 (the default PostgreSQL port).

Let's review

I integrated a Docker PostgreSQL image to store my data for this Django project. Every time I do work on my project, I have to start the PostgreSQL database with the help of Docker.

So, if I can't authenticate to the PostgreSQL database and I need to start the Docker container for my database, then we'll use the following command: docker start blog_db

But the command also gives an error in my case:

Error response from daemon: driver failed programming external connectivity on endpoint blog_db (5c7e8ec6968e0b268470615dba7a7a9af2dddec1cf3e7631eab062372a485d8c): failed to bind port 0.0.0.0:5432/tcp: Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use
Error: failed to start containers: blog_db

When checking the currently running Docker container on my machine with the command docker ps, there is no running container on my machine. The Docker container must be running somewhere else.

How to solve the problem?

To check which process is currently using the port: 5432 on my system, I use sudo lsof -i :5432.

    • lsof:
      Stands for List Open Files. It lists information about files that are currently open by processes. Since many system resources (like network sockets, pipes, etc.) are treated as files in Unix-based systems, lsof can also display information about network connections.

    • -i :5432:
      The -i option filters for network files. The :5432 specifies a particular port (port 5432, commonly used by PostgreSQL).

With this command I can see that port 5432 is still in use. To stop the currently running port, I used: sudo systemctl stop postgresql. This command stops the running Docker container.

Next, I can use the command to restart the Docker PostgreSQL container: docker start blog_db and use the command: python manage.py runserver to start the development server.


Designed by BootstrapMade and modified by DoriDoro