配置環境:主機名ip地址角色數據目錄pg186.168.100.14主庫/PostgreSQL/9.6.1/datanpghs186.168.100.24standby/PostgreSQL/9.6.1/datahs主數據庫的配置:允許主庫接受流復制的連接pg_hba.conf中:host replication postgres 186.168.100.0/24 trustpostgresql.conf設置:listen_addresses = '*'max_wal_senders = 5wal_level = hot_standby重啟數據庫standby上的操作:在備庫生成基礎備份:[postgres@pghs data]$ pg_basebackup -h 186.168.100.14 -U postgres -F p -P -x -R -D /PostgreSQL/9.6.1/datahs -l postgresbackup2017020945089/45089 kB (100%), 2/2 tablespaces那么在/PostgreSQL/9.6.1/datahs 路徑下就看到了拷貝過來的文件等,因為使用了-R,所以有recovery.conf文件,內容:、standby_mode = 'on'PRimary_conninfo = 'user=postgres host=186.168.100.14 port=5432 sslmode=disable sslcompression=1'在啟動standby數據庫之前,需要修改postgresql.conf文件:hot_standby = on啟動standby:[postgres@pghs datahs]$ pg_ctl start -D /PostgreSQL/9.6.1/datahs/server starting[postgres@pghs datahs]$ FATAL: data directory "/PostgreSQL/9.6.1/datahs" has group or world accessDETAIL: Permissions should be u=rwx (0700).[postgres@pghs 9.6.1]$ chmod 700 datahs/[postgres@pghs 9.6.1]$ LOG: redirecting log output to logging collector processHINT: Future log output will appear in directory "pg_log".在主庫建一個表,然后插入幾條數據:postgres=# create table testhsb(id int,name varchar(10));CREATE TABLEpostgres=# insert into testhsb values (1,'test');INSERT 0 1備庫查詢:postgres=# select * from testhsb; id | name----+------ 1 | test(1 row)操作馬上就同步了在備庫嘗試修改:postgres=# delete from testhsb where id=1;ERROR: cannot execute DELETE in a read-only transaction
新聞熱點
疑難解答