## WAITLSN

WAITLSN — wait for the target LSN to be replayed

## Synopsis

    WAITLSN 'LSN' [ INFINITELY ]
    WAITLSN 'LSN' TIMEOUT wait_time
    WAITLSN 'LSN' NOWAIT

## Description

`WAITLSN` provides a simple interprocess communication mechanism to wait for the target log sequence number (LSN) on standby in Postgres Pro Enterprise databases with master-standby asynchronous replication. When run with the `LSN` option, the `WAITLSN` command waits for the specified LSN to be replayed. By default, wait time is unlimited. Waiting can be interrupted using `Ctrl+C`, or by shutting down the `postgres` server. You can also limit the wait time using the `TIMEOUT` option, or check the target LSN status immediately using the `NOWAIT` option.

## Parameters

`LSN`

  Specify the target log sequence number to wait for.

INFINITELY

  Wait until the target LSN is replayed on standby. This is an optional parameter reinforcing the default behavior.

TIMEOUT `wait_time`

  Limit the time to wait for the LSN to be replayed. The specified `wait_time` must be an integer and is measured in milliseconds.

NOWAIT

  Report whether the target LSN has been replayed already, without any waiting.

## Examples

Run `WAITLSN` from psql, limiting wait time to 10000 milliseconds:

    WAITLSN '0/3F07A6B1' TIMEOUT 10000;
    NOTICE:  LSN is not reached. Try to increase wait time.
    LSN reached
    -------------
     f
    (1 row)

Wait until the specified LSN is replayed:

    WAITLSN '0/3F07A611';
    LSN reached
    -------------
     t
    (1 row)

Limit LSN wait time to 500000 milliseconds, and then cancel the command:

    WAITLSN '0/3F0FF791' TIMEOUT 500000;
    ^CCancel request sent
    NOTICE:  LSN is not reached. Try to increase wait time.
    ERROR:  canceling statement due to user request
     LSN reached
    -------------
     f
    (1 row)

## Compatibility

There is no `WAITLSN` statement in the SQL standard.