[3] PostgreSQL 创建多个实例

创建多个 postgres 实例

postgres 可以通过指定不同的 data 目录以启动多个实例。1

首先登录 postgres 用户

1
sudo -su postgres

然后运行此命令初始化 data 目录

1
/usr/lib/postgresql/9.5/bin/pg_ctl init -D /var/lib/postgresql/9.5/main_2

会在 main_2 目录里生成 pg_hba.confpostgres.conf

需要在 postgres.conf 指定端口和 hba_path,(可以 copy 之前的 conf 文件 /etc/postgresql/9.5/main/postgresql.conf

将 conf 文件修改为

1
2
3
4
5
data_directory = '/var/lib/postgresql/9.5/main_2'
hba_file = '/var/lib/postgresql/9.5/main_2/pg_hba.conf'
ident_file = '/var/lib/postgresql/9.5/main_2/pg_ident.conf'
external_pid_file = '/var/run/postgresql/9.5-main-2.pid'
port = 5433

运行命令,启动 postgres

1
/usr/lib/postgresql/9.5/bin/pg_ctl -D /var/lib/postgresql/9.5/main_2 -l /var/log/postgresql/pg_5433.log start

参考

Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计