title: Postgresql User not connecting to Database (Nginx Django Gunicorn)
body: <p>For almost a month now I have been struggling with this issue. Whenever I try to access my <strong>Django Admin</strong> page on production I get the following error:</p>
  
  <pre><code>OperationalError at /admin/login/
  FATAL:  password authentication failed for user "vpusr"
  FATAL:  password authentication failed for user "vpusr"
  </code></pre>
  
  <p>My <strong>production.py</strong> settings file is as follows:</p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql',
          'NAME': 'vpdb',
          'USER': 'vpusr',
          'PASSWORD': os.environ["VP_DB_PASS"],
          'HOST': 'localhost',
      }
  }
  </code></pre>
  
  <p>NOTE: the environment variable is working correctly. even if I put the normal password hard coded in there it doesn't work.</p>
  
  <p>Here is the <strong>list of databases</strong> with their owner:</p>
  
  <pre><code>                                  List of databases
     Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
  -----------+----------+----------+-------------+-------------+-----------------------
   postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
   template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
             |          |          |             |             | postgres=CTc/postgres
   template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
             |          |          |             |             | postgres=CTc/postgres
   vpdb      | vpusr    | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/vpusr            +
             |          |          |             |             | vpusr=CTc/vpusr
  </code></pre>
  
  <p>And here is the <strong>list of users</strong>:</p>
  
  <pre><code>                                   List of roles
   Role name |                         Attributes                         | Member of 
  -----------+------------------------------------------------------------+-----------
   postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
   vpusr     | Superuser, Create DB                                       | {}
  </code></pre>
  
  <p>As you can see I have also tried adding the roles of Superuser and Create DB to the vpusr but that did not have any effect.</p>
  
  <p>Even when I try to connect through the terminal like this I get the same error:</p>
  
  <pre><code>sudo -u postgres psql -U vpusr vpdb
  </code></pre>
  
  <p>I still get the error: <code>psql: FATAL:  Peer authentication failed for user "vpusr"</code></p>
  
  <p>When I do this command:</p>
  
  <pre><code>psql -U vpusr -h localhost vpdb
  </code></pre>
  
  <p>I properly connect to psql as vpusr.</p>
  
  <p><em>A few more notes:</em> I did delete the database, and the user and re created them. I made sure the password was correct.
  I use Gunicorn, Nginx, Virtualenv, Django, Postgres on an Ubuntu Server from Digital Ocean.</p>
  
  <p>Thank you in advance for taking the time to read this and helping me out! </p>
  
  <p><strong>EDIT:</strong> <strong>I have noticed that there are no migrations in my apps migration folder! Could it be that django or my user or postgres does not have permission to write the file</strong>?</p>
  
  <p>EDIT: <strong>NOTE: I CHANGED THE USER TO TONY</strong>
  In my postgres log file the following errors are found:</p>
  
  <pre><code>    2017-09-09 18:09:55 UTC [29909-2] LOG:  received fast shutdown request
  2017-09-09 18:09:55 UTC [29909-3] LOG:  aborting any active transactions
  2017-09-09 18:09:55 UTC [29914-2] LOG:  autovacuum launcher shutting down
  2017-09-09 18:09:55 UTC [29911-1] LOG:  shutting down
  2017-09-09 18:09:55 UTC [29911-2] LOG:  database system is shut down
  2017-09-09 18:09:56 UTC [2711-1] LOG:  database system was shut down at 2017-09-09 18:09:55 UTC
  2017-09-09 18:09:56 UTC [2711-2] LOG:  MultiXact member wraparound protections are now enabled
  2017-09-09 18:09:56 UTC [2710-1] LOG:  database system is ready to accept connections
  2017-09-09 18:09:56 UTC [2715-1] LOG:  autovacuum launcher started
  2017-09-09 18:09:57 UTC [2717-1] [unknown]@[unknown] LOG:  incomplete startup packet
  2017-09-09 18:10:17 UTC [2740-1] tony@vpdb LOG:  provided user name (tony) and authenticated user name (postgres) do not match
  2017-09-09 18:10:17 UTC [2740-2] tony@vpdb FATAL:  Peer authentication failed for user "tony"
  2017-09-09 18:10:17 UTC [2740-3] tony@vpdb DETAIL:  Connection matched pg_hba.conf line 90: "local   all             all                                     peer"
  </code></pre>
  
  <p>EDIT:</p>
  
  <p><strong>pg_hba.conf</strong> file:</p>
  
  <pre><code># Database administrative login by Unix domain socket
  local   all             postgres                                peer
  
  # TYPE  DATABASE        USER            ADDRESS                 METHOD
  
  # "local" is for Unix domain socket connections only
  local   all             all                                     peer
  # IPv4 local connections:
  host    all             all             127.0.0.1/32            password
  # IPv6 local connections:
  host    all             all             ::1/128                 md5
  # Allow replication connections from localhost, by a user with the
  # replication privilege.
  #local   replication     postgres                                peer
  #host    replication     postgres        127.0.0.1/32            md5
  #host    replication     postgres        ::1/128                 md5
  </code></pre>
  
  <p>what can you tell form this?</p>