Postgresql 操作错误:错误:pgbouncer无法连接到服务器
我正试图在Django安装上执行Postgresql 操作错误:错误:pgbouncer无法连接到服务器,postgresql,pgbouncer,Postgresql,Pgbouncer,我正试图在Django安装上执行python manage.py syncdb,但我不断收到OperationalError:ERROR:pgbouncer无法连接到服务器。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
python manage.py syncdb
,但我不断收到OperationalError:ERROR:pgbouncer无法连接到服务器
。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\u 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
似乎连接正在进行,但是用户
和数据库
名称是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"
完全被难住了。在
settings.py
中,这一行似乎产生了错误配置:
'PORT': '6432',
我对它进行了评论,pgbouncer开始工作
虽然我不知道“为什么”
也许这个港口发生了碰撞;在我的例子中,Pgbouncer和PG共存于一台服务器上。过去我在不同的虚拟机上设置了它们,没有任何问题(并且不需要注释
“端口”:“6432”,
)PostgreSQL日志对此有何评论?目标是否正在运行PostgreSQL?您没有阅读我评论的第一部分。打开log\u connections
至并检查PostgreSQL log.settings.py已将套接字目录定义为主机,但您在/etc/pgbouncer/pgbouncer.ini
-将/var/run/PostgreSQL
更改为127.0.0.1
请在settings.py
@VaoTsun:ah不,这不起作用。为了记录,我在pgbouncer.ini中设置了unix\u socket\u dir=/var/run/postgresql
,所以socket应该可以工作。当我执行sudo服务pgbouncer start
时,可能pgbouncer.ini
没有正确加载?要么是这样,要么就是权限问题。你感觉如何?ps-aef | grep pgbouncer
显示正确的配置。您的身份验证文件中有什么内容?。。