pg_notification_queue_usage()

一个报告异步通知队列有多满的函数

pg_notification_queue_usage() 是一个系统函数,它返回异步通知队列当前未处理通知所占用的最大容量的比例。

pg_notification_queue_usage() 添加于 PostgreSQL 9.6

用法

pg_notification_queue_usage () → double precision

返回的数字是一个介于 01 之间的值,表示由尚未被监听会话消费的通知(由 NOTIFY 命令或 pg_notify() 函数发送)占用的异步通知队列最大容量(默认:8GB)的比例。

变更历史

示例

pg_notification_queue_usage() 的基本执行示例,表明没有排队的 istmessage

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

将大量消息插入队列;请注意,这需要至少一个其他会话正在监听名为 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)

分类

异步通知, 系统函数

另请参阅

pg_notify(), NOTIFY, LISTEN, UNLISTEN

反馈

提交任何关于“pg_notification_queue_usage()”的评论、建议或更正 请点击这里