科学地增加postgresql最大连接数
PG配置文件路径
/etc/postgresql/9.3/main/postgresql.conf
首先如何查看最大连接数
This SQL will help you
select max_conn,used,res_for_super,max_conn-used-res_for_super res_for_normal
from
(select count(*) used from pg_stat_activity) t1,
(select setting::int res_for_super from pg_settings where name=$$superuser_reserved_connections$$) t2,
(select setting::int max_conn from pg_settings where name=$$max_connections$$) t3
Result:
max_conn | used | res_for_super | res_for_normal
---------+------+---------------+----------------
100 | 2 | 3 | 95
(1 row)
You can put this in shell:
#!/bin/bash
for (( c=1; c<=3600; c++ ))
do
gsql -U pgdba -W pgdba -p 6432 -c "sql" >> /home/pgdba/res_data.log
sleep 1 # once per second
done
or you can record the results into a table, then execute
postgres=# copy restbl to '/home/pgdba/res.csv' csv header;
to get result csv file.
其次如何科学设置
https://stackoverflow.com/a/32584211/2803340
Just increasing max_connections is bad idea. You need to increase shared_buffers and kernel.shmmax as well.
Considerations
max_connections determines the maximum number of concurrent connections to the database server. The default is typically 100 connections.
Before increasing your connection count you might need to scale up your deployment. But before that, you should consider whether you really need an increased connection limit.
Each PostgreSQL connection consumes RAM for managing the connection or the client using it. The more connections you have, the more RAM you will be using that could instead be used to run the database.
A well-written app typically doesn't need a large number of connections. If you have an app that does need a large number of connections then consider using a tool such as pg_bouncer which can pool connections for you. As each connection consumes RAM, you should be looking to minimize their use.
How to increase max connections
1. Increase max_connection and shared_buffers
in /var/lib/pgsql/data/postgresql.conf
change
max_connections = 100
shared_buffers = 24MB
to
max_connections = 300
shared_buffers = 80MB
The shared_buffers configuration parameter determines how much memory is dedicated to PostgreSQL to use for caching data.
- If you have a system with 1GB or more of RAM, a reasonable starting
value for shared_buffers is 1/4 of the memory in your system. - it's unlikely you'll find using more than 40% of RAM to work better
than a smaller amount (like 25%) - Be aware that if your system or PostgreSQL build is 32-bit, it might
not be practical to set shared_buffers above 2 ~ 2.5GB. - Note that on Windows, large values for shared_buffers aren't as
effective, and you may find better results keeping it relatively low
and using the OS cache more instead. On Windows the useful range is
64MB to 512MB.
2. Change kernel.shmmax
You would need to increase kernel max segment size to be slightly larger
than the shared_buffers.
In file /etc/sysctl.conf set the parameter as shown below. It will take effect when postgresql reboots (The following line makes the kernel max to 96Mb)
kernel.shmmax=100663296
References
How to increase max connections in postgres
Postgres Max Connections And Shared Buffers
科学地增加postgresql最大连接数的更多相关文章
- postgresql 最大连接数相关
PG中有一张表记录着当前有多少连接 表名:pg_stat_activity 查询当前连接数: select count(1) from pg_stat_activity; 查询最大连接数 show m ...
- linux下postgresql的连接数配置
1.查询当前连接数: select count(*) from pg_stat_activity; 2.查询最大连接数 show max_connections; 3.修改最大连接数 SHOW con ...
- PostgreSQL之连接数修改
当前总共正在使用的连接数 select count(1) from pg_stat_activity; 显示系统允许的最大连接数 show max_connections; 显示系统保留的用户数 sh ...
- PostgreSQL问题解决--连接数过多
I am trying to connect to a Postgresql database, I am getting the following Error: Error:org.postgre ...
- postgresql修改最大连接数
1.合适的最大连接数 used_connections/max_connections在85%左右2.修改最大连接数postgresql最大连接数默认为1001)打开postgresql配置文件vim ...
- 增加oracle数据库最大连接数
这几天碰到系统不能登陆的情况,初步判断可能是数据库连接满了,(后来检查不是这个原因),做了一次增加数据库最大连接数操作.操作步骤如下 操作系统:Red Hat Enterprise Linux Ser ...
- 修改ArcSDE的最大连接数
我们大体都知道ArcSDE的连接数有 48 的限制,很多人也知道这个参数可以修改,并且每种操作系统能支持的最大连接数是不同的. 如果应用报错:超出系统最大连接数该如何处理? 两种解决办法: 第一,首先 ...
- 修改mysql最大连接数的方法
MYSQL数据库安装完成后,默认最大连接数是100,一般流量稍微大一点的论坛或网站这个连接数是远远不够的,增加默认MYSQL连接数的方法有两个 方法一:进入MYSQL安装目录 打开MYSQL配置文件 ...
- 正确修改MySQL最大连接数的三种好用方案
以下的文章主要介绍的是正确修改MySQL最大连接数的三种好用方案,我们大家都知道MySQL数据库在安装完之后,默认的MySQL数据库,其最大连接数为100,一般流量稍微大一点的论坛或网站这个连接数是远 ...
随机推荐
- 利用tornado实现表格文件预览
项目介绍 本文将介绍笔者的一个项目,主要是利用tornado实现表格文件的预览,能够浏览的表格文件支持CSV以及Excel文件.预览的界面如下: 下面我们将看到这个功能是如何通过tornado ...
- DSAPI 字符串和文件转Md5字符串
方法列表: 字符串转MD5字符串(ByVal 要转换的字符串 As String, Optional 转换格式 As MD5格式 = MD5格式.小写32位) As String 文件转MD5字符串( ...
- VUE v-for问题
今天写一个拖动然后使装备交换的功能,在背包格子里 发现直接设置Bags数组的项,v-for渲染出来的列表不会对应改变,只有设置值才会改变 有点拗口,贴代码吧 var repear = this.Bag ...
- 【译】最大限度地降低多线程 C# 代码的复杂性
分支或多线程编程是编程时最难最对的事情之一.这是由于它们的并行性质所致,即要求采用与使用单线程的线性编程完全不同的思维模式.对于这个问题,恰当类比就是抛接杂耍表演者,必须在空中抛接多个球,而不要让它们 ...
- MySQL索引初探
一.什么是索引? 帮助数据库系统实现高效获取数据的数据结构 索引可以帮助我们快速地定位到数据而不需要每次搜索的时候都遍历数据库中的每一行. 二.常见实现方式有哪些? 常见索引模型有三种:哈希表.有序数 ...
- js 3D旋转效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 微信小程序之菜鸟入门教学(二)
昨天学习了一些简单的概念,今天开始实际操作,通过搭建简单的计算器来学习小程序的架构 一.小程序框架 程序框架如上图所示.由此可见,框架的基本构成为: 1. app.js . app.wxss 2. a ...
- idea Maven项目找不到相关依赖包(红色波浪线)
前两天做项目的时候,把团队其他人的代码从git同步到自己电脑上,出现了冲突.发现是maven依赖出现了问题,之前的截图找不到了,我就简单描述一下.就是下图箭头所示位置出现了红色波浪线. 在网上找了很多 ...
- python带参函数(计算器脚本解释标注)
环境 python 3.* def operator(op1,op2,opfu): #定义符号函数,op1表示第一个运算数值,op2表示第二个,opfu表示运算符号 if opfu not in '+ ...
- scp远程拷贝文件及文件夹
scp : 远程copy 命令 -r : 递归copy 从Linux Copy 到 Linux 从Linux Copy 到 Windows (当前目录使用. 就可以了) scp -r root@10. ...