pg_notification_queue_usage()

A function reporting how full the asynchronous notification queue is

pg_notification_queue_usage() is a system function returning the fraction of the asynchronous notification queue's maximum size currently occupied by unprocessed notifications.

pg_notification_queue_usage() was added in PostgreSQL 9.6.

Usage

pg_notification_queue_usage () → double precision

The returned number is a value between 0 and 1 expressing the fraction of the asynchronous notification queue's maximum size (default: 8GB) taken up by notifications (sent by the NOTIFY command or the pg_notify() function) which have not been consumed by listening sessions.

Change history

Examples

Basic execution example for pg_notification_queue_usage(), indicating there are no queued messages:

postgres=# SELECT pg_notification_queue_usage();
 pg_notification_queue_usage 
-----------------------------
                           0
(1 row)

Inserting a large number of messages into the queue; note this requires at least one other sessoin to be listening on channel foo:

postgres=# CREATE TABLE notifications(channel NAME NOT NULL, message TEXT);
CREATE TABLE

postgres=# INSERT INTO notifications
             SELECT 'foo', y || REPEAT('x', 7990)
               FROM generate_series(1,10000) AS x(y);
INSERT 0 10000

postgres=# SELECT COUNT(pg_notify(channel, message)) FROM notifications;
 count
-------
 10000
(1 row)

postgres=# SELECT pg_notification_queue_usage();
 pg_notification_queue_usage
-----------------------------
         0.01049041748046875
(1 row)

Categories

Asynchronous notifications, System function

See also

pg_notify(), NOTIFY, LISTEN, UNLISTEN