首页 > 数据库 >如何在不停机的情况下向现有的 PostgreSQL 级联复制添加额外的从属服务器?

如何在不停机的情况下向现有的 PostgreSQL 级联复制添加额外的从属服务器?

时间:2024-07-22 11:31:41浏览次数:8  
标签:10 级联 slave postgres 192.168 下向 pg conf PostgreSQL

步骤 1:将第 3 个从属信息放在从属 2 的 pg_hba.conf 中,如果这里没有 recovery.conf 文件,请立即创建

cat recovery.conf
standby_mode='on'
primary_conninfo = 'host=192.168.2.3 port=5432 user=postgres password=postgres'

#restore_command = 'cp /archive/%f "%p"'
#archive_cleanup_command = '/usr/pgsql-9.4/bin/pg_archivecleanup /archive %r'
recovery_target_timeline = 'latest'

Pg_hba.conf:

host    replication     postgres            192.168.2.5/32  trust
host    replication     postgres            192.168.2.4/32  trust

步骤2. reload或者重新启动slave_2服务器:

Option 1: From the command-line shell
su - postgres
/usr/bin/pg_ctl -D /DATA reload

Option 2: Using SQL
SELECT pg_reload_conf();

步骤3:暂停slave_2服务器,然后检查是否暂停

select pg_wal_replay_pause();
select pg_is_wal_replay_paused();

注意:如果您的服务器正在测试,则在暂停slave_2后,只需在主服务器上创建一些表,因为恢复后您需要检查slave_2和slave_3是否复制了数据 

步骤4:在slave_2上进行物理备份并将其发送到slave_3:

ON SLAVE_3:
/usr/pgsql-10/bin/pg_ctl -D /var/lib/pgsql/10/data/ stop  -----stop the slave_3 cluster
rm -vfr /var/lib/pgsql/10/data/*      ---remove the old data's
FROM SLAVE_2:
rsync -cva --inplace /DATA/* [email protected]:/var/lib/pgsql/10/data/
slave_3 pg_hba.conf:
host    replication     postgres            192.168.2.4/3 2  trust
Slave_3 postgresql.conf:
listen_addresses = 'localhost,192.168.2.5'
port = 5432 
wal_level = 'hot_standby'       # minimal, archive, hot_standby, or logical
max_wal_senders = 10             # max number of walsender processes
                                # (change requires restart)
wal_keep_segments = 64          # in logfile segments, 16MB each; 0 disables
hot_standby = on
archive_mode = on               # allows archiving to be done
archive_command =  'rsync -av %p /archive/%f && rsync -av %p [email protected]:/archive/%f' # or 'cd .'
slave_3 recovery.conf:
cat /var/lib/pgsql/10/data/recovery.conf
standby_mode = 'on'      # to enable the standby (read-only) mode.
primary_conninfo = 'host=192.168.2.4 port=5432 user=postgres password=postgres'
                         # to specify a connection info to the master node.

步骤5:恢复slave_2服务器然后重新启动slave_3服务器:

At slave_2:
select pg_wal_replay_resume();
At Slave_3:
/usr/pgsql-10/bin/pg_ctl -D /var/lib/pgsql/10/data/ start

监控 SLAVE_3 和 MASTER 服务器:

ON SLAVE_3:
postgres=# select * from pg_stat_wal_receiver ;
  pid  |  status   | receive_start_lsn | receive_start_tli | received_lsn | received_tli |       last_msg_send_time       |      last_msg_receipt_time       | latest_end_lsn |         latest_end_time          | slot_name |                                                                                             conninfo                                                                                             
-------+-----------+-------------------+-------------------+--------------+--------------+--------------------------------+----------------------------------+----------------+----------------------------------+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 39970 | streaming | 0/1A000000        |                 1 | 0/1A000000   |            1 | 2018-03-15 16:39:03.4787+05:30 | 2018-03-15 16:39:01.426584+05:30 | 0/1A30B500     | 2018-03-15 16:37:03.161287+05:30 |           | user=postgres password=******** dbname=replication host=192.168.2.4 port=5432 fallback_application_name=walreceiver sslmode=prefer sslcompression=1 krbsrvname=postgres target_session_attrs=any
(1 row)
ON MASTER:
select * from pg_stat_replication ;
  pid  | usesysid | usename  | application_name | client_addr | client_hostname | client_port |          backend_start           | backend_xmin |   state   |  sent_lsn  | write_lsn  | flush_lsn  | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state 
-------+----------+----------+------------------+-------------+-----------------+-------------+----------------------------------+--------------+-----------+------------+------------+------------+------------+-----------+-----------+------------+---------------+------------
 14640 |       10 | postgres | walreceiver      | 192.168.2.3 |                 |       57716 | 2018-03-15 09:33:48.617764+05:30 |              | streaming | 0/1A30B500 | 0/1A30B500 | 0/1A30B500 | 0/1A30B500 |           |           |            |             0 | async
(1 row)

 

标签:10,级联,slave,postgres,192.168,下向,pg,conf,PostgreSQL
From: https://www.cnblogs.com/wonchaofan/p/18315712

相关文章

  • PostgreSQL安装异常:Problem running post-install step
    1.错误详情安装PostgreSQL时快要完成的时候抛出异常Problemrunningpost-installstep.Installationmaynotcompletecorrectlty.Thedatabaseclusterinitialisationfailed.2.解决方法以管理员权限打开PowerShell找到PostgreSQL安装目录,进入bin文件夹(例子中是D:\Post......
  • postgresql数据库sql常用函数
    常用sql写法postgresql基本数据类型类型描述INTEGER整数类型,-2,147,483,648到2,147,483,647BIGINT大整数类型,-9,223,372,036,854,775,808到9,223,372,036,854,775,807SMALLINT小整数类型,-32,768到32,767DECIMAL精确数字类型,可定义精度和标度NUMERIC高精度数字类型,与......
  • 2024“钉耙编程”中国大学生算法设计超级联赛(1)结题报告1 2 8
    1001循环位移字符串哈希将a展开*2对于每个长度为len_a的序列进行一次hash存储并将其插入set中对于b进行一次哈希对于每个长度为len_a的连续子串进行一次查询点击查看代码#include<bits/stdc++.h>usingnamespacestd;//22222constintN=5e6+10;constintp1......
  • 2024“钉耙编程”中国大学生算法设计超级联赛(1)
    发挥相当差,最好笑的是1h没写出一个三维偏序、30min没写出一个字符串哈希。甚至1h没意识到组合数式子推错了。A我写了点阴间东西。假设模式串为ABC,考虑一个形如ABCABCABC的东西,如果长度是\(x\),会贡献\(x-n+1\)个子串。枚举\(i\),从\(i\)把\(T\)分成两部分,一部分......
  • 循环位移(2024“钉耙编程”中国大学生算法设计超级联赛(1))
    #include<bits/stdc++.h>#defineendl'\n'usingll=longlong;typedefunsignedlonglongull;usingnamespacestd;voidGordenGhost();constintN=4e6+7;constintP=131;ullp[N],an[N],bn[N];intn;voidinit(stringa,stringb){......
  • 2024“钉耙编程”中国大学生算法设计超级联赛(1)
    Preface唐完了的一集,被前中期题花式腐乳以至于中期一度被同校队伍打出\(n+3\)最后4h时堪堪写完8个题,最后1h冲刺众数那个题然后写一半方法假了直接下班当然还有个难绷的是传送那个题和我今年给新生拉的数据结构专题的一个题几乎一样,把代码拉来改下输入输入就过了,12min抢......
  • Postgresql主键自增的方法
    Postgresql主键自增的方法一.方法(一)使用 serialPRIMARYKEY插入数据 二.方法(二)......
  • leetcode 1459 矩形面积(postgresql)
    需求表:Points±--------------±--------+|ColumnName|Type|±--------------±--------+|id|int||x_value|int||y_value|int|±--------------±--------+id是该表主键每个点都用二维坐标(x_value,y_value)表示写一个SQL语句,报告由表......
  • 使用ElementUI和element-china-area-data库实现省市区三级联动组件封装
    使用ElementUI和element-china-area-data库实现省市区三级联动组件封装在前端开发中,省市区三级联动是一个常见的需求。今天我们将使用Vue.js和ElementUI组件库,结合element-china-area-data库,来实现一个省市区三级联动的组件。这个组件不仅可以提高用户体验,还能大大简化我们的代码......
  • postgresql删除用户
    背景**角色与用户**:在PostgreSQL中,用户和组的概念是通过“角色”来统一实现的。角色可以有登录权限(在这种情况下,它们通常被称为“用户”),也可以没有(在这种情况下,它们通常用于权限管理,类似于组)。**依赖关系**:在删除角色之前,需要确保该角色没有被其他数据库对象(如表、视图、......