gpt4 book ai didi

PostgreSQL 流式复制

转载 作者:行者123 更新时间:2023-11-29 11:35:33 25 4
gpt4 key购买 nike

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

  • 设置两个节点:
  • initdb -D $PGDATA initdb -D $STANDBY
  • 在主节点中创建一个用户进行复制。我在 pgAdmin 中这样做(它确实具有 super 用户权限)
  • 在 pg_hba.conf 中的主节点中添加允许备用连接的部分:
  • host replication repuser 127.0.0.1/0 md5
  • 在 postgresql.conf 中的 master 节点设置:
  • max_wal_senders = 1 archive_mode = on archive_command = 'cp %p ~/postgresql/backup/archivedir/%f' wal_level = archive wal_keep_segments = 32
  • 启动主节点并做基础备份:
  • psql -d dellstore2 -c "SELECT pg_start_backup('backup for replication', true)" rsync -av ${PGDATA}/ $STANDBY --exclude postmaster.pid psql -d dellstore2 -c "select pg_stop_backup()"
    pg_stop_backup 表示一切正常,所有 WAL 文件都已存档
  • 在备用 (data2) 节点中,我使用以下命令创建了 recovery.conf:
  • standby_mode = 'on' 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"'
  • 启动主节点,然后启动备用节点 - 复制应该开始,备用应该 catch 主节点。这正是第一次发生的事情。
    现在,当我开始待机时,我得到: “地址已被使用”错误。
    当然,standby 和 master 都有在 postgresql.conf 中指定的相同端口(它们有完全相同的 postgresql.conf 文件)。如果我将备用端口更改为 5433,那么我会得到:
  • LOG: database system was shut down in recovery at 2012-06-12 19:48:01 CEST LOG: entering standby mode cp: cannot stat /home/michau/postgresql/backup/archivedir/000000010000000000000007: No such file or directory LOG: consistent recovery state reached at 0/7000070 LOG: record with zero length at 0/7000070 cp: cannot stat /home/michau/postgresql/backup/archivedir/000000010000000000000007: No such file or directory LOG: streaming replication successfully connected to primary LOG: redo starts at 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 michau 2493 2491 0 19:46 ? 00:00:01 postgres: writer process michau 2494 2491 0 19:46 ? 00:00:00 postgres: wal writer process michau 2495 2491 0 19:46 ? 00:00:00 postgres: autovacuum launcher process michau 2496 2491 0 19:46 ? 00:00:00 postgres: archiver process last was 000000010000000000000008 michau 2497 2491 0 19:46 ? 00:00:00 postgres: stats collector process michau 2571 2214 0 19:49 pts/1 00:00:00 postgres -D /home/michau/postgresql/9.1/data2 michau 2572 2571 0 19:49 ? 00:00:01 postgres: startup process recovering 000000010000000000000009 michau 2575 2571 0 19:49 ? 00:00:01 postgres: writer process michau 2578 2571 0 19:49 ? 00:00:02 postgres: wal receiver process streaming 0/99782DC michau 2579 2491 0 19:49 ? 00:00:00 postgres: wal sender process repuser 127.0.0.1(42142) streaming 0/99782DC michau 2586 2491 0 19:51 ? 00:00:00 postgres: michau postgres ::1(49941) idle michau 2587 2491 0 19:51 ? 00:00:01 postgres: michau dellstore2 ::1(49942) idle
    正在恢复的 0000000010000009 改变了一段时间,但半小时后它不再存在。

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

    最佳答案

    我完成了你上面发布的步骤,我得到了你发布的确切错误,但我能够解决这个问题。

    我试图将您的步骤与本网站上发布的步骤合并
    http://www.debian-administration.org/article/How_to_setup_Postgresql_9.1_Streaming_Replication_Debian_Squeeze

    除了您发布的步骤之外,我还从我提供的站点中添加了 2 个步骤。 2个步骤如下:

  • 在 rsync 主服务器上的文件和文件夹之前,删除备用服务器中的所有文件和文件夹。
  • 在 master 的 postgresql.conf 中,将 wal_level 设置为 hot_standby 而不是 archive 并将 hot_standby 设置为 on。
  • 关于PostgreSQL 流式复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11002767/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com