---
name: "ocf_heartbeat_pgsql"
section: "7"
platform: "linux"
package: "resource-agents"
version: "1:4.16.0-3+deb13u2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/ocf_heartbeat_pgsql"
---

# ocf\_heartbeat\_pgsql(7)

Manages a PostgreSQL database instance

## NAME

ocf\_heartbeat\_pgsql - Manages a PostgreSQL database instance

## 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.

## SUPPORTED PARAMETERS

**pgctl**

Path to pg\_ctl command.

(optional, string, default "/usr/bin/pg\_ctl")

**start\_opt**

Start options (-o start\_opt in pg\_ctl). "-i -p 5432" for example.

(optional, string, no default)

**ctl\_opt**

Additional pg\_ctl options (-w, -W etc..).

(optional, string, no default)

**psql**

Path to psql command.

(optional, string, default "/usr/bin/psql")

**pgdata**

Path to PostgreSQL data directory.

(optional, string, default "/var/lib/pgsql/data")

**pgdba**

User that owns PostgreSQL.

(optional, string, default "postgres")

**pghost**

Hostname/IP address where PostgreSQL is listening

(optional, string, no default)

**pgport**

Port where PostgreSQL is listening

(optional, integer, default 5432)

**pglibs**

Custom location of the Postgres libraries. If not set, the standard location will be used.

(optional, string, default "/usr/lib")

**monitor\_user**

PostgreSQL user that pgsql RA will user for monitor operations. If it's not set pgdba user will be used.

(optional, string, no default)

**monitor\_password**

Password for monitor user.

(optional, string, no default)

**monitor\_sql**

SQL script that will be used for monitor operations.

(optional, string, default "select now();")

**config**

Path to the PostgreSQL configuration file for the instance.

(optional, string, default "/var/lib/pgsql/data/postgresql.conf")

**pgdb**

Database that will be used for monitoring.

(optional, string, default "template1")

**logfile**

Path to PostgreSQL server log output file.

(optional, string, default "/dev/null")

**socketdir**

Unix socket directory for PostgreSQL.

If you use PostgreSQL 9.3 or higher and define unix\_socket\_directories in the postgresql.conf, then you must set socketdir to determine which directory is used for psql command.

(optional, string, no default)

**stop\_escalate**

Number of seconds to wait for stop (using -m fast) before resorting to -m immediate

(optional, integer, default 90)

**rep\_mode**

Replication mode may be set to "async" or "sync" or "slave". They require PostgreSQL 9.1 or later. Once set, "async" and "sync" require node\_list, master\_ip, and restore\_command parameters,as well as configuring PostgreSQL for replication (in postgresql.conf and pg\_hba.conf).

"slave" means that RA only makes recovery.conf before starting to connect to primary which is running somewhere. It doesn't need master/slave setting. It requires master\_ip 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**

restore\_command for recovery.conf. This is required for replication.

(optional, string, no default)

**archive\_cleanup\_command**

archive\_cleanup\_command for recovery.conf. This is used for replication and is optional.

(optional, string, no default)

**recovery\_end\_command**

recovery\_end\_command for recovery.conf. This is used for replication and is optional.

(optional, string, no default)

**master\_ip**

Master's floating IP address to be connected from hot standby. This parameter is used for "primary\_conninfo" in recovery.conf. This is required for replication.

(optional, string, no default)

**repuser**

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**

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, RA deletes recovery.conf and restarts PostgreSQL on promote to keep 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.

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**

Path to temporary directory. This is optional for replication.

(optional, string, default "/var/lib/pgsql/tmp")

**xlog\_check\_count**

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 crm\_attribute forever update command. Default value is 5 seconds. This is optional for replication.

(optional, integer, default 5)

**stop\_escalate\_in\_slave**

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, RA checks wal\_receiver process on monitor and notifies its status using "(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 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)

## SUPPORTED ACTIONS

This resource agent supports the following actions (operations):

**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

The following is an example configuration for a pgsql resource using the [**crm**(8)](/crm/8.md) shell:

```
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

The following is an example configuration for a pgsql resource using [**pcs**(8)](/pcs/8.md)

```
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/**

## AUTHOR

**ClusterLabs contributors (see the resource agent source for information about individual authors)**
