Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the total number of tables in postgresql?

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.

like image 974
harry Avatar asked Dec 18 '12 11:12

harry


People also ask

How do I find the number of tables in PostgreSQL?

Use the \dt or \dt+ command in psql to show tables in a specific database. Use the SELECT statement to query table information from the pg_catalog.

How many tables can you have in PostgreSQL?

Technically Postgres does not have a limit on the number of tables. However, each table is a file on the OS filesystem. And the OS probably has some opinion on how many files is "too many".

How do I list all databases in PostgreSQL?

Use \l or \l+ in psql to show all databases in the current PostgreSQL server. Use the SELECT statement to query data from the pg_database to get all databases.


2 Answers

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'; 
like image 79
a_horse_with_no_name Avatar answered Oct 05 '22 16:10

a_horse_with_no_name


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 ; 
like image 37
sufleR Avatar answered Oct 05 '22 16:10

sufleR