pg_notification_queue_usage() 是一个系统函数,它返回异步通知队列当前未处理通知所占用的最大容量的比例。
pg_notification_queue_usage() 添加于 PostgreSQL 9.6。
用法
pg_notification_queue_usage () → double precision
返回的数字是一个介于 0 和 1 之间的值,表示由尚未被监听会话消费的通知(由 NOTIFY 命令或 pg_notify() 函数发送)占用的异步通知队列最大容量(默认:8GB)的比例。
变更历史
- PostgreSQL 9.6
- 添加(提交 a04bb65f)
示例
对 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)
参考资料
- PostgreSQL 文档: 会话信息函数
