cp /usr/lib/systemd/system/postgresql-12.service /usr/lib/systemd/system/pg02.service
修改PGDATA的值
vi /usr/lib/systemd/system/pg02.service # Location of database directory Environment=PGDATA=/var/lib/pgsql/12/data02/
不用手動創建data02目錄,初始化數據庫實例時會自動生成 /var/lib/pgsql/12/data02/
初始化數據庫實例
[root@centos7-6 ~]# /usr/pgsql-12/bin/postgresql-12-setup initdb pg02
修改監聽和端口
cd /var/lib/pgsql/12/data02/ vi postgresql.conf listen_addresses = '*' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) port = 5433
vi pg_hba.conf host all all 0.0.0.0/0 md5
systemctl enable pg02
systemctl start pg02
ps -ef|grep postgres
根據端口登錄不同的數據庫
psql -p 5432 -dpostgres psql -p 5433 -dpostgres