pg_stat_get_backend_idset()

A function providing a sequential IDs for each backend

pg_stat_get_backend_idset() is a system function which generates a list of sequential IDs for each current backend, which can then be provided to a of functions, each of which returns a specifc items of information about each backend. These functions underly the pg_stat_activity view, but can be used to extract a subset of information provided by that view.

pg_stat_get_backend_idset() was added in PostgreSQL 7.2.

Usage

pg_stat_get_backend_idset () → setof integer

In PostgreSQL 16 and later, the integers returned are the actual backend IDs.

In PostgreSQL 15 and earlier, the integers returned from 1 to the number of currently active backends.

Change history

Examples

Basic usage example for pg_stat_get_backend_idset() in PostgreSQL 15 and earlier:

postgres=# SELECT * FROM pg_stat_get_backend_idset();
 pg_stat_get_backend_idset 
---------------------------
                         1
                         2
                         3
                         4
                         5
                         6
(6 rows)

In PostgreSQL 16 and later:

postgres=# SELECT * FROM pg_stat_get_backend_idset();
 pg_stat_get_backend_idset 
---------------------------
                         1
                         2
                         3
                       256
                       258
                       259
(6 rows)

By itself this information is of little use; normally this query will be combined with one or more of the per-backend statistics functions:

postgres=# SELECT pg_stat_get_backend_pid(s.id) AS pid
             FROM (SELECT pg_stat_get_backend_idset() AS id) AS s;
  pid  
-------
 18206
 18207
 18217
 18203
 18202
 18205
(6 rows)

Categories

System function

See also

pg_stat_get_backend_activity(), pg_stat_get_backend_activity_start(), pg_stat_get_backend_client_addr(), pg_stat_get_backend_client_port(), pg_stat_get_backend_dbid(), pg_stat_get_backend_pid(), pg_stat_get_backend_start(), pg_stat_get_backend_userid(), pg_stat_get_backend_wait_event(), pg_stat_get_backend_wait_event_type(), pg_stat_get_backend_xact_start()