python – Postgresql数据库随机崩溃

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

日志读取

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

相关文章

使用OpenCV实现视频去抖 整体步骤: 设置输入输出视频 寻找帧...
前言 对中文标题使用余弦相似度算法和编辑距离相似度分析进行...
前言 之前尝试写过一个爬虫,那时对网页请求还不够熟练,用的...
前言 本文使用Python实现了PCA算法,并使用ORL人脸数据集进行...
前言 使用opencv对图像进行操作,要求:(1)定位银行票据的...
天气预报API 功能 从中国天气网抓取数据返回1-7天的天气数据...