【发布时间】:2017-09-22 17:32:15
【问题描述】:
我正在尝试在 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
似乎连接正在通过,但user 和database 的名称是postgres。这些凭据不是我在pgbouncer.ini 中提供的。
但是,在pgbouncer.ini 中描述的连接字符串中显式添加myuser 会导致:
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"
完全被难住了。
【问题讨论】:
-
PostgreSQL 日志对此有何评论? PostgreSQL 是否在目的地运行?
-
您没有阅读我评论的第一部分。将
log_connections转为on并检查PostgreSQL 日志。 -
settings.py 已将套接字目录定义为主机,但您在
/etc/pgbouncer/pgbouncer.ini中有 localhost - 请在settings.py中将/var/run/postgresql更改为127.0.0.1 -
@VaoTsun:啊,不,那没用。作为记录,我在 pgbouncer.ini 中设置了
unix_socket_dir = /var/run/postgresql,所以套接字应该可以工作。当我执行sudo service pgbouncer start时,可能pgbouncer.ini没有正确加载?要么,要么这里有权限问题。你有什么感觉? -
ps -aef | grep pgbouncer显示正确的配置。你在auth_hba_file有什么?..
标签: postgresql pgbouncer