標籤:
主庫配置
pg_hba.conf
host replication all 10.2.0.0/0 trust
postgresql.conf
listen_addresses = ‘*‘max_wal_senders = 5wal_level = hot_standby
重啟主庫
從庫配置
安裝
使用yum安裝 (找源 http://yum.postgresql.org/)
yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpmyum install postgresql95-server postgresql95-contrib
產生基礎備份(主要資料庫IP 10.2.0.14)
pg_basebackup -h 10.2.0.14 -U postgres -F p -P -x -R -D /var/lib/pgsql/9.5/data/ -l postgresbackup20160506
查看組建檔案(注意檔案的許可權,使用者組)
ls -l /var/lib/pgsql/9.5/data -rw-------. 1 postgres postgres 197 5月 6 13:11 backup_label.olddrwx------. 6 postgres postgres 50 5月 6 13:11 basedrwx------. 2 postgres postgres 4096 5月 6 13:38 globaldrwx------. 2 postgres postgres 17 5月 6 13:11 pg_clogdrwx------. 2 postgres postgres 6 5月 6 13:11 pg_commit_tsdrwx------. 2 postgres postgres 6 5月 6 13:11 pg_dynshmem-rw-------. 1 postgres postgres 4214 5月 6 13:11 pg_hba.conf-rw-------. 1 postgres postgres 1636 5月 6 13:11 pg_ident.confdrwx------. 2 postgres postgres 56 5月 6 13:11 pg_logdrwx------. 4 postgres postgres 37 5月 6 13:11 pg_logicaldrwx------. 4 postgres postgres 34 5月 6 13:11 pg_multixactdrwx------. 2 postgres postgres 17 5月 6 13:38 pg_notifydrwx------. 2 postgres postgres 6 5月 6 13:11 pg_replslotdrwx------. 2 postgres postgres 6 5月 6 13:11 pg_serialdrwx------. 2 postgres postgres 6 5月 6 13:11 pg_snapshotsdrwx------. 2 postgres postgres 6 5月 6 13:11 pg_statdrwx------. 2 postgres postgres 6 5月 6 13:11 pg_stat_tmpdrwx------. 2 postgres postgres 17 5月 6 13:11 pg_subtransdrwx------. 2 postgres postgres 6 5月 6 13:11 pg_tblspcdrwx------. 2 postgres postgres 6 5月 6 13:11 pg_twophase-rw-------. 1 postgres postgres 4 5月 6 13:11 PG_VERSIONdrwx------. 3 postgres postgres 89 5月 6 13:29 pg_xlog-rw-------. 1 postgres postgres 88 5月 6 13:11 postgresql.auto.conf-rw-------. 1 postgres postgres 21756 5月 6 13:38 postgresql.conf-rw-------. 1 postgres postgres 59 5月 6 13:38 postmaster.opts-rw-------. 1 postgres postgres 87 5月 6 13:38 postmaster.pid-rw-r--r--. 1 postgres postgres 140 5月 6 13:35 recovery.conf
cat recovery.conf standby_mode = ‘on‘primary_conninfo = ‘user=postgres host=10.2.0.14 port=5432 sslmode=disable sslcompression=1‘
修改 postgresql.conf(否則啟動失敗 錯誤:postgresql-9.5.service start operation timed out. Terminating.)
hot_standdby=on
啟動從庫
systemctl start postgresql-9.5.servicesystemctl enable postgresql-9.5.service
測試
主庫操作從庫查看同步結果
psql -U postgres postgres=# \lList of databasesName | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+-----------------------postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| | | | | postgres=CTc/postgrestemplate1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| | | | | postgres=CTc/postgrestest | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows)postgres=# \c testest=# create table test01(id int primary key,note text);CREATE TABLEtest=# \dList of relationsSchema | Name | Type | Owner --------+--------+-------+----------public | test01 | table | postgres(1 row)test=# insert into test01 values(1,‘1111‘);INSERT 0 1test=# insert into test01 values(2,‘2222‘);INSERT 0 1test=# insert into test01 values(4,‘4444‘);INSERT 0 1test=# insert into test01 values(5,‘5555‘);INSERT 0 1test=# \qselect * from test01;id | note ----+------1 | 11112 | 22224 | 44445 | 5555
CentOS7 PostgreSQL 主從配置( 一)