加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – Postgresql数据库随机崩溃

发布时间:2020-12-16 22:53:48 所属栏目:Python 来源:网络整理
导读:我真的不知道问题是什么. 日志读取 FATAL: sorry,too many clients already 一遍又一遍地.起初我认为有时连接徘徊或没有正确关闭所以我通过连接到数据库并检查在任何给定时间有多少打开的连接测试,并且答案一直是1. 我试图连接到使用数据库的网站,我设法瞥见

我真的不知道问题是什么.

日志读取

FATAL: sorry,too many clients already

一遍又一遍地.起初我认为有时连接徘徊或没有正确关闭所以我通过连接到数据库并检查在任何给定时间有多少打开的连接测试,并且答案一直是1.

我试图连接到使用数据库的网站,我设法瞥见2或3个打开的连接,这些连接在页面加载完成后立即关闭.

我的另一个猜测是,有时网站的并发连接会出现峰值,导致数据库停止接受新连接,并且不知何时不允许删除当前连接.

我没有写任何与数据库连接的代码,我使用的是一个非常香草的Django(1.7)后端来处理所有的连接.

在搜索谷歌时我找不到任何东西,有没有人遇到过任何问题?

编辑:

Database configuration is here(PasteBin)

重要组成部分:

port = 26445                # (change requires restart)
max_connections = 500           # (change requires restart)
unix_socket_directory = '/home/clearintent/webapps/norr2_db/run'        # (change requires restart)

shared_buffers = 32MB           # min 128kB
                    # (change requires restart)
log_destination = 'stderr'      # Valid values are combinations of
logging_collector = on          # Enable capturing of stderr and csvlog
log_directory = 'pg_log'        # directory where log files are written,log_filename = 'postgresql-%a.log'  # log file name pattern,log_truncate_on_rotation = on       # If on,an existing log file with the
log_rotation_age = 1d           # Automatic rotation of logfiles will
log_rotation_size = 0           # Automatic rotation of logfiles will
datestyle = 'iso,mdy'
lc_messages = 'C'           # locale for system error message
lc_monetary = 'C'           # locale for monetary formatting
lc_numeric = 'C'            # locale for number formatting
lc_time = 'C'               # locale for time formatting
default_text_search_config = 'pg_catalog.english'
最佳答案
听起来有些东西正在抨击你的PostgreSQL,但仅此错误并不会导致数据库崩溃.
它只是意味着最新的连接尝试超过了允许的与DB的并行连接数量,并且被拒绝.

但是,如果要每分钟转储连接数量,可以使用此脚本

#!/bin/bash

function spew_connections() {
# Run psql on local if trust or auth is set.
# Change dbadmin and dbname accordingly.
/usr/bin/psql -d dbname -U dbadmin -w -t -c "SELECT localtimestamp(2),count(*) FROM pg_stat_activity;"
}

echo -n `spew_connections` >> /tmp/connections
echo >> /tmp/connections

然后,每分钟使用crontab执行它

crontab -e
*/1 * * * * /path/to/executable/script

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读