pgAdmin中的临时表

10

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

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

4个回答

13

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

在pgAdmin(至少是pgAdmin4)中,您可以打开首选项面板并切换此设置:

显示->显示系统对象?True

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

PS 更改首选项后请刷新模式树


11

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"来列出您的模式。

希望这能帮到您。


太好了!它完美地运行了。我知道它一定在那里。 ;) - MPękalski
我尝试了这个,但是没有返回任何东西,有什么想法吗?! - leoschet
3
根据这个,似乎无法通过pgadmin GUI访问临时表? - chrowe

1
在pgAdmin 4中,您只需要在“属性-浏览器-显示-显示系统对象”(最后一个选项)中启用即可。启用后,您就可以在“pg_temp_(#) schema”下找到您的表格。

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)

请对您的 SQL 查询提供一些解释。 - mishsx

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接