暗黑模式
rocky
ubuntu
https://www.postgresql.org/download/linux/ubuntu/
bash
# Automated repository configuration:
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
# Update the package lists:
sudo apt update
# Install the latest version of PostgreSQL:
# If you want a specific version, use 'postgresql-17' or similar instead of 'postgresql'
sudo apt -y install postgresql
apt-cache policy postgresql-17 # 查看所有版本
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
参数调优
其他服务器参数
bash
systemctl edit postgresql-17 # rocky
systemctl edit postgresql@17-main # ubuntu
1
2
2
bash
[Service]
LimitNOFILE=65536
1
2
2
bash
systemctl daemon-reexec
systemctl restart postgresql-17 # rocky
systemctl restart postgresql@17-main # ubuntu
1
2
3
2
3
bash
cat /proc/$(pgrep -u postgres -o postgres)/limits | grep "Max open files"
1
设置 pg_hba.conf
bash
vi /var/lib/pgsql/17/data/pg_hba.conf # rocky
vi /etc/postgresql/17/main/pg_hba.conf # ubuntu
1
2
2
host all all a.b.c.d/32 scram-sha-256
local all all peer #scram-sha-256 可选设置
1
2
3
2
3
设置 postgresql.conf
bash
# rocky: /var/lib/pgsql/17/data/postgresql.conf
# ubuntu: /etc/postgresql/17/main/postgresql.conf
listen_addresses = '*'
1
2
3
2
3
其他参数可以在线获取参考配置:https://pgtune.leopard.in.ua/
huge_pages 保持默认的 try
????
bash
systemctl restart postgresql-17 # rocky
systemctl restart postgresql@17-main # ubuntu
1
2
2
pg_basebackup
bash
# postgres user
pg_basebackup -h 1.2.3.4 -U postgres -D ./main -Fp -Xs -P
# root user
systemctl start postgresql@17-main
1
2
3
4
5
2
3
4
5
rocky:
- 数据目录:
/var/lib/psql/17/data
pg_hba.conf
pg_ident.conf
postgresql.conf
存放在 pg data 目录 ubuntu:- 数据目录:
/var/lib/postgresql/17/main
- 3个配置文件存放在
/etc/postgresql/17/main
WARNING
postgres/template1 coll
bash
# in postgres linux user
psql
# 如果提示 database "postgres" has a collation version mismatch
REINDEX DATABASE postgres;
ALTER DATABASE postgres REFRESH COLLATION VERSION;
psql -U postgres -d template1
# 如果提示 database "template1" has a collation version mismatch
REINDEX DATABASE template1;
ALTER DATABASE template1 REFRESH COLLATION VERSION;
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
tar
bash
# 验证版本兼容
sudo -u postgres pg_controldata /var/lib/postgresql/17/main
1
2
2