简体   繁体   English

pg_stat_activity不会在过程或事务中更新

[英]pg_stat_activity doesn't update within a procedure or transaction

I query pg_stat_activity but the contents seem to stay the same after the first time I query it within a plpgsql function body, SERIALIZABLE or REPEATABLE READ transaction. 我查询pg_stat_activity但是在我第一次在plpgsql函数体, SERIALIZABLEREPEATABLE READ事务中查询后,内容似乎保持不变。

Why does pg_stat_activity not follow the rules for READ COMMITTED in a plpgsql procedure? 为什么pg_stat_activity不遵循plpgsql过程中的READ COMMITTED规则?

How do I get the current status? 我如何获得当前状态? I want to loop over a query against pg_stat_activity in plpgsql until another query running on another backend finishes. 我想在plpgsql中循环查询pg_stat_activity的查询,直到在另一个后端运行的另一个查询完成。

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 . PostgreSQL对pg_stat_activitypg_stat_replication使用的pg_stat_get_activity()函数使用的数据进行每个后端(每个连接,有效)缓存。

This cache is cleared on commit/rollback, but not at the end of each statement within a transaction in READ COMMITTED like usual. 此缓存在提交/回滚时清除,但不会像往常一样在READ COMMITTED的事务中的每个语句的末尾清除。

You can explicitly clear it with SELECT pg_stat_clear_snapshot() . 您可以使用SELECT pg_stat_clear_snapshot()显式清除它。 Call it within the body of a PL/PgSQL LOOP to refresh. 在PL / PgSQL LOOP的主体内调用它来刷新。

There is AFAIK no way to ask PostgreSQL to auto-refresh after each statement when using repeatable read or higher isolation. 当使用repeatable read或更高隔离时,AFAIK无法在每个语句后要求PostgreSQL自动刷新。

In the source code, see pgstat_read_current_status(void) and pgstat_clear_snapshot(void) . 在源代码中,请参阅pgstat_read_current_status(void)pgstat_clear_snapshot(void)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM