zoukankan      html  css  js  c++  java
  • postgresql 线同步pg_rewind使用报错及注意

    pg_rewind 是postgresql主丛数据库之同步数据目录的工具。

    pg_rewind只复制表数据文件中更改的块;所有其他文件都被完整复制,包括配置文件。pg_rewind相对于使用pg_basebackup备份或rsync等工具的优势在于,pg_rewind不需要读取数据库中未更改的块。这使得在数据库很大且之间只有一小部分块不同的情况下,速度会快得多。

    二、使用前提:

    1、配置两台数据库的时候postgresql.conf 中wal_log_hints设置为on,不能数据库都开始使用了,再返回来修改这个参数。

    2、使用场景是一主一备,当主节点挂掉后,备节点成为了主节点;此时向新主节点加入数据;然后原来的主节点以备节点方式启动后,发现数据没有同步过来。

    3、使用规则需要注意:

      

    [atlasdb@vm1 ~]$ /usr/local/atlasdb/bin/pg_rewind --help
    pg_rewind resynchronizes a PostgreSQL cluster with another copy of the cluster.
    
    Usage:
      pg_rewind [OPTION]...
    
    Options:
      -D, --target-pgdata=DIRECTORY  existing data directory to modify
          --source-pgdata=DIRECTORY  source data directory to synchronize with
          --source-server=CONNSTR    source server to synchronize with
      -n, --dry-run                  stop before modifying anything
      -P, --progress                 write progress messages
          --debug                    write a lot of debug messages
      -V, --version                  output version information, then exit
      -?, --help                     show this help, then exit

    首先明白一个概念很重要(目标服务器指的是宕机后重新起来的那台,也就是需要更新数据的。源服务器指的是拥有最新数据的那台)

    其次,目标服务根据命令不同,要求有不同的启停状态。

    -D directory --target-pgdata=directory
    此选项指定与源同步的目标数据目录。在运行pg_rewind之前,必须干净关闭目标服务器

    --source-pgdata=directory
    指定要与之同步的源服务器的数据目录的文件系统路径。此选项要求干净关闭源服务器

    --source-server=connstr
    指定要连接到源PostgreSQL服务器的libpq连接字符串。连接必须是具有超级用户访问权限的正常(非复制)连接。此选项要求源服务器正在运行,而不是处于恢复模式

    -n --dry-run
    除了实际修改目标目录之外,执行所有操作。

    -P --progress
    输出进展报告。

    --debug
    输出很多Debug的信息。如果失败时,可以用此选项定位错误原因。

    例如:此命令是在数据库目录bin下执行的

    pg_rewind --target-pgdata=/data/atlasdb --source-server='host=192.168.0.201 port=5432 user=atlasdb password=atlasdb dbname=atlasdb' -P --debug
    参考:https://www.jianshu.com/p/bb05dc9639c0

  • 相关阅读:
    SpringBoot之使用外部的启动类
    CCF——最小差值(2017-12)
    CCF——买菜(2018-09)
    CCF——卖菜(2018-09)
    2792. Grammar Lessons
    2756. Lucky Transformation
    2776. String Task
    2794. Petya and Strings
    2810. Palindromic Times
    14. Football
  • 原文地址:https://www.cnblogs.com/zxg-blog/p/12218361.html
Copyright © 2011-2022 走看看