title: Django connection error - django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres"
body: <p>My Django project fails to connect to postgres database.</p>
  <blockquote>
  <p>django.db.utils.OperationalError: FATAL:  password authentication
  failed for user &quot;postgres&quot;</p>
  </blockquote>
  <p>The settings.py file:</p>
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': 'postgres',
          'USER': 'postgres',
          'PASSWORD': 'postgres',
          'HOST': '127.0.0.1',
          'PORT': 5432,
          'ATOMIC_REQUESTS': True
      }
  }
  </code></pre>
  <p>The <code>pg_hba.conf</code> file contents:</p>
  <p><a href="https://i.stack.imgur.com/Gybgy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gybgy.png" alt="enter image description here" /></a></p>
  <p>Before, the 'TRUSTED' method was set to 'PEER' by default. By it wasn't working that way. So I changed it to TRUSTED, ran <code>systemctl restart postgresql</code>, and it isn't working now either.</p>
  <p>I know that postgres password is empty by default, so I tried the following:</p>
  <pre><code>sudo -u postgres psql
  
  postgres=# ALTER USER postgres PASSWORD 'postgres';
  </code></pre>
  <p>The output was <code>ALTER ROLE</code>.
  But the error from Django still persists.</p>
  <p>I ran out of ideas. Any hints ?</p>
  <p>I ran out of ideas.</p>