PgBouncer:关闭原因:客户端关闭请求和关闭原因:服务器不干净

2024-05-16 07:31:29 发布

您现在位置:Python中文网/ 问答频道 /正文

虽然我的web应用程序工作正常,数据写入数据库时没有问题。我查看了PgBouncer的日志,它显示了大量的

pgbouncer_1        | 2021-04-13 10:45:47.061 UTC [1] LOG C-0x7f7f368200e0: my_affiliate/write_user@172.24.0.8:39444 closing because: client close request (age=0s)
pgbouncer_1        | 2021-04-13 10:45:47.061 UTC [1] LOG S-0x7f7f36819100: my_affiliate/write_user@172.24.0.11:5432 closing because: unclean server (age=0s)
pgbouncer_1        | 2021-04-13 10:45:50.272 UTC [1] LOG C-0x7f7f368200e0: my_affiliate/write_user@172.24.0.8:39456 login attempt: db=my_affiliate user=write_user tls=no
pgbouncer_1        | 2021-04-13 10:45:50.273 UTC [1] LOG S-0x7f7f36819100: my_affiliate/write_user@172.24.0.11:5432 new connection to server (from 172.24.0.4:34854)
pgbouncer_1        | 2021-04-13 10:45:50.282 UTC [1] LOG C-0x7f7f368200e0: my_affiliate/write_user@172.24.0.8:39456 closing because: client close request (age=0s)
pgbouncer_1        | 2021-04-13 10:45:50.282 UTC [1] LOG S-0x7f7f36819100: my_affiliate/write_user@172.24.0.11:5432 closing because: unclean server (age=0s)
pgbouncer_1        | 2021-04-13 10:45:57.770 UTC [1] LOG C-0x7f7f368200e0: my_affiliate/write_user@172.24.0.8:39672 login attempt: db=my_affiliate user=write_user tls=no
pgbouncer_1        | 2021-04-13 10:45:57.771 UTC [1] LOG S-0x7f7f36819100: my_affiliate/write_user@172.24.0.11:5432 new connection to server (from 172.24.0.4:35070)
pgbouncer_1        | 2021-04-13 10:45:57.781 UTC [1] LOG C-0x7f7f368200e0: my_affiliate/write_user@172.24.0.8:39672 closing because: client close request (age=0s)
pgbouncer_1        | 2021-04-13 10:45:57.781 UTC [1] LOG S-0x7f7f36819100: my_affiliate/write_user@172.24.0.11:5432 closing because: unclean server (age=0s)

我在想,这是PgBouncer的正常情况吗

我只是在数据库上执行正常的读/写操作,并进行适当的连接清理

conn = None
cursor = None

try:        
    conn = psycopg2.connect(constants.POSTGRES_CONNECTION_STRING)        
    cursor = conn.cursor()
    
    ...
    
    conn.commit()
except Exception as e:
    ...
finally:
    if cursor is not None:
        cursor.close()
    
    if conn is not None:
        conn.close()

我在docker中的设置也非常简单

Dockerfile

FROM edoburu/pgbouncer:1.15.0

COPY pgbouncer.ini /etc/pgbouncer/
COPY auth_file /etc/pgbouncer/

pgbouncer.ini

**
#pgbouncer.ini
# Description
# Config file is in “ini” format. Section names are between “[” and “]”.
# Lines starting with “;” or “#” are taken as comments and ignored.
# The characters “;” and “#” are not recognized when they appear later in the line.
[databases]
* = host=postgres port=5432
[pgbouncer]
# Generic settings

# Uncomment this if you want loggin.
#- LOGFILE=/var/log/pgbouncer/pgbouncer.log

listen_addr = 0.0.0.0
auth_file = /etc/pgbouncer/auth_file
auth_type = md5
ignore_startup_parameters = extra_float_digits
# Log settings
admin_users = pgbouncer
# Connection sanity checks, timeouts
# TLS settings
# Dangerous timeouts
################## end file ##################

你知道为什么我收到大量的日志消息吗

  • 关闭原因:客户端关闭请求
  • 关闭原因:服务器不干净

有没有担心过

谢谢


Tags: logcloseageservermyconncursorfile