47

Is there any way by which I can get the total number of tables in a Postgresql database? The postgresql version I'm using is PostgreSQL 8.4.14.

4

4 回答 4

71
select count(*)
from information_schema.tables;

Or if you want to find the number of tables only for a specific schema:

select count(*)
from information_schema.tables
where table_schema = 'public';
于 2012-12-18T12:41:01.667 回答
20

Just try to search in pg_stat... tables or information_schema you can find there very useful informations about your database.
Example:

select * from  pg_stat_user_tables ;
select count(*) from  pg_stat_user_tables ; 
select * from  pg_stat_all_tables ;
于 2012-12-18T11:59:42.353 回答
1

If you want to get just the number of tables (without views) then:

select count(*) from information_schema.tables where table_type = 'BASE TABLE';

Or you can also filter by schema name by adding the where condition like:

table_schema = 'public'
于 2021-05-24T08:47:21.213 回答
-5
select Count(*) from sys.tables
于 2016-10-21T10:12:48.670 回答