title: OperationalError: ERROR: pgbouncer cannot connect to server
body: <p>I'm trying to do <code>python manage.py syncdb</code> on a Django installation, but I keep getting <code>OperationalError: ERROR:  pgbouncer cannot connect to server</code>. pgbouncer.log contains lines such as:</p>
  
  <pre><code>2017-09-19 19:44:15.107 1128 LOG C-0x8a9930: mydb/myuser@unix:6432 closing because: pgbouncer cannot connect to server (age=0)
  2017-09-19 19:44:15.107 1128 WARNING C-0x8a9930: mydb/myuser@unix:6432 Pooler Error: pgbouncer cannot connect to server
  2017-09-19 19:44:15.107 1128 LOG S-0x8c72e0: mydb/myuser@35.154.149.188:5432 new connection to server
  2017-09-19 19:44:15.107 1128 LOG C-0x8a9930: mydb/myuser@unix:6432 login failed: db=mydb user=myuser
  2017-09-19 19:44:30.108 1128 LOG S-0x8c72e0: mydb/myuser@35.154.149.188:5432 closing because: connect failed (age=15)
  </code></pre>
  
  <p>In case needed, <code>ps -aef | grep pgbouncer</code> yields:</p>
  
  <pre><code>postgres  1128     1  0 18:38 ?        00:00:00 /usr/sbin/pgbouncer -d /etc/pgbouncer/pgbouncer.ini
  myuser    1919  1533  0 19:45 pts/0    00:00:00 grep --color=auto pgbouncer
  </code></pre>
  
  <p>Moreover, <code>grep port /etc/pgbouncer/pgbouncer.ini</code> results in:</p>
  
  <pre><code>;;   dbname= host= port= user= password=
  mydb = host=xx.xxx.xxx.xxx port=5432 dbname=mydb
  ;forcedb = host=127.0.0.1 port=300 user=baz password=foo client_encoding=UNICODE datestyle=ISO connect_query='SELECT 1'
  listen_port = 6432
  </code></pre>
  
  <p>Lastly, the relevant parts of <code>settings.py</code> contain:</p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'NAME': 'mydb',
          'USER': 'myuser',
          'PASSWORD': 'mypassword',
          'HOST': '/var/run/postgresql',
          'PORT': '6432',
      }
  </code></pre>
  
  <hr>
  
  <p>I turned <code>log_connections</code> to <code>on</code> in postgresql.conf, restarted PG and tried again. Here's the relevant lines:</p>
  
  <pre><code>2017-09-20 07:50:59 UTC LOG:  database system is ready to accept connections
  2017-09-20 07:50:59 UTC LOG:  autovacuum launcher started
  2017-09-20 07:51:00 UTC LOG:  connection received: host=[local]
  2017-09-20 07:51:00 UTC LOG:  incomplete startup packet
  2017-09-20 07:51:00 UTC LOG:  connection received: host=[local]
  2017-09-20 07:51:00 UTC LOG:  connection authorized: user=postgres database=postgres
  2017-09-20 07:51:01 UTC LOG:  connection received: host=[local]
  2017-09-20 07:51:01 UTC LOG:  connection authorized: user=postgres database=postgres
  2017-09-20 07:51:01 UTC LOG:  connection received: host=[local]
  2017-09-20 07:51:01 UTC LOG:  connection authorized: user=postgres database=postgres
  </code></pre>
  
  <p>It seems the connection is going through, but the <code>user</code> and <code>database</code> name is <code>postgres</code>. Those credentials aren't what I supplied in <code>pgbouncer.ini</code>. </p>
  
  <p>However, explicitly adding <code>myuser</code> in the connection string described in <code>pgbouncer.ini</code> leads to: </p>
  
  <pre><code>2017-09-20 09:37:37 UTC FATAL:  Peer authentication failed for user "myuser"
  2017-09-20 09:37:37 UTC DETAIL:  Connection matched pg_hba.conf line 90: "local   all             all                                     peer"
  </code></pre>
  
  <p>Totally stumped.</p>