postgresql_16:3.6.27.4 Recovery Control Functions
PostgreSQL 16 > The SQL Language > Functions and Operators > System Administration Functions > Recovery Control Functions
The functions shown in (see functions-recovery-info-table) provide information about the current status of a standby server. These functions may be executed both during recovery and in normal running.
| Function Description | | --- | | pg_is_in_recovery () boolean Returns true if recovery is still in progress. | | pg_last_wal_receive_lsn () pg_lsn Returns the last write-ahead log location that has been received and synced to disk by streaming replication. While streaming replication is in progress this will increase monotonically. If recovery has completed then this will remain static at the location of the last WAL record received and synced to disk during recovery. If streaming replication is disabled, or if it has not yet started, the function returns NULL. | | pg_last_wal_replay_lsn () pg_lsn Returns the last write-ahead log location that has been replayed during recovery. If recovery is still in progress this will increase monotonically. If recovery has completed then this will remain static at the location of the last WAL record applied during recovery. When the server has been started normally without recovery, the function returns NULL. | | pg_last_xact_replay_timestamp () timestamp with time zone Returns the time stamp of the last transaction replayed during recovery. This is the time at which the commit or abort WAL record for that transaction was generated on the primary. If no transactions have been replayed during recovery, the function returns NULL. Otherwise, if recovery is still in progress this will increase monotonically. If recovery has completed then this will remain static at the time of the last transaction applied during recovery. When the server has been started normally without recovery, the function returns NULL. | | pg_get_wal_resource_managers () setof record ( rm_id integer, rm_name text, rm_builtin boolean ) Returns the currently-loaded WAL resource managers in the system. The column rm_builtin indicates whether it's a built-in resource manager, or a custom resource manager loaded by an extension. |
The functions shown in (see functions-recovery-control-table) control the progress of recovery. These functions may be executed only during recovery.
| Function Description | | --- | | pg_is_wal_replay_paused () boolean Returns true if recovery pause is requested. | | pg_get_wal_replay_pause_state () text Returns recovery pause state. The return values are not paused if pause is not requested, pause requested if pause is requested but recovery is not yet paused, and paused if the recovery is actually paused. | | pg_promote ( wait boolean DEFAULT true, wait_seconds integer DEFAULT 60 ) boolean Promotes a standby server to primary status. With wait set to true (the default), the function waits until promotion is completed or wait_seconds seconds have passed, and returns true if promotion is successful and false otherwise. If wait is set to false, the function returns true immediately after sending a SIGUSR1 signal to the postmaster to trigger promotion. This function is restricted to superusers by default, but other users can be granted EXECUTE to run the function. | | pg_wal_replay_pause () void Request to pause recovery. A request doesn't mean that recovery stops right away. If you want a guarantee that recovery is actually paused, you need to check for the recovery pause state returned by pg_get_wal_replay_pause_state(). Note that pg_is_wal_replay_paused() returns whether a request is made. While recovery is paused, no further database changes are applied. If hot standby is active, all new queries will see the same consistent snapshot of the database, and no further query conflicts will be generated until recovery is resumed. This function is restricted to superusers by default, but other users can be granted EXECUTE to run the function. | | pg_wal_replay_resume () void Restarts recovery if it was paused. This function is restricted to superusers by default, but other users can be granted EXECUTE to run the function. |
pg_wal_replay_pause and pg_wal_replay_resume cannot be executed while a promotion is ongoing. If a promotion is triggered while recovery is paused, the paused state ends and promotion continues.
If streaming replication is disabled, the paused state may continue indefinitely without a problem. If streaming replication is in progress then WAL records will continue to be received, which will eventually fill available disk space, depending upon the duration of the pause, the rate of WAL generation and available disk space.