在Docker容器中修改PostgresSQL最大连接数

pclin
160
2024-07-03

在Docker容器中修改PostgresSQL最大连接数

1.首先查询当前最大连接数

-- 查看最大连接数
show max_connections;

2.然后找到你的 postgresql.conf 文件

--可以用sql命令查询文件所在位置

SHOW config_file;

3、进入docker容器

docker exec -it [容器id] /bin/bash

4.修改配置文件

vim /var/lib/postgresql/data/postgresql.conf

将文件中 max_connections=100 修改为需要的数值

如果提示bash: vim: command not found请看文章最后内容,安装vim命令

4.然后重启postgres服务

docker容器的重启命令

docker restart [容器id]

非docker安装的重启命令

sudo service postgresql restart

附Postgres中常用sql命令

-- 1、查看最大连接数

show max_connections;

--  2、查看当前连接数

select count(*) from pg_stat_activity;

-- 3、查看系统保留的用户数

 show superuser_reserved_connections;

 

--  4、查看按用户分组统计连接数

select usename, count(*) from pg_stat_activity group by usename order by count(*) desc;

-- 查看pg库设置max_connections的配置文件的路径 需要管理员执行

SHOW config_file;

-- name = 配置项名字

-- setting = 配置项的value

-- boot_val = 配置项的初始化value

-- sourcefile = 配置项所在的配置文件的路径

select name, setting, boot_val, reset_val, sourcefile from pg_settings where name = 'max_connections';

-- 查询当前活跃连接数

select count(1) from pg_stat_activity;

-- 查看当前配置的最大连接数

show max_connections;

-- 查看指定IP的活跃连接信息

select  * from  pg_stat_activity where  client_addr = '192.168.148.100';

	

-- 按IP地址查询当前活跃的连接数

select   client_addr, count(1) num from  pg_stat_activity group by   client_addr order by  num desc;

	

-- 按用户查询当前活跃的连接数

select usename, count(1) num from  pg_stat_activity group by  usename order by  num desc;

-- 查找 postgresql.conf 文件

SHOW config_file;

解决 bash: vim: command not found

# apt-get update
# apt-get install vim

————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/zixiao_love/article/details/127688995

动物装饰