PostgreSQL pg_notification_queue_usage() Function

The PostgreSQL pg_notification_queue_usage() function returns the maximum size portion of the asynchronous notification queue currently occupied by unprocessed notifications.

pg_notification_queue_usage() Syntax

Here is the syntax of the PostgreSQL pg_notification_queue_usage() function:

pg_notification_queue_usage() -> double precision

Parameters

The PostgreSQL pg_notification_queue_usage() function does not require any parameters.

Return value

The PostgreSQL pg_notification_queue_usage() function returns a number between 0 and 1, which is the maximum size portion of the asynchronous notification queue currently occupied by outstanding notifications.

pg_notification_queue_usage() Examples

The following statements illustrate the pg_notification_queue_usage() basic usage of PostgreSQL functions:

SELECT pg_notification_queue_usage();
 pg_notification_queue_usage
-----------------------------
                           0

Here, there are no pending asynchronous notification queues in the current session, so the pg_notification_queue_usage() function returns 0.

To send 10,000 asynchronous notifications on a specified channel, use the following statement:

SELECT COUNT(pg_notify('channel1', y || repeat('x', 5000)))
FROM generate_series(1, 20000) AS x(y);
 count
-------
 10000

Here the generate_series() function to produce a set, and the repeat() function is used to construct a message by repeating the x characters 5000.

While sending, open another session and run the following statement:

SELECT pg_notification_queue_usage();
 pg_notification_queue_usage
-----------------------------
       0.0006856918334960938