OperationalError:错误:pgbouncer无法连接到服务器

时间:2017-09-19 19:58:34

标签: postgresql pgbouncer

我正在尝试在Django安装上执行python manage.py syncdb,但我一直在OperationalError: ERROR: pgbouncer cannot connect to server。 pgbouncer.log包含如下行:

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)

如果需要,ps -aef | grep pgbouncer会产生:

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

此外,grep port /etc/pgbouncer/pgbouncer.ini会导致:

;;   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

最后,settings.py的相关部分包含:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
        'HOST': '/var/run/postgresql',
        'PORT': '6432',
    }

我在postgresql.conf中将log_connections转为on,重新启动PG并再次尝试。以下是相关部分:

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

似乎连接正在进行,但userdatabase名称为postgres。这些凭据不是我在pgbouncer.ini中提供的凭据。

但是,在myuser中描述的连接字符串中明确添加pgbouncer.ini会导致:

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"

完全难倒。

1 个答案:

答案 0 :(得分:1)

似乎错误的配置来自settings.py中的这一行:

'PORT': '6432',

我评论了它,pgbouncer开始工作了。

虽然我不确定'为什么'。

也许这个港口发生了碰撞;在我的案例中,Pgbouncer和PG共存于一台服务器上。我过去在不同的虚拟机上设置了它们(并且无需评论'PORT': '6432',