PostgreSQL学习第十六篇 异步流复制Hot Standby的示例

前端之家收集整理的这篇文章主要介绍了PostgreSQL学习第十六篇 异步流复制Hot Standby的示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. 配置环境:
  2.  
  3. 主机名
  4. IP地址
  5. 角色
  6. 数据目录
  7. pg
  8. 186.168.100.14
  9. 主库
  10. /Postgresql/9.6.1/datan
  11. pghs
  12. 186.168.100.24
  13. standby
  14. /Postgresql/9.6.1/datahs
  15.  
  16. 数据库的配置:
  17. 允许主库接受流复制的连接pg_hba.conf中:
  18. host replication postgres 186.168.100.0/24 trust
  19.  
  20. postgresql.conf设置:
  21. listen_addresses = '*'
  22. max_wal_senders = 5
  23. wal_level = hot_standby
  24. 重启数据库
  25.  
  26.  
  27. standby上的操作:
  28. 在备库生成基础备份:
  29. [postgres@pghs data]$ pg_basebackup -h 186.168.100.14 -U postgres -F p -P -x -R -D /Postgresql/9.6.1/datahs -l postgresbackup20170209
  30. 45089/45089 kB (100%),2/2 tablespaces
  31.  
  32.  
  33. 那么在/Postgresql/9.6.1/datahs 路径下就看到了拷贝过来的文件等,因为使用了-R,所以有recovery.conf文件内容:、
  34. standby_mode = 'on'
  35. primary_conninfo = 'user=postgres host=186.168.100.14 port=5432 sslmode=disable sslcompression=1'
  36.  
  37. 在启动standby数据库之前,需要修改postgresql.conf文件
  38. hot_standby = on
  39.  
  40. 启动standby
  41. [postgres@pghs datahs]$ pg_ctl start -D /Postgresql/9.6.1/datahs/
  42. server starting
  43. [postgres@pghs datahs]$ FATAL: data directory "/Postgresql/9.6.1/datahs" has group or world access
  44. DETAIL: Permissions should be u=rwx (0700).
  45.  
  46. [postgres@pghs 9.6.1]$ chmod 700 datahs/
  47. [postgres@pghs 9.6.1]$ LOG: redirecting log output to logging collector process
  48. HINT: Future log output will appear in directory "pg_log".
  49.  
  50.  
  51. 在主库建一个表,然后插入几条数据:
  52. postgres=# create table testhsb(id int,name varchar(10));
  53. CREATE TABLE
  54. postgres=# insert into testhsb values (1,'test');
  55. INSERT 0 1
  56.  
  57. 备库查询
  58. postgres=# select * from testhsb;
  59. id | name
  60. ----+------
  61. 1 | test
  62. (1 row)
  63.  
  64. 操作马上就同步了
  65. 在备库尝试修改
  66. postgres=# delete from testhsb where id=1;
  67. ERROR: cannot execute DELETE in a read-only transaction

猜你在找的Postgre SQL相关文章