【发布时间】:2012-12-05 13:43:47
【问题描述】:
有什么方法可以获取 Postgresql 数据库中的表总数?我使用的 postgresql 版本是 PostgreSQL 8.4.14。
【问题讨论】:
-
要探索仅在一个数据库中发生的事情,我通常使用
\d。有了这个,您还可以列出表格、视图和序列的总数。
标签: database postgresql postgresql-8.4
有什么方法可以获取 Postgresql 数据库中的表总数?我使用的 postgresql 版本是 PostgreSQL 8.4.14。
【问题讨论】:
\d。有了这个,您还可以列出表格、视图和序列的总数。
标签: database postgresql postgresql-8.4
如果您只想获取表的数量(没有视图),那么:
select count(*) from information_schema.tables where table_type = 'BASE TABLE';
或者您也可以通过添加 where 条件来按架构名称过滤:
table_schema = 'public'
【讨论】:
select Count(*) from sys.tables
【讨论】:
select count(*)
from information_schema.tables;
或者,如果您只想查找特定模式的表数:
select count(*)
from information_schema.tables
where table_schema = 'public';
【讨论】:
只需尝试在 pg_stat... 表或 information_schema 中搜索,您就可以找到有关您的数据库的非常有用的信息。
示例:
select * from pg_stat_user_tables ;
select count(*) from pg_stat_user_tables ;
select * from pg_stat_all_tables ;
【讨论】: