OperationalError: ERROR: pgbouncer cannot connect to server
OperationalError: ERROR: pgbouncer cannot connect to server
我正在尝试在 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"
完全被难住了。
settings.py
中的这一行似乎配置错误:
'PORT': '6432',
我评论了它,pgbouncer 开始工作了。
虽然我不确定'why'。
可能这个端口有冲突;在我的案例中,Pgbouncer 和 PG 在一台服务器上共存。我过去在不同的 VM 上设置它们没有任何障碍(并且不需要评论 'PORT': '6432',
)
我正在尝试在 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"
完全被难住了。
settings.py
中的这一行似乎配置错误:
'PORT': '6432',
我评论了它,pgbouncer 开始工作了。
虽然我不确定'why'。
可能这个端口有冲突;在我的案例中,Pgbouncer 和 PG 在一台服务器上共存。我过去在不同的 VM 上设置它们没有任何障碍(并且不需要评论 'PORT': '6432',
)