在仪表板中,我看到当前有 22 个打开的数据库实例连接,阻止新连接并出现错误:
remaining connection slots are reserved for non-replication superuser connections.
我正在从 EC2 实例上运行的 Web 服务 API 访问数据库,并始终保持最佳实践:
Connection connection = DriverManager.getConnection(URL, USER_NAME, PASSWORD);
Class.forName(DB_CLASS);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(SQL_Query_String);
...
resultSet.close();
statement.close();
connection.close();
我可以在代码中做其他事情吗?
我应该在数据库管理中做些其他事情吗?
有没有办法定期关闭连接?
最佳答案
亚马逊必须根据每个模型对一定内存和连接数的要求来设置连接数
MODEL max_connections innodb_buffer_pool_size
--------- --------------- -----------------------
t1.micro 34 326107136 ( 311M)
m1-small 125 1179648000 ( 1125M, 1.097G)
m1-large 623 5882511360 ( 5610M, 5.479G)
m1-xlarge 1263 11922309120 (11370M, 11.103G)
m2-xlarge 1441 13605273600 (12975M, 12.671G)
m2-2xlarge 2900 27367833600 (26100M, 25.488G)
m2-4xlarge 5816 54892953600 (52350M, 51.123G)
但如果你愿意,你可以通过
将最大连接大小更改为自定义值从 RDS 控制台 > 参数组 > 编辑参数,
您可以将 max_connections 参数的值更改为自定义值。
要定期关闭连接,您可以像这样设置一个 cron 作业。
select pg_terminate_backend(procpid)
from pg_stat_activity
where usename = 'yourusername'
and current_query = '<IDLE>'
and query_start < current_timestamp - interval '5 minutes';
关于sql - AWS RDS PostgreSQL 错误 "remaining connection slots are reserved for non-replication superuser connections",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38555679/