PostgreSQL query the number of records in all tables

Method 1: (The query is only an estimated value, which is not consistent with the actual data volume)

select relname as 表名, reltuples as 记录数 
from pg_class 
where relkind = 'r' 
and relnamespace = (select oid from pg_namespace where nspname='指定schema') order by 记录数 desc;

Examples:

select relname as 表名, reltuples as 记录数 
from pg_class 
where relkind = 'r' 
and relnamespace = (select oid from pg_namespace where nspname='npas') order by 记录数 desc;

But it feels that the queried records are not consistent with the actual

 

43423432432

Method Two:

SELECT schemaname,relname,n_live_tup FROM pg_stat_user_tables 
where schemaname='npas'
ORDER BY n_live_tup DESC;

 

Reference materials:

PostgreSQL table row count

Guess you like

Origin blog.csdn.net/londa/article/details/109046131