title: Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "postgres"
body: <p>How can how to access postgres databases from <strong>adminer</strong>?</p>
  
  <p>I have changed the password for the user <code>postgres</code>:</p>
  
  <pre><code>$ sudo -u postgres psql
  $ postgres=# alter user postgres password 'secret';
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>ALTER ROLE
  </code></pre>
  
  <p>But I still get this error on the adminer:</p>
  
  <pre><code>Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "postgres"
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/grvR3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/grvR3.png" alt="enter image description here"></a></p>
  
  <p>Any ideas why?</p>
  
  <p>I have these two users:</p>
  
  <pre><code>postgres=# \du
                                     List of roles
   Role name |                         Attributes                         | Member of 
  -----------+------------------------------------------------------------+-----------
   postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
   root      | Superuser, Create role, Create DB                          | {}
  </code></pre>
  
  <p>But I did not set password for user <code>root</code> when I created it with this command:</p>
  
  <pre><code>sudo -u postgres createuser --interactive
  </code></pre>
  
  <p>Output (<strong>why doesn't it ask for password??</strong>):</p>
  
  <pre><code>Enter name of role to add: root
  Shall the new role be a superuser? (y/n) y
  </code></pre>
  
  <p>But I still get the error on adminer:</p>
  
  <pre><code>Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "root"
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>THis is some bits of my <code>pg_hba.conf</code></p>
  
  <pre><code>sudo nano /etc/postgresql/9.5/main/pg_hba.conf
  
  # 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            md5
  # 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>I changed <code>peer</code> to <code>ident</code>:</p>
  
  <pre><code># Database administrative login by Unix domain socket
  local   all             postgres                                ident
  
  # TYPE  DATABASE        USER            ADDRESS                 METHOD
  
  # "local" is for Unix domain socket connections only
  local   all             all                                     ident
  # 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     postgres                                peer
  #host    replication     postgres        127.0.0.1/32            md5
  #host    replication     postgres        ::1/128                 md5
  </code></pre>
  
  <p>Then restarted my machine. but still no luck.</p>