Answers:
从postgres 9.3开始,可以使用postgres在psql中获取信息命令的确切sql(例如\ d,\ du,\ dp等)的一种技巧。这就是窍门。打开一个postgres会话,然后输入命令:
begin;
\dn+
当事务仍在运行时,打开另一个postgres会话,并查询pg_stat_activity,您可以获取确切的sql。
postgres=# select query from pg_stat_activity ;
query
-----------------------------------------------------------------------
SELECT n.nspname AS "Name", +
pg_catalog.pg_get_userbyid(n.nspowner) AS "Owner", +
pg_catalog.array_to_string(n.nspacl, E'\n') AS "Access privileges",+
pg_catalog.obj_description(n.oid, 'pg_namespace') AS "Description" +
FROM pg_catalog.pg_namespace n +
WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema' +
ORDER BY 1;
\set ECHO_HIDDEN on
psql -E