pgAdmin中的临时表

时间:2011-04-04 09:34:57

标签: postgresql temp-tables pgadmin

我正在使用pgAdmin作为我的Postgres 8.4数据库,我想知道在哪里(任何表/模式/等等?)我可以找到当前使用的临时表的列表?我认为必须有一个我能找到它的地方。

它们不在目录对象中,也不在视图中,还有其他任何建议吗?

3 个答案:

答案 0 :(得分:9)

Postgres为名为“pg_temp_#”的临时表创建一个临时模式,你可以用psql看到它......

create temp table mytemptable(name varchar);

select c.relname
from pg_namespace n
  join pg_class   c on n.oid=c.relnamespace
where n.nspname='pg_temp_1';

您可以列出在psql中执行“\ dn”的模式。

希望有所帮助。

答案 1 :(得分:5)

临时表位于临时模式pg_temp_{№}中,该临时模式默认情况下隐藏在pgAdmin UI中。

在pgAdmin(至少为p​​gAdmin4)中,您可以打开“首选项”窗格并启用以下设置:

Display->Show system objects?True

这将显示您创建的临时表的隐藏模式。

PS更改首选项后刷新架构树

答案 2 :(得分:0)

https://www.dbrnd.com/2017/06/postgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection/

SELECT
    n.nspname as SchemaName
    ,c.relname as RelationName
    ,CASE c.relkind
    WHEN 'r' THEN 'table'
    WHEN 'v' THEN 'view'
    WHEN 'i' THEN 'index'
    WHEN 'S' THEN 'sequence'
    WHEN 's' THEN 'special'
    END as RelationType
    ,pg_catalog.pg_get_userbyid(c.relowner) as RelationOwner               
    ,pg_size_pretty(pg_relation_size(n.nspname ||'.'|| c.relname)) as RelationSize
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n               
                ON n.oid = c.relnamespace
WHERE  c.relkind IN ('r','s') 
AND  (n.nspname !~ '^pg_toast' and nspname like 'pg_temp%')
ORDER BY pg_relation_size(n.nspname ||'.'|| c.relname) DESC

将显示所有临时表的输出。

 schemaname | relationname | relationtype | relationowner | relationsize
------------+--------------+--------------+---------------+--------------
 pg_temp_63 | temp_sl_4    | table        | power_bi_cr   | 2355 MB
 pg_temp_63 | temp_sl_3    | table        | power_bi_cr   | 1342 MB
 pg_temp_63 | temp_sl_2    | table        | power_bi_cr   | 1239 MB
 pg_temp_63 | temp_sl      | table        | power_bi_cr   | 1216 MB
 pg_temp_63 | temp_sl_gr   | table        | power_bi_cr   | 521 MB
 pg_temp_63 | temp_ftlo    | table        | power_bi_cr   | 457 MB
 pg_temp_63 | temp_th3     | table        | power_bi_cr   | 123 MB
 pg_temp_63 | temp_th      | table        | power_bi_cr   | 79 MB
 pg_temp_63 | temp_th2     | table        | power_bi_cr   | 17 MB
(9 rows)
相关问题