How to list all prepared statements for all active sessions?

跟風遠走 提交于 2019-12-01 17:04:03

Nope. AFAIK prepared statements are local to a backend; other backends just don't know they exist. You'd need to modify the server to add additional inter-process communication to allow one backend to ask the others about prepared statements.

The backends initally appeared to share the same pg_prepared_statements table storage, as:

SELECT relfilenode FROM pg_class WHERE  relname = 'pg_prepared_statements';

returns the same relfilenode from different backends. I was surprised, as I thought prepared statements had no on-disk presence. If they were on disk I guess you could use the functions from the pageinspect contrib module to read the raw tuples or table pages. Visibility would be a problem; how would you know what was related to a dead/terminated backend, and what was valid?

I tried that, and found that pg_prepared_statements is actually a view:

regress=# SELECT * FROM heap_page_items(get_raw_page('pg_prepared_statements', 1));
ERROR:  cannot get raw page from view "pg_prepared_statements"

specifically a view over the pg_prepared_statement() function. So there's nothing to inspect. It's backend internal.

This seems like one of those "... but why would you do that?" questions, which is often a sign that someone is asking about a solution they've envisioned to their real problem, rather than asking about their real problem.

So: Why do you want that? What's the real problem you're trying to solve?

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