pg_sleep_until()

A system function for sleeping until the specified time

pg_sleep_until() is a system function for causing the connected backend to sleep until the specified time.

pg_sleep_until() was added in PostgreSQL 9.4.

Usage

pg_sleep_until ( timestamp with time zone ) → returns NULL

The documentation notes the following caveats:

  • the minimum sleep interval is platform-dependent and is typically 0.01 seconds
  • the sleep delay will always be at least the value specified, but may be longer under some circumstances

Change history

Examples

Basic usage of pg_sleep_until():

postgres=# SELECT clock_timestamp();
        clock_timestamp
-------------------------------
 2021-02-02 13:21:34.778857+01
(1 row)

Time: 0.291 ms
postgres=# SELECT pg_sleep_until('2021-02-02 13:22');
 pg_sleep_until
----------------

(1 row)

Time: 14710.314 ms (00:14.710)

No sleep will be performed if a point-in-time in the past is specified:

postgres=# SELECT pg_sleep_until('yesterday');
 pg_sleep_until
----------------

(1 row)

Time: 0.310 ms

Categories

System function

See also

pg_sleep(), pg_sleep_until()