OCF_HEARTBEAT_PGSQL(7)

πŸ’– OCF_HEARTBEAT_PGSQL πŸ’–

okay so bestie, this is ocf_heartbeat_pgsql β€” the resource agent that manages a PostgreSQL database instance. Yes, the manual page name really is that whole mouthful. Think of it as the pgsql RA's official group chat bio. 🐘✨

It's a resource script for PostgreSQL, and its whole job is managing a PostgreSQL as an HA resource. That's it, that's the vibe. 🫢


✨ SYNOPSIS ✨

pgsql [start | stop | status | monitor | promote | demote | meta-data |
      validate-all]

🌸 DESCRIPTION 🌸

Resource script for PostgreSQL. It manages a PostgreSQL as an HA resource. Literally that's the job description, and it does it slayfully. πŸ’…


πŸŽ€ SUPPORTED PARAMETERS πŸŽ€

okay so there are a lot of these. Do not panic. We go through them one by one, together. πŸ‘‘

  • pgctl β€” the path to the pg_ctl command. (optional, string, default "/usr/bin/pg_ctl")
  • start_opt β€” the start options (-o start_opt in pg_ctl). Like "-i -p 5432" for example. (optional, string, no default)
  • ctl_opt β€” extra pg_ctl options (-w, -W etc..). (optional, string, no default)
  • psql β€” the path to the psql command. (optional, string, default "/usr/bin/psql")
  • pgdata β€” the path to the PostgreSQL data directory. (optional, string, default "/var/lib/pgsql/data")
  • pgdba β€” the user that owns PostgreSQL. (optional, string, default "postgres")
  • pghost β€” the hostname/IP address where PostgreSQL is listening. (optional, string, no default)
  • pgport β€” the port where PostgreSQL is listening. (optional, integer, default 5432)
  • pglibs β€” a custom location for the Postgres libraries. If you don't set it, the standard location gets used. (optional, string, default "/usr/lib")
  • monitor_user β€” the PostgreSQL user that the pgsql RA will use for monitor operations. If it's not set, the pgdba user gets used instead. (optional, string, no default)
  • monitor_password β€” the password for the monitor user. (optional, string, no default)
  • monitor_sql β€” the SQL script that gets used for monitor operations. (optional, string, default "select now();")
  • config β€” the path to the PostgreSQL configuration file for the instance. (optional, string, default "/var/lib/pgsql/data/postgresql.conf")
  • pgdb β€” the database that gets used for monitoring. (optional, string, default "template1")
  • logfile β€” the path to the PostgreSQL server log output file. (optional, string, default "/dev/null")
  • socketdir β€” the Unix socket directory for PostgreSQL.

so like, if you're on PostgreSQL 9.3 or higher and you define unix_socket_directories in the postgresql.conf, then you must set socketdir to determine which directory is used for the psql command. no skipping this one, bestie. (optional, string, no default)

  • stop_escalate β€” the number of seconds to wait for stop (using -m fast) before resorting to -m immediate. (optional, integer, default 90)
  • rep_mode β€” the replication mode, and it may be set to "async" or "sync" or "slave". πŸ‘€

These require PostgreSQL 9.1 or later. Once it's set, "async" and "sync" require the node_list, master_ip, and restore_command parameters, as well as configuring PostgreSQL for replication (in postgresql.conf and pg_hba.conf).

"slave" means the RA only makes recovery.conf before starting to connect to a primary which is running somewhere. It doesn't need master/slave setting. It requires the master_ip and restore_command parameters.

(optional, string, default "none")

  • node_list β€” all node names. Please separate each node name with a space. This is optional for replication. Defaults to all nodes in the cluster. (optional, string, no default)
  • restore_command β€” the restore_command for recovery.conf. This is required for replication. (optional, string, no default)
  • archive_cleanup_command β€” the archive_cleanup_command for recovery.conf. This is used for replication and is optional. (optional, string, no default)
  • recovery_end_command β€” the recovery_end_command for recovery.conf. This is used for replication and is optional. (optional, string, no default)
  • master_ip β€” the master's floating IP address, to be connected from the hot standby. This parameter is used for "primary_conninfo" in recovery.conf. This is required for replication. (optional, string, no default)
  • repuser β€” the user used to connect to the master server. This parameter is used for "primary_conninfo" in recovery.conf. This is required for replication. (optional, string, default "postgres")
  • primary_conninfo_opt β€” the primary_conninfo options of recovery.conf except host, port, user and application_name. This is optional for replication. (optional, string, no default)
  • restart_on_promote β€” if this is true, the RA deletes recovery.conf and restarts PostgreSQL on promote to keep the Timeline ID. It probably makes fail-over slower. It's recommended to set on-fail of promote up as fence. This is optional for replication. (optional, boolean, default false)
  • replication_slot_name β€” set this option when using replication slots. Can only use lower case letters, numbers and underscore for replication_slot_name. πŸ”₯

The replication slots would be created for each node, with the name adding the node name as postfix. For example, replication_slot_name is "sample" and 2 slaves which are "node1" and "node2" connect to their slots, the slots names are "sample_node1" and "sample_node2". If the node name contains a upper case letter, hyphen and dot, those characters will be converted to a lower case letter or an underscore. For example, Node-1.example.com to node_1_example_com.

⚠️ ok so this part is important, no cap: the pgsql RA doesn't monitor and delete the replication slot. When the slave node has been disconnected in failure or the like, execute one of the following manually. Otherwise it may eventually cause a disk full because the master node will continue to accumulate the unsent WAL. 1. recover and reconnect the slave node to the master node as soon as possible. 2. delete the slot on the master node by following psql command. $ select pg_drop_replication_slot('replication_slot_name');

(optional, string, no default)

  • tmpdir β€” the path to a temporary directory. This is optional for replication. (optional, string, default "/var/lib/pgsql/tmp")
  • xlog_check_count β€” the number of checks of xlog on monitor before promote. This is optional for replication.
πŸ“ Note: for backward compatibility, the terms are unified with PostgreSQL 9. If you are using PostgreSQL 10 or later, replace "xlog" with "wal". Likewise, replacing "location" with "lsn".

(optional, integer, default 3)

  • crm_attr_timeout β€” the timeout of the crm_attribute forever update command. The default value is 5 seconds. This is optional for replication. (optional, integer, default 5)
  • stop_escalate_in_slave β€” the number of seconds to wait for stop (using -m fast) before resorting to -m immediate in slave state. This is optional for replication. (optional, integer, default 90)
  • check_wal_receiver β€” if this is true, the RA checks the wal_receiver process on monitor and notifies its status using the "(resource name)-receiver-status" attribute. It's useful for checking whether PostgreSQL (hot standby) connects to primary. The attribute shows status as "normal" or "normal (master)" or "ERROR". Note that if you configure PostgreSQL as master/slave resource, then the wal receiver is not running in the master and the attribute shows status as "normal (master)" consistently because it is normal status. (optional, boolean, default false)
  • external_standby_node_list β€” all node names of synchronous standby nodes that may connect from outside the Pacemaker cluster. Please separate each node name with a space. When set, the RA automatically manages synchronous_standby_names for both in-cluster and external standby nodes during monitor. Each node name must match the application_name the standby uses to connect. This parameter requires rep_mode=sync. This is optional for replication. (optional, string, no default)

πŸ¦‹ SUPPORTED ACTIONS πŸ¦‹

This resource agent supports the following actions (operations), and yes, each one has opinions about your timeouts:

  • start β€” starts the resource. Suggested minimum timeout: 120s.
  • stop β€” stops the resource. Suggested minimum timeout: 120s.
  • status β€” performs a status check. Suggested minimum timeout: 60s.
  • monitor β€” performs a detailed status check. Suggested minimum timeout: 30s. Suggested interval: 30s.
  • monitor (Promoted role) β€” performs a detailed status check. Suggested minimum timeout: 30s. Suggested interval: 29s.
  • promote β€” promotes the resource to the Master role. Suggested minimum timeout: 120s.
  • demote β€” demotes the resource to the Slave role. Suggested minimum timeout: 120s.
  • notify β€” suggested minimum timeout: 90s.
  • meta-data β€” retrieves resource agent metadata (internal use only). Suggested minimum timeout: 5s.
  • validate-all β€” performs a validation of the resource configuration. Suggested minimum timeout: 5s.
  • methods β€” suggested minimum timeout: 5s.

πŸ’œ EXAMPLE CRM SHELL πŸ’œ

here's an example configuration for a pgsql resource using the crm(8) shell, copy-paste-ready and iconic:

primitive p_pgsql ocf:heartbeat:pgsql \
  op monitor depth="0" timeout="30s" interval="30s" \
  op monitor depth="0" timeout="30s" interval="29s" role="Promoted"

ms ms_pgsql p_pgsql \
  meta notify="true" interleave="true"

🌈 EXAMPLE PCS 🌈

and this one's the example configuration for a pgsql resource using pcs(8):

pcs resource create p_pgsql ocf:heartbeat:pgsql \
  op monitor OCF_CHECK_LEVEL="0" timeout="30s" interval="30s" \
  op monitor OCF_CHECK_LEVEL="0" timeout="30s" interval="29s" role="Promoted" promotable

πŸ‘€ SEE ALSO πŸ‘€

http://clusterlabs.org/ β€” go say hi to the ClusterLabs besties.


🌟 AUTHOR 🌟

ClusterLabs contributors (see the resource agent source for information about individual authors). ilysm for maintaining this. πŸ™


okay that's the whole page, you made it to the end, I'm so proud of you fr fr πŸŽ‰ the resource agents package version is UNKNOWN and this page is dated 10/01/2026 β€” so like, timestamped and cute, periodt. πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from