pg_stat_activity doesn't update within a procedure or transaction

匆匆过客 提交于 2019-12-01 18:15:40

PostgreSQL makes a per-backend (per-connection, effectively) cache of the data used by the pg_stat_get_activity() function used by both pg_stat_activity and pg_stat_replication.

This cache is cleared on commit/rollback, but not at the end of each statement within a transaction in READ COMMITTED like usual.

You can explicitly clear it with SELECT pg_stat_clear_snapshot(). Call it within the body of a PL/PgSQL LOOP to refresh.

There is AFAIK no way to ask PostgreSQL to auto-refresh after each statement when using repeatable read or higher isolation.

In the source code, see pgstat_read_current_status(void) and pgstat_clear_snapshot(void).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!