### repmgrd startup log example Source: https://www.repmgr.org/docs/current/repmgr.html Example log output when repmgrd starts on a standby node. Shows connection status and monitoring initiation. ```log [2019-08-15 07:14:42] [NOTICE] repmgrd (repmgrd 5.0) starting up [2019-08-15 07:14:42] [INFO] connecting to database "host=node2 dbname=repmgr user=repmgr connect_timeout=2" INFO: set_repmgrd_pid(): provided pidfile is /var/run/repmgr/repmgrd-12.pid [2019-08-15 07:14:42] [NOTICE] starting monitoring of node "node2" (ID: 2) [2019-08-15 07:14:42] [INFO] monitoring connection to upstream node "node1" (ID: 1) ``` -------------------------------- ### Install PostgreSQL build prerequisites on Debian/Ubuntu Source: https://www.repmgr.org/docs/current/repmgr.html Install the prerequisites for building PostgreSQL on Debian or Ubuntu systems using apt-get. ```bash sudo apt-get update sudo apt-get build-dep postgresql-9.6 ``` -------------------------------- ### Install repmgr from source Source: https://www.repmgr.org/docs/current/repmgr.html Configure and install repmgr from the source code. Ensure pg_config for the target PostgreSQL version is in your PATH. ```bash ./configure && make install ``` -------------------------------- ### repmgr Password File Example (with wildcards) Source: https://www.repmgr.org/docs/current/repmgr.html Simplified example of a ~/.pgpass file using wildcards for hosts, ports, and databases when specific restrictions are not required. ```text *:*:*:repmgr:foo *:*:*:postgres:foo ``` -------------------------------- ### repmgr Password File Example (with superuser) Source: https://www.repmgr.org/docs/current/repmgr.html Example of a ~/.pgpass file including entries for a superuser ('postgres') when using the -S/--superuser option. ```text node1:5432:repmgr:repmgr:foo node1:5432:repmgr:postgres:foo node1:5432:replication:repluser:foo node2:5432:repmgr:repmgr:foo node2:5432:repmgr:postgres:foo node2:5432:replication:repluser:foo node3:5432:repmgr:repmgr:foo node3:5432:repmgr:postgres:foo node3:5432:replication:repluser:foo ``` -------------------------------- ### Install PostgreSQL build prerequisites on RHEL/CentOS Source: https://www.repmgr.org/docs/current/repmgr.html Install the prerequisites for building PostgreSQL on RHEL or CentOS systems using yum. ```bash sudo yum check-update sudo yum groupinstall "Development Tools" sudo yum install yum-utils openjade docbook-dtds docbook-style-dsssl docbook-style-xsl sudo yum-builddep postgresql96 ``` -------------------------------- ### Barman Server Configuration Example Source: https://www.repmgr.org/docs/current/repmgr.html An example of a Barman server configuration section in its configuration file, referenced by 'barman_server' in repmgr.conf. ```ini [pg] description = "Main cluster" ... ``` -------------------------------- ### Install repmgr Snapshot RPM Repository (as root) Source: https://www.repmgr.org/docs/current/repmgr.html Execute this command as the root user to install the EDB public snapshot repository for repmgr 9.6. This allows for the installation of snapshot packages. ```bash curl https://dl.enterprisedb.com/default/snapshot/get/9.6/rpm | bash ``` -------------------------------- ### repmgr Password File Example (repmgr user) Source: https://www.repmgr.org/docs/current/repmgr.html Example of a ~/.pgpass file for a 3-node cluster using the 'repmgr' database user for both metadata access and replication. ```text node1:5432:repmgr:repmgr:foo node1:5432:replication:repmgr:foo node2:5432:repmgr:repmgr:foo node2:5432:replication:repmgr:foo node3:5432:repmgr:repmgr:foo node3:5432:replication:repmgr:foo ``` -------------------------------- ### Promote Command Example for repmgrd Source: https://www.repmgr.org/docs/current/repmgr.html Example of setting the `promote_command` in `repmgr.conf`. This command is executed by repmgrd when a node needs to be promoted to primary. Ensure `--log-to-file` is used for proper logging. ```ini promote_command='/usr/bin/repmgr standby promote -f /etc/repmgr.conf --log-to-file' ``` -------------------------------- ### repmgr daemon start Source: https://www.repmgr.org/docs/current/repmgr.html Starts the repmgrd service on the local node. By default, it waits up to 15 seconds for confirmation, which can be adjusted or disabled. ```APIDOC ## repmgr daemon start ### Description Starts the repmgrd service on the local node. By default, repmgr will wait for up to 15 seconds to confirm that repmgrd started. This behaviour can be overridden by specifying a different value using the `--wait` option, or disabled altogether with the `--no-wait` option. ### Important The `repmgr.conf` parameter `repmgrd_service_start_command` must be set for `repmgr daemon start` to work. ### Method Not specified (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Options - `--wait ` - Specifies the time to wait for repmgrd to start (default: 15 seconds). - `--no-wait` - Disables waiting for repmgrd to start. ### Request Example ```bash $ repmgr daemon start ``` ### Response #### Success Response - repmgrd service started successfully on the local node. #### Error Response - Specific error codes are not detailed in the provided text, but failures may occur if `repmgrd_service_start_command` is not configured or if the service fails to start. ``` -------------------------------- ### pg_rewind execution example Source: https://www.repmgr.org/docs/current/repmgr.html This example shows the expected output from repmgr when pg_rewind execution is required. It highlights the timeline and WAL location details. ```text NOTICE: pg_rewind execution required for this node to attach to rejoin target node 1 DETAIL: rejoin target server's timeline 3 forked off current database system timeline 2 before current recovery point 0/7019C10 ``` -------------------------------- ### repmgr Configuration File Example Source: https://www.repmgr.org/docs/current/repmgr.html This is a minimal example of a repmgr.conf file. It must contain at least node_id, node_name, conninfo, and data_directory. Do not store this file within the PostgreSQL data directory. ```ini node_id=1 node_name='node1' conninfo='host=node1 user=repmgr dbname=repmgr connect_timeout=2' data_directory='/var/lib/postgresql/data' ``` -------------------------------- ### Example repmgr.conf File Source: https://www.repmgr.org/docs/current/repmgr.html A sample repmgr.conf file demonstrating basic configuration parameters like node ID, name, connection info, and data directory. ```shell # repmgr.conf node_id=1 node_name= node1 conninfo ='host=node1 dbname=repmgr user=repmgr connect_timeout=2' data_directory = '/var/lib/pgsql/12/data' ``` -------------------------------- ### Install repmgr Snapshot RPM Repository (with sudo) Source: https://www.repmgr.org/docs/current/repmgr.html Run this command as a normal user with sudo access to install the EDB public snapshot repository for repmgr 9.6. This method is an alternative to running as root directly. ```bash curl https://dl.enterprisedb.com/default/snapshot/get/9.6/rpm | sudo bash ``` -------------------------------- ### Example Status Log Line Source: https://www.repmgr.org/docs/current/repmgr.html This is an example of a status log line emitted by repmgrd at a configured interval, showing its current state. ```text [2018-07-12 00:47:32] [INFO] monitoring connection to upstream node "node1" (ID: 1) ``` -------------------------------- ### Start repmgrd Daemon Source: https://www.repmgr.org/docs/current/repmgr.html Starts the repmgrd service on the local node. The repmgr.conf parameter 'repmgrd_service_start_command' must be set for this command to function. By default, it waits up to 15 seconds for confirmation. ```bash repmgr daemon start ``` -------------------------------- ### repmgr Password File Example (dedicated replication user) Source: https://www.repmgr.org/docs/current/repmgr.html Example of a ~/.pgpass file for a 3-node cluster using a dedicated replication user ('repluser') for replication connections. ```text node1:5432:repmgr:repmgr:foo node1:5432:replication:repluser:foo node2:5432:repmgr:repmgr:foo node2:5432:replication:repluser:foo node3:5432:repmgr:repmgr:foo node3:5432:replication:repluser:foo ``` -------------------------------- ### Install repmgr14 Package Source: https://www.repmgr.org/docs/current/repmgr.html Installs the repmgr14 package using DNF. This command assumes the EDB repository has already been configured and is accessible. ```bash sudo dnf install repmgr14 ``` -------------------------------- ### Configure repmgrd Service Commands Source: https://www.repmgr.org/docs/current/repmgr.html Set the commands to start and stop the repmgrd service. This is required if using 'repmgr daemon start' and 'repmgr daemon stop'. ```shell repmgrd_service_start_command='sudo systemctl repmgr12 start' repmgrd_service_stop_command='sudo systemctl repmgr12 stop' ``` -------------------------------- ### Start repmgrd Manually Source: https://www.repmgr.org/docs/current/repmgr.html Use this command to start the repmgrd daemon manually. Ensure the configuration file and PID file paths are correct for your environment. ```bash repmgrd -f /etc/repmgr.conf --pid-file /tmp/repmgrd.pid ``` -------------------------------- ### Register Primary Server with repmgr Source: https://www.repmgr.org/docs/current/repmgr.html Use this command to register the primary node with repmgr. This installs the repmgr extension and metadata, and creates a record for the primary server. ```bash $ repmgr -f /etc/repmgr.conf primary register INFO: connecting to primary database... NOTICE: attempting to install extension "repmgr" NOTICE: "repmgr" extension successfully installed NOTICE: primary node record (id: 1) registered ``` -------------------------------- ### Install Specific repmgr Package Version (dnf) Source: https://www.repmgr.org/docs/current/repmgr.html After listing available versions, use this command to install a precise version of repmgr. Ensure the version string matches one of the available packages. ```bash [root@localhost ~]# dnf install repmgr10-5.3.0-1.el8 ``` -------------------------------- ### List Available repmgr Package Versions (dnf) Source: https://www.repmgr.org/docs/current/repmgr.html Use this command to see all available versions of a repmgr package before installation. This helps in identifying the exact version string needed for specific installations. ```bash [root@localhost ~]# dnf --showduplicates list repmgr10 ``` -------------------------------- ### Example repmgr Snapshot Package Name Source: https://www.repmgr.org/docs/current/repmgr.html This is an example of how a repmgr snapshot package name is formatted. It includes the version, snapshot build number, and git commit hash. ```text repmgr96-4.1.1-0.0git320.g5113ab0.1.el7.x86_64.rpm ``` -------------------------------- ### repmgr node status command example Source: https://www.repmgr.org/docs/current/repmgr.html Displays an overview of a node's basic information and replication status. This command must be run on the local node. ```bash $ repmgr -f /etc/repmgr.conf node status Node "node1": PostgreSQL version: 10beta1 Total data size: 30 MB Conninfo: host=node1 dbname=repmgr user=repmgr connect_timeout=2 Role: primary WAL archiving: off Archive command: (none) Replication connections: 2 (of maximal 10) Replication slots: 0 (of maximal 10) Replication lag: n/a ``` -------------------------------- ### Standby Follow Command Example Source: https://www.repmgr.org/docs/current/repmgr.html Example of using the 'repmgr standby follow' command to attach a standby node to a new upstream primary. This command restarts the PostgreSQL server after reconfiguring the standby. ```bash $ repmgr -f /etc/repmgr.conf standby follow INFO: setting node 3's primary to node 2 NOTICE: restarting server using "pg_ctl -l /var/log/postgres/startup.log -w -D '/var/lib/postgres/data' restart" waiting for server to shut down........ done server stopped waiting for server to start.... done server started NOTICE: STANDBY FOLLOW successful DETAIL: node 3 is now attached to node 2 ``` -------------------------------- ### repmgr node service with --superuser and --checkpoint Source: https://www.repmgr.org/docs/current/repmgr.html Example of using the --superuser and --checkpoint options with repmgr node service. This allows repmgr to execute CHECKPOINT. ```bash repmgr node service --checkpoint -S postgres ``` -------------------------------- ### Search for Available repmgr Packages Source: https://www.repmgr.org/docs/current/repmgr.html Lists all available repmgr packages in the configured repositories. This command is useful for discovering package names before installation. ```bash dnf search repmgr ``` -------------------------------- ### repmgr standby switchover with --superuser Source: https://www.repmgr.org/docs/current/repmgr.html Example of using the --superuser option with repmgr standby switchover. This allows repmgr to execute the CHECKPOINT command. ```bash repmgr standby switchover -S postgres ``` -------------------------------- ### Install repmgr using APT (Debian/Ubuntu) Source: https://www.repmgr.org/docs/current/repmgr.html After configuring the EDB APT repository, use this command to install the repmgr package suitable for your PostgreSQL version. For older PostgreSQL versions (9.6 and earlier), the package name format differs. ```bash sudo apt-get install postgresql-11-repmgr ``` -------------------------------- ### repmgr standby clone with --superuser Source: https://www.repmgr.org/docs/current/repmgr.html Example of using the --superuser option with repmgr standby clone. This is necessary when copying configuration files outside the data directory with --copy-external-config-files. ```bash repmgr standby clone --copy-external-config-files -S postgres ``` -------------------------------- ### repmgr node check with --superuser Source: https://www.repmgr.org/docs/current/repmgr.html Example of using the --superuser option with repmgr node check. This is required for executing repmgr node check --data-directory-config. ```bash repmgr node check --data-directory-config -S postgres ``` -------------------------------- ### Configuring Systemd Service Commands (CentOS 7) Source: https://www.repmgr.org/docs/current/repmgr.html Example configuration for repmgr.conf using systemd commands on CentOS 7. These commands require passwordless sudo access for the postgres user. ```config service_start_command = 'sudo systemctl start postgresql-9.6' service_stop_command = 'sudo systemctl stop postgresql-9.6' service_restart_command = 'sudo systemctl restart postgresql-9.6' service_reload_command = 'sudo systemctl reload postgresql-9.6' ``` -------------------------------- ### Create repmgr extension Source: https://www.repmgr.org/docs/current/repmgr.html Execute this command in the database of an existing repmgr installation to move and convert objects to the standard 'repmgr' schema. Ensure only one schema matches 'repmgr_%' in the database. ```sql CREATE EXTENSION repmgr FROM unpackaged ``` -------------------------------- ### Build HTML Documentation Source: https://www.repmgr.org/docs/current/repmgr.html Execute this command to generate HTML documentation files. The output will be in the doc/html subdirectory. ```bash ./configure && make doc ``` -------------------------------- ### Build PDF Documentation Source: https://www.repmgr.org/docs/current/repmgr.html Run this command to generate the documentation in PDF format (A4 size) after building the main repmgr source. ```bash ./configure && make doc-repmgr-A4.pdf ``` -------------------------------- ### Build Single HTML File Documentation Source: https://www.repmgr.org/docs/current/repmgr.html Use this command to create a single HTML file for the documentation after building the main repmgr source. ```bash ./configure && make doc-repmgr.html ``` -------------------------------- ### Add apt.postgresql.org repository Source: https://www.repmgr.org/docs/current/repmgr.html Add the apt.postgresql.org repository to your sources.list and ensure the source repository is enabled. ```bash deb https://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main deb-src https://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main ``` -------------------------------- ### Install repmgr on CentOS 6 Source: https://www.repmgr.org/docs/current/repmgr.html Use this command to install the repmgr package on CentOS 6 systems. Replace '96' with your specific PostgreSQL major version. ```bash yum install repmgr96 ``` -------------------------------- ### Install repmgr Package Source: https://www.repmgr.org/docs/current/repmgr.html Use this command to install the repmgr package for PostgreSQL 11 on Debian systems. Ensure you replace '11' with your specific PostgreSQL major version. ```bash apt-get install postgresql-11-repmgr ``` -------------------------------- ### Install repmgr on CentOS 7 Source: https://www.repmgr.org/docs/current/repmgr.html Use this command to install the repmgr package on CentOS 7 systems. Ensure you replace '11' with your specific PostgreSQL major version. ```bash yum install repmgr11 ``` -------------------------------- ### repmgr follow_command Example Source: https://www.repmgr.org/docs/current/repmgr.html Specifies the command to execute when a node follows a new primary. Ensure the full path is used for user-defined scripts. The %n placeholder is replaced by the new primary's node ID. The --log-to-file option directs output to repmgrd's log destination. ```bash follow_command='/usr/bin/repmgr standby follow -f /etc/repmgr.conf --log-to-file --upstream-node-id=%n' ``` -------------------------------- ### repmgrd Log: Initializing and Connecting Nodes Source: https://www.repmgr.org/docs/current/repmgr.html Shows typical repmgrd log output when it starts up on the primary node and child nodes begin to connect. This is before the minimum required child nodes are connected. ```log [2019-04-24 15:25:33] [INFO] monitoring primary node "node1" (ID: 1) in normal state [2019-04-24 15:25:35] [NOTICE] new node "node2" (ID: 2) has connected [2019-04-24 15:25:35] [NOTICE] 1 (of 1) child nodes are connected, but at least 2 child nodes required [2019-04-24 15:25:35] [INFO] no child nodes have detached since repmgrd startup (...) [2019-04-24 15:25:44] [NOTICE] new node "node3" (ID: 3) has connected [2019-04-24 15:25:46] [INFO] monitoring primary node "node1" (ID: 1) in normal state (...) ``` -------------------------------- ### Record repmgrd startup event Source: https://www.repmgr.org/docs/current/repmgr.html Records a 'repmgrd_start' event for a specific node in the cluster. Useful for auditing and debugging. ```bash $ repmgr -f /etc/repmgr.conf cluster event --event=repmgrd_start Node ID | Name | Event | OK | Timestamp | Details ---------+-------+---------------+----+---------------------+-------------------------------------------------------- 3 | node3 | repmgrd_start | t | 2019-08-15 07:14:42 | monitoring connection to upstream node "node1" (ID: 1) 2 | node2 | repmgrd_start | t | 2019-08-15 07:14:41 | monitoring connection to upstream node "node1" (ID: 1) 1 | node1 | repmgrd_start | t | 2019-08-15 07:14:39 | monitoring cluster primary "node1" (ID: 1) ``` -------------------------------- ### Start PostgreSQL in Single-User Mode for pg_rewind Source: https://www.repmgr.org/docs/current/repmgr.html This snippet demonstrates how to start a PostgreSQL instance in single-user mode to perform recovery, making it suitable for pg_rewind. Ensure `standby.signal` or `recovery.conf` is removed beforehand. ```bash rm -f /var/lib/pgsql/data/recovery.conf postgres --single -D /var/lib/pgsql/data/ < /dev/null ``` -------------------------------- ### pg_rewind no rewind required example Source: https://www.repmgr.org/docs/current/repmgr.html This example shows the output from pg_rewind when it determines that no rewind action is necessary, even if repmgr indicated it was required. This can occur in specific corner-case bugs in older PostgreSQL versions. ```text pg_rewind: servers diverged at WAL location 0/7015540 on timeline 2 pg_rewind: no rewind required ``` -------------------------------- ### Install a specific old repmgr package version Source: https://www.repmgr.org/docs/current/repmgr.html Install a specific version of a repmgr package on RHEL/CentOS systems by providing the package name and version. The version can be found using `yum --showduplicates list`. ```bash yum install {package_name}-{version} ``` ```bash yum install repmgr96-4.0.6-1.rhel6 ``` -------------------------------- ### Get repmgr Cluster Status in CSV Format Source: https://www.repmgr.org/docs/current/repmgr.html Outputs the replication cluster's status in a simple CSV format, suitable for parsing by scripts. Use this to get a machine-readable overview of your cluster's health. ```bash $ repmgr -f /etc/repmgr.conf service status --csv 1,node1,primary,1,1,5722,1,100,-1,default 2,node2,standby,1,0,-1,1,100,1,default 3,node3,standby,1,1,5779,1,100,1,default ``` -------------------------------- ### PostgreSQL replication termination log example Source: https://www.repmgr.org/docs/current/repmgr.html This example shows log entries from a PostgreSQL standby server indicating that replication was terminated by the primary server due to timeline divergence, often seen when pg_rewind incorrectly reports no action is needed. ```log [2020-09-07 15:01:41 UTC] LOG: 00000: replication terminated by primary server [2020-09-07 15:01:41 UTC] DETAIL: End of WAL reached on timeline 2 at 0/7015540. [2020-09-07 15:01:41 UTC] LOG: 00000: new timeline 3 forked off current database system timeline 2 before current recovery point 0/7019C10 ``` -------------------------------- ### Configuring pg_ctlcluster Service Commands (Debian/Ubuntu) Source: https://www.repmgr.org/docs/current/repmgr.html Example configuration for repmgr.conf using pg_ctlcluster for Debian/Ubuntu systems. It is recommended to use 'sudo pg_ctlcluster' to ensure systemd has an accurate view of the PostgreSQL application state. ```config service_start_command = 'sudo pg_ctlcluster 9.6 main start' service_stop_command = 'sudo pg_ctlcluster 9.6 main stop' service_restart_command = 'sudo pg_ctlcluster 9.6 main restart' service_reload_command = 'sudo pg_ctlcluster 9.6 main reload' ``` -------------------------------- ### Update repmgr extension Source: https://www.repmgr.org/docs/current/repmgr.html Run this SQL command in the database where repmgr is installed on the primary node after a major version upgrade. ```sql ALTER EXTENSION repmgr UPDATE ``` -------------------------------- ### Get Raw repmgr Version Number Source: https://www.repmgr.org/docs/current/repmgr.html Use the --version-number option for scripts that require a parseable representation of the repmgr version. ```bash repmgr --version-number ```