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

Tuning Your PostgreSQL Server

科学地增加postgresql最大连接数的更多相关文章

  1. postgresql 最大连接数相关

    PG中有一张表记录着当前有多少连接 表名:pg_stat_activity 查询当前连接数: select count(1) from pg_stat_activity; 查询最大连接数 show m ...

  2. linux下postgresql的连接数配置

    1.查询当前连接数: select count(*) from pg_stat_activity; 2.查询最大连接数 show max_connections; 3.修改最大连接数 SHOW con ...

  3. PostgreSQL之连接数修改

    当前总共正在使用的连接数 select count(1) from pg_stat_activity; 显示系统允许的最大连接数 show max_connections; 显示系统保留的用户数 sh ...

  4. PostgreSQL问题解决--连接数过多

    I am trying to connect to a Postgresql database, I am getting the following Error: Error:org.postgre ...

  5. postgresql修改最大连接数

    1.合适的最大连接数 used_connections/max_connections在85%左右2.修改最大连接数postgresql最大连接数默认为1001)打开postgresql配置文件vim ...

  6. 增加oracle数据库最大连接数

    这几天碰到系统不能登陆的情况,初步判断可能是数据库连接满了,(后来检查不是这个原因),做了一次增加数据库最大连接数操作.操作步骤如下 操作系统:Red Hat Enterprise Linux Ser ...

  7. 修改ArcSDE的最大连接数

    我们大体都知道ArcSDE的连接数有 48 的限制,很多人也知道这个参数可以修改,并且每种操作系统能支持的最大连接数是不同的. 如果应用报错:超出系统最大连接数该如何处理? 两种解决办法: 第一,首先 ...

  8. 修改mysql最大连接数的方法

    MYSQL数据库安装完成后,默认最大连接数是100,一般流量稍微大一点的论坛或网站这个连接数是远远不够的,增加默认MYSQL连接数的方法有两个 方法一:进入MYSQL安装目录 打开MYSQL配置文件 ...

  9. 正确修改MySQL最大连接数的三种好用方案

    以下的文章主要介绍的是正确修改MySQL最大连接数的三种好用方案,我们大家都知道MySQL数据库在安装完之后,默认的MySQL数据库,其最大连接数为100,一般流量稍微大一点的论坛或网站这个连接数是远 ...

随机推荐

  1. 解决在C#(.net)按字节数截取字符串最后出现乱码的问题

    最近需要用到按字节数截取字符串.在网上找了很多方法. Encoding.Default.GetString采用的DefaultEncoding.UTF8.GetBytes采用的是utf-8编码.这样当 ...

  2. [TCP/IP] 数据链路层-ethereal 抓包分析数据帧

    1.下载 http://dx1.pc0359.cn/soft/e/ethereal.rar 2.打开软件,指定抓取的网卡,下面是我抓取自己的主要网卡数据 3.开启个ping命令 , 不停的ping一台 ...

  3. 了解spring

    一.spring简介 Spring是一个JavaEE轻量级的一站式的开发框架(spring的可插拔特性,企业用于整合其他框架)轻量级:使用最少的代码启动程序,根据所需选择功能选择模块使用一站式:提供了 ...

  4. 【spring实战第五版遇到的坑】3.2中配置关系映射时,表名和3.1中不一样

    3.2章中按照书中的步骤写好相应类的映射关系,发现启动时,之前在3.1章中建的表全部被删重新建立了,并且Ingredient表的数据没了,由于使用了JPA,默认使用的是hibernate,在启动时会删 ...

  5. [笔记]记录原开发工作在base命名空间下扩展的属性与方法

    前言 该笔记只是为了记录以前开发使用的方式. 处理命名空间namespace /** * 处理命名空间 * @param {string} 空间名称,可多个 * @return {object} 对象 ...

  6. 结对编程项目总结 by:陈宏伟&刘益

    结对编程项目在欢快的国庆假期中也顺利结束了.从最初拿到结对编程项目的思考,再到一步一步实现,中间经历了一个漫长的过程.在我和队友的多次协商下,最终我们还是选择使用基于python来实现这一次结对编程项 ...

  7. Python第十五天 datetime模块 time模块 thread模块 threading模块 Queue队列模块 multiprocessing模块 paramiko模块 fabric模块

    Python第十五天  datetime模块 time模块   thread模块  threading模块  Queue队列模块  multiprocessing模块  paramiko模块  fab ...

  8. hbase 工作原理

    一.HBASE介绍HBase是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBase技术可在廉价PC Server上搭建大规模结构化的存储集群.HBase的目标是存储并处理大型数据,具体 ...

  9. JavaScript(四)变量

    变量的声明 在JavaScript程序中,使用一个变量之前应当使用关键字var进行声明,如下所示:var num;var sum; 也可以写成var num,sum,avg;如果只是声明变量而没有给变 ...

  10. 网络浅析(<<网络是怎么连接的>> 总结)

    概要 基本概念 网线 集线器 交换机 路由器 路由器和交换机 路由器和集线器 接入网 IP DNS 以太网 协议栈 网络连接过程 通信过程(浏览器 -> 服务器) 客户端和服务端 服务端的套接字 ...