自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

PostgreSQL數(shù)據(jù)庫單機(jī)擴(kuò)展為流復(fù)制

數(shù)據(jù)庫 PostgreSQL
以下是PostgreSQL數(shù)據(jù)庫單機(jī)擴(kuò)展為流復(fù)制,希望對小伙伴們有所幫助。

[[194921]]

1. 在standby服務(wù)器安裝postgres數(shù)據(jù)庫,不需要初始化.

安裝過程詳見:http://www.cnblogs.com/ilifeilong/p/6979288.html

2. 在primary服務(wù)器創(chuàng)建具有REPLICATION權(quán)限的復(fù)制用戶

  1. postgres=# CREATE ROLE repl WITH REPLICATION PASSWORD ‘repl‘ LOGIN; 

3. 允許復(fù)制用戶遠(yuǎn)程連接到primary服務(wù)器

  1. $ grep "^host" pg_hba.conf 
  2. host    all             all             127.0.0.1/32            trust 
  3. host    replication             repl             0.0.0.0/0               md5  
  4. host    all             all             ::1/128                 trust 

4. 在primary服務(wù)器設(shè)置流復(fù)制相關(guān)的參數(shù)

  1. $ mkdir /usr/local/pgsql/arch  
  2. $ egrep "archive_mode|max_wal_senders|wal_keep_segments|archive_command|wal_level|hot_standby" postgresql.conf 
  3. al_level = hot_standby            # minimal, archive, hot_standby, or logical 
  4. archive_mode = on        # enables archiving; offonor always 
  5. archive_command = ‘test ! -f /usr/local/pgsql/arch/%f && cp %p /usr/local/pgsql/arch/%f‘         
  6. max_wal_senders = 5        # max number of walsender processes 
  7. wal_keep_segments = 30        # in logfile segments, 16MB each; 0 disables 
  8. hot_standby = on            # "on" allows queries during recovery 
  9. #hot_standby_feedback = off        # send info from standby to prevent 

5. 重新啟動primary服務(wù)器進(jìn)程

  1. $ pg_ctl stop -m fast 
  2. $ pg_ctl start 

6. 對primary服務(wù)器做一個全備并傳輸?shù)絪tandby服務(wù)器

  • 在primary服務(wù)器通過pg_(start|stop)_backup函數(shù)進(jìn)行備份
  1. postgres=# SELECT pg_start_backup(‘label‘, true); 
  2.  pg_start_backup  
  3. ----------------- 
  4.  7/E6000060 
  5. (1 row) 
  6. $ rsync -az --progress ${PGDATA} postgres@10.189.100.195:/usr/local/pgsql/ --exclude postmaster.pid 
  7. postgres=# SELECT pg_stop_backup(); 
  8. NOTICE:  pg_stop_backup complete, all required WAL segments have been archived 
  9.  pg_stop_backup  
  10. ---------------- 
  11.  7/E60005C8 
  12. (1 row) 

在standby服務(wù)器通過pg_basebackup命令進(jìn)行備份,要求standby的PGDATA目錄為空

  1. $ pg_basebackup --host=10.189.102.118 --username=repl --port=5432 --label=backup --verbose --progress --pgdata=/usr/local/pgsql/data --checkpoint=fast --format=p --xlog-method=stream 
  2. Password:  
  3. transaction log start point: 7/EA000028 on timeline 1 
  4. pg_basebackup: starting background WAL receiver 
  5. 65933562/65933562 kB (100%), 1/1 tablespace                                          
  6. transaction log end point: 7/EA000830 
  7. pg_basebackup: waiting for background process to finish streaming ... 
  8. pg_basebackup: base backup completed 

7. 設(shè)置standby數(shù)據(jù)庫復(fù)制相關(guān)參數(shù),使得standby失效轉(zhuǎn)移后可以作為主庫工作

  1. $ mkdir /usr/local/pgsql/arch 
  2. $ egrep "archive_mode|max_wal_senders|wal_keep_segments|archive_command|wal_level|hot_standby" postgresql.conf 
  3. wal_level = hot_standby                 # minimal, archive, hot_standby, or logical 
  4. archive_mode = on               # enables archiving; offonor always 
  5. archive_command = ‘test ! -f /usr/local/pgsql/arch/%f && cp %p /usr/local/pgsql/arch/%f‘ 
  6. max_wal_senders = 5             # max number of walsender processes 
  7. wal_keep_segments = 30          # in logfile segments, 16MB each; 0 disables 
  8. hot_standby = on                        # "on" allows queries during recovery 
  9. #hot_standby_feedback = off             # send info from standby to prevent 

8. 在standby文件創(chuàng)建恢復(fù)文件

  1. $ cat recovery.conf  
  2. restore_command = ‘cp /usr/local/pgsql/arch/%f "%p"‘ 
  3. standby_mode = ‘on‘ 
  4. primary_conninfo = ‘user=repl password=repl host=10.189.102.118 port=5432 sslmode=disable sslcompression=1‘ 
  5. archive_cleanup_command = ‘pg_archivecleanup -d /usr/local/pgsql/arch %r >> /usr/local/pgsql/arch/archive_cleanup.log‘ 
  6. trigger_file = ‘/usr/local/pgsql/data/trigger_active_standby‘ 

9. 啟動standby數(shù)據(jù)庫進(jìn)程,自動啟動流復(fù)制

  1. $ pg_ctl start -w 
  2. waiting for server to start....LOG:  could not create IPv6 socket: Address family not supported by protocol 
  3. LOG:  redirecting log output to logging collector process 
  4. HINT:  Future log output will appear in directory "pg_log"
  5.  done 
  6. server started 

10. 檢查primary和standby數(shù)據(jù)庫的延遲

  • 通過函數(shù)和系統(tǒng)表查看
  1. edbstore=# select * from pg_stat_replication;           #在primary主庫查看 
  2. -[ RECORD 1 ]----+------------------------------ 
  3. pid              | 15013 
  4. usesysid         | 19206 
  5. usename          | repl 
  6. application_name | walreceiver 
  7. client_addr      | 10.189.100.195 
  8. client_hostname  |  
  9. client_port      | 56072 
  10. backend_start    | 2017-06-13 08:10:35.400508-07 
  11. backend_xmin     |  
  12. state            | streaming 
  13. sent_location    | 7/EC01A588 
  14. write_location   | 7/EC01A588 
  15. flush_location   | 7/EC01A588 
  16. replay_location  | 7/EC01A588 
  17. sync_priority    | 0 
  18. sync_state       | async 
  19.  
  20. edbstore=# SELECT pg_current_xlog_location();                      #在primary主庫查看 
  21.  pg_current_xlog_location  
  22. -------------------------- 
  23.  7/EC01A588 
  24. (1 row) 
  25.  
  26. postgres=# select pg_last_xlog_receive_location(),pg_last_xlog_replay_location(),pg_last_xact_replay_timestamp();     #在standby備庫查看 
  27.  pg_last_xlog_receive_location | pg_last_xlog_replay_location | pg_last_xact_replay_timestamp  
  28. -------------------------------+------------------------------+------------------------------- 
  29.  7/EC01A588                    | 7/EC01A588                   | 2017-06-13 08:25:20.281568-07 
  30. (1 row) 
  • 通過進(jìn)程查看
  1. $ ps -ef | grep sender | grep -v grep #在primary庫查看  
  2. postgres 15013 24883 0 08:10 ? 00:00:00 postgres: wal sender process repl 10.189.100.195(56072) streaming 7/EC01A668  
  3. $ ps -ef | grep receiver | grep -v grep #在standby庫查看  
  4. postgres 12857 12843 0 08:10 ? 00:00:00 postgres: wal receiver process streaming 7/EC01A668 
責(zé)任編輯:武曉燕 來源: 碼迷
相關(guān)推薦

2017-06-16 21:36:14

2024-01-18 08:00:00

PostgreSQLPgvector

2019-11-20 09:08:46

PostgreSQL數(shù)據(jù)庫

2023-07-24 09:00:00

數(shù)據(jù)庫

2011-04-15 13:41:27

SqlServer數(shù)據(jù)復(fù)制

2022-01-10 07:59:14

PostgreSQl 主從流復(fù)制歸檔配置

2024-03-04 10:48:15

PostgreSQL數(shù)據(jù)庫

2021-07-07 21:07:16

PostgreSQL架構(gòu)容災(zāi)庫

2011-03-08 08:49:55

MySQL優(yōu)化單機(jī)

2017-10-13 15:06:18

數(shù)據(jù)庫PostgreSQL特性

2010-05-26 10:15:11

MySQL數(shù)據(jù)庫

2022-10-12 13:33:25

PostgreSQL數(shù)據(jù)庫

2024-11-19 13:11:19

2010-08-27 09:59:51

SQL Server

2011-05-17 13:43:23

Oracle數(shù)據(jù)庫

2011-05-17 11:19:39

rcp數(shù)據(jù)庫

2010-03-02 15:16:23

Ubuntu Post

2025-04-02 08:30:00

IvorySQLOraclePostgreSQL

2011-03-25 13:08:19

PostgreSQL數(shù)

2019-02-15 14:59:09

華為云
點贊
收藏

51CTO技術(shù)棧公眾號