日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯網營銷解決方案
PostgreSQL安裝及StreamingReplication配置詳解

PostgreSQL安裝及Streaming Replication配置是本文我們主要要介紹的內容,因為項目需要搭建postgres環(huán)境,并要求具有一定的可靠性。所以筆者在搭建這個環(huán)境的同時把步驟及命令記錄下來的。筆者是DB2 DBA.但現在項目準備從DB2遷移到postgresql. postgresql筆者也是剛剛接觸.筆者以后會把學到的關于postgresql的知識,以及DB2遷移postgresql過程中遇到的問題及經驗總結出來,陸續(xù)整理成文檔.,然后和有同樣需求的朋友進行交流,希望能夠對您有所幫助。

 
 
 
  1. -------------------------------------------------------
  2. >>>>>>>>>INSTALL<<<<<<<<<<<<<
  3. --primary 10.4.5.94
  4. --standby 10.4.5.93
  5. --standby 10.4.5.91
  6. psql (PostgreSQL) 9.0.4
  7. -------------------------------------------------------
  8. cd /root/postgresql-9.0.4
  9. ./configure --with-wal-segsize=32 --with-wal-blocksize=16
  10. gmake
  11. gmake install
  12. adduser postgres
  13. mkdir -p /usr/local/pgsql/data
  14. mkdir -p /usr/local/pgsql/etc
  15. chown postgres /usr/local/pgsql/data
  16. chown postgres /usr/local/pgsql/etc
  17. chown postgres /pg_data_logs
  18. cd /pg_data_logs/
  19. mkdir pg_xlog
  20. chown postgres pg_xlog/
  21. su - postgres
  22. /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data --xlogdir=/pg_data_logs/pg_xlog
  23. mv /usr/local/pgsql/data/*.conf /usr/local/pgsql/etc
  24. exit (su - root)
  25. cp /root/postgresql-9.0.4/contrib/start-scripts/linux /etc/init.d/postgresd
  26. vi /etc/init.d/postgresd  修改如下部分,用-c config_file指定postgresql.conf的位置:
  27. ===============================================================
  28.   start)
  29.         echo -n "Starting PostgreSQL: "
  30.         test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
  31.         su - $PGUSER -c "$DAEMON -D '$PGDATA' -c config_file=/usr/local/pgsql/etc/postgresql.conf &" >>$PGLOG 2>&1
  32.         echo "ok"
  33.         ;;
  34.   restart)
  35.         echo -n "Restarting PostgreSQL: "
  36.         su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
  37.         test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
  38.         su - $PGUSER -c "$DAEMON -D '$PGDATA' -c config_file=/usr/local/pgsql/etc/postgresql.conf &" >>$PGLOG 2>&1
  39.         echo "ok"
  40.         ;;
  41. ===============================================================
  42. vi /usr/local/pgsql/etc/postgresql.conf  修改如下部分:
  43. ===============================================================
  44. #------------------------------------------------------------------------------
  45. # FILE LOCATIONS
  46. #------------------------------------------------------------------------------
  47. # The default values of these variables are driven from the -D command-line
  48. # option or PGDATA environment variable, represented here as ConfigDir.
  49. #data_directory = 'ConfigDir'           # use data in another directory
  50.                                         # (change requires restart)
  51. hba_file = '/usr/local/pgsql/etc/pg_hba.conf'     # host-based authentication file
  52.                                         # (change requires restart)
  53. ident_file = '/usr/local/pgsql/etc/pg_ident.conf' # ident configuration file
  54.                                         # (change requires restart)
  55. # If external_pid_file is not explicitly set, no extra PID file is written.
  56. #external_pid_file = '(none)'           # write an extra PID file
  57.                                         # (change requires restart)
  58. ===============================================================
  59. /etc/init.d/postgresd start
  60. -------------------------------------------------------
 
 
 
  1. >>>>>>>>>Streaming Replication<<<<<<<<<<<<<
  2. -------------------------------------------------------
  3. --IN ALL SERVER:
  4. 修改訪問控制
  5. vi /usr/local/pgsql/etc/pg_hba.conf
  6. ***加一行
  7. host all all 10.4.5.0/24 password
  8. host all all 10.4.2.0/24 password
  9. 修改監(jiān)聽范圍
  10. vi /usr/local/pgsql/etc/postgresql.conf
  11. 修改listen_addresses = ‘localhost’為listen_addresses = ‘*’,如果前面有#號則需要刪除#號
  12. 重啟
  13. /etc/init.d/postgresd restart
  14. --IN PRIMARY SERVER:
  15. 設置同步賬號
  16. psql
  17. create user repl superuser login password 'meiyoumima';
  18. 修改訪問控制
  19. vi /usr/local/pgsql/etc/pg_hba.conf
  20. ***添加以下內容
  21. host replication repl 10.4.5.93/32 password
  22. host replication repl 10.4.5.91/32 password

修改postgresql服務配置文件

 
 
 
  1. vi /usr/local/pgsql/etc/postgresql.conf
  2. ####Add by paolo for replications
  3. wal_level = hot_standby
  4. archive_mode = on
  5. archive_command = 'cp -i %p /pg_data_logs/archivedir/%f 
  6. #archive_timeout = 600
  7. archive_timeout = 86400
  8. max_wal_senders = 5
  9. wal_keep_segments = 32

建立歸檔目錄

mkdir -p /pg_data_logs/archivedir

重啟

/etc/init.d/postgresd restart

--IN STANDBY SERVER:

修改postgresql服務配置文件

 
 
 
  1. vi /usr/local/pgsql/etc/postgresql.conf
  2. #Add by paolo for replications
  3. wal_level = hot_standby
  4. hot_standby = on
  5. vi /usr/local/pgsql/etc/recovery.conf
  6. #Add by paolo for replications
  7. restore_command = 'cp /pg_data_logs/archivedir/%f %p' 
  8. archive_cleanup_command = 'pg_archivecleanup /pg_data_logs/archivedir %r'
  9. standby_mode = 'on'
  10. primary_conninfo = 'host=10.4.5.94 port=5432 user=repl password=meiyoumima'
  11. trigger_file = '/home/postgres/trigger_activestb'

建立歸檔目錄

mkdir -p /pg_data_logs/archivedir

停止postgres

/etc/init.d/postgresd stop

刪除原數據目錄下數據文件

 
 
 
  1. exit (su - root)
  2. cd /usr/local/pgsql/
  3. rm -rf data/
  4. mkdir data
  5. chown postgres data
  6. chmod -R 700 data/
 
 
 
  1. >>>>>>>>>>>>>>傳送數據文件到StandBy并啟動集群<<<<<<<<<<<<<<<<<
  2. --IN PRIMARY
  3. su - postgres
  4. psql -c "SELECT pg_start_backup('label',true);"
  5. cd /usr/local/pgsql/
  6. scp -r data/ postgres@10.4.5.93:/usr/local/pgsql/
  7. scp -r data/ postgres@10.4.5.91:/usr/local/pgsql/
  8. --IN STANDBY
  9. su - postgres
  10. cd /usr/local/pgsql/data
  11. rm postmaster.pid
  12. ln -s /usr/local/pgsql/etc/recovery.conf recovery.conf
  13. cd pg_xlog
  14. mv * /pg_data_logs/archivedir/
  15. /etc/init.d/postgresd start
  16. --IN PRIMARY
  17. su - postgres
  18. psql -c "SELECT * from pg_stop_backup();"

重啟

 
 
 
  1. /etc/init.d/postgresd restart
  2. -------------------------------------------------------
  3. >>>>>>>>>pg_archivecleanup inatall<<<<<<<<<<<<<
  4. -------------------------------------------------------
  5. su - root
  6. cd postgresql-9.0.4/contrib/pg_archivecleanup/
  7. make
  8. make install

關于PostgreSQL安裝及Streaming Replication配置就介紹到這里了,希望本次的介紹能夠對您有所收獲!


分享名稱:PostgreSQL安裝及StreamingReplication配置詳解
網站鏈接:http://www.5511xx.com/article/dpidphg.html