在 CentOS 上优化 pgAdmin(通常指 pgAdmin 4),需要从 系统层面、pgAdmin 配置、PostgreSQL 服务端、使用习惯 四个方面来做。下面给你一套实用优化方案。
systemctl disable --now firewalld # 如果不用防火墙
systemctl disable --now postfix
减少资源占用。
pgAdmin / PostgreSQL 都依赖大量连接:
vi /etc/security/limits.conf
添加:
* soft nofile 65536
* hard nofile 65536
重启生效。
pgAdmin 本身不重 IO,但 PostgreSQL backend 很吃 IO。
sudo yum install -y https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-1-1.noarch.rpm
sudo yum install -y pgadmin4-web
sudo /usr/pgadmin4/bin/setup-web.sh
优点:
pgAdmin → Preferences → Browser
Preferences → Dashboards
几百张表时,pgAdmin 会非常卡
建议:
shared_buffers = 25% RAM
work_mem = 16MB~64MB
maintenance_work_mem = 512MB
effective_cache_size = 70% RAM
重载:
SELECT pg_reload_conf();
VACUUM ANALYZE;
否则 pgAdmin 查询计划会非常慢。
location / {
proxy_pass http://127.0.0.1:5050;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
并启用:
| 现象 | 原因 | 解决 |
|---|---|---|
| 打开表很慢 | 默认加载全部数据 | 限制行数 |
| 展开 schema 卡 | 表太多 | 过滤 |
| 浏览器卡死 | WebGL / 图表 | 关 Dashboard |
| 登录慢 | LDAP / 认证慢 | 用本地账号 |
你可以告诉我:
我可以直接给你 针对性配置或一键优化脚本。