PostgreSQL 中的流式复制

mic*_*iam 7 postgresql replication

我正在尝试在一台机器上设置两台 PostgreSQL 服务器并执行流式复制。我已经成功过一次,但是当我按照完全相同的步骤再次尝试时它不起作用..这些是步骤:我有 $PGDATA = home/postgresql/9.1/data 和 $STANDBY = home/postgresql/9.1 /数据2

  1. 设置两个节点:
    initdb -D $PGDATA
    initdb -D $STANDBY
  2. 在主节点中创建一个用户进行复制。我在 pgAdmin 中这样做(它确实具有超级用户权限)
  3. 在 pg_hba.conf 中的主节点中添加允许备用连接的部分: host replication repuser 127.0.0.1/0 md5
  4. 在 postgresql.conf 中的 master 节点中设置:

    max_wal_senders = 1
    归档模式 = 开
    存档命令 = 'cp %p ~/postgresql/backup/archivedir/%f'
    wal_level = 存档
    wal_keep_segments = 32

  5. 启动主节点并做基础备份:

    psql -d dellstore2 -c "SELECT pg_start_backup('backup for replication', true)"
    rsync -av ${PGDATA}/ $STANDBY --exclude postmaster.pid
    psql -d dellstore2 -c "选择 pg_stop_backup()"
    
    pg_stop_backup 表示一切正常,所有 WAL 文件都已存档

  6. 在备用 (data2) 节点中,我使用以下命令创建 recovery.conf:

    待机模式 = '开'
    primary_conninfo = 'host=127.0.0.1 port=5432 user=repuser password=haslo'
    trigger_file = '/home/michau/postgresql/replication.trigger'
    restore_command = 'cp /home/michau/postgresql/backup/archivedir/%f "%p"'

  7. 启动主节点,然后启动备用节点 - 复制应该开始,备用应该赶上主节点。这正是第一次发生的事情。现在,当我启动待机时,我收到:“地址已在使用中”错误。当然,standby 和 master 都有在 postgresql.conf 中指定的相同端口(它们有完全相同的 postgresql.conf 文件)。如果我将备用端口更改为 5433,那么我会得到:

    LOG: 数据库系统在 2012-06-12 19:48:01 CEST 被关闭恢复
    LOG:进入待机模式
    cp:无法统计/home/michau/postgresql/backup/archivedir/000000010000000000000007:没有那个文件或目录
    LOG:一致恢复状态达到 0/7000070
    LOG:0/7000070 处的零长度记录
    cp:无法统计/home/michau/postgresql/backup/archivedir/000000010000000000000007:没有那个文件或目录
    LOG:流复制成功连接到主
    日志:重做从 0/7000070 开始
    

它只是挂在这里。运行 ps -ef | grep postgresql 产生:

michau 2491 1898 0 19:46 pts/0 00:00:00 postgres -D /home/michau/postgresql/9.1/data
米修 2493 2491 0 19:46 ? 00:00:01 postgres:写入进程
米修 2494 2491 0 19:46 ? 00:00:00 postgres:wal 写进程
米修 2495 2491 0 19:46 ? 00:00:00 postgres:autovacuum 启动程序
米修 2496 2491 0 19:46 ? 00:00:00 postgres:归档进程最后是 000000010000000000000008
米修 2497 2491 0 19:46 ? 00:00:00 postgres:统计信息收集器进程
michau 2571 2214 0 19:49 pts/1 00:00:00 postgres -D /home/michau/postgresql/9.1/data2
米修 2572 2571 0 19:49 ? 00:00:01 postgres:启动过程正在恢复 000000010000000000000009
米修 2575 2571 0 19:49 ? 00:00:01 postgres:写入进程
米修 2578 2571 0 19:49 ? 00:00:02 postgres:wal 接收器进程流 0/99782DC
米修 2579 2491 0 19:49 ? 00:00:00 postgres:wal 发送者进程 repuser 127.0.0.1(42142) 流 0/99782DC
米修 2586 2491 0 19:51 ? 00:00:00 postgres: michau postgres ::1(49941) 空闲
米修 2587 2491 0 19:51 ? 00:00:01 postgres: michau dellstore2 ::1(49942) 空闲
正在恢复的 0000000010000009 改变了一段时间,但半小时后它不再存在。

我确定有些事情我一定是第一次做的,没有写下来或其他什么,但我完全无法说出它是什么。我将不胜感激任何帮助。

Chr*_*ers 7

PostgreSQL 副本永远不会完成恢复。这是设计使然。基本上,副本始终处于“从灾难中恢复”模式,只是它使用从主服务器而不是在磁盘上接收 WAL 段。

因此,您所看到的无需担心。如果它还不能正常工作,那么您需要提供更详细的说明,说明您正在尝试做什么以及什么不起作用。但就你发帖而言,这似乎很正常。