最近监控系统的数据库监控总是延迟,查看日志报错:
2015-08-27 10:20:19,534 ERROR Traceback (most recent call last):
File "oracle_mon.py",line 306,in <module>
update_status(ip,'stop',timer.end_date)
File "oracle_mon.py",line 285,in update_status
pg.db.update("oracle_mon",where=where,status=status,stat_date=status_date)
File "/usr/lib/python2.7/site-packages/web/db.py",line 881,in update
db_cursor = self._db_cursor()
File "/usr/lib/python2.7/site-packages/web/db.py",line 566,in _db_cursor
return self.ctx.db.cursor()
File "/usr/lib/python2.7/site-packages/web/db.py",line 507,in _getctx
self._load_context(self._ctx)
File "/usr/lib/python2.7/site-packages/web/db.py",line 516,in _load_context
ctx.db = self._connect_with_pooling(self.keywords)
File "/usr/lib/python2.7/site-packages/web/db.py",line 970,in _connect_with_pooling
conn = DB._connect_with_pooling(self,keywords)
File "/usr/lib/python2.7/site-packages/web/db.py",line 563,in _connect_with_pooling
return self._pooleddb.connection()
File "/usr/lib/python2.7/site-packages/DBUtils-1.1-py2.7.egg/DBUtils/PooledDB.py",line 331,in connection
con = self.steady_connection()
File "/usr/lib/python2.7/site-packages/DBUtils-1.1-py2.7.egg/DBUtils/PooledDB.py",line 279,in steady_connection
*self._args,**self._kwargs)
File "/usr/lib/python2.7/site-packages/DBUtils-1.1-py2.7.egg/DBUtils/SteadyDB.py",line 134,in connect
failures,ping,closeable,*args,**kwargs)
File "/usr/lib/python2.7/site-packages/DBUtils-1.1-py2.7.egg/DBUtils/SteadyDB.py",line 186,in __init__
self._store(self._create())
File "/usr/lib/python2.7/site-packages/DBUtils-1.1-py2.7.egg/DBUtils/SteadyDB.py",line 190,in _create
con = self._creator(*self._args,**self._kwargs)
File "/usr/lib64/python2.7/site-packages/psycopg2/__init__.py",line 179,in connect
connection_factory=connection_factory,async=async)
OperationalError: 致命错误: 已保留的连接位置为执行非复制请求的超级用户预留
查到数据库使用的活动连接数为90左右,而pg的默认最大连接数MAX_CONNECTION=100,怀疑是数据库连接数过多导致报错。
事实果然如此,老数据库的MAX_CONNECTION=200,并没有使用默认的100。
解决办法:修改配置文件(postgresql.conf)中的默认最大连接数MAX_CONNECTION=200,重启数据库即可。