Find the row count for all your tables in a Postgres database

select table_schema, 
(xpath('/row/cnt/text()', xml_count))[1]::text::int as row_count
from (
select table_name, table_schema,
query_to_xml(format('select count(*) as cnt from %I.%I', table_schema, table_name), false, true, '') as xml_count
from information_schema.tables
where table_schema = 'public' --<< change here for the schema you want
) t order by row_count desc;




System Administrator and Full stack web developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

IOT With Wemos

RESTful API: The Principles and Constraints

READ/DOWNLOAD*( Principles of Electric Circuits: Conventional Current Version (9th Edition) FULL…

We Migrated From AWS Lambda to ECS, but Hope to Eventually Migrate Back

AWS Lambda vs ECS

Everyday Linux Essentials

How did I do to resolve the Spark Serialization error?

Pitfalls of Templates type deduction in C++

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Himanshu Pratap

Himanshu Pratap

System Administrator and Full stack web developer.

More from Medium

PostgreSQL vs MySQL (Which is better for Business Intelligence Reporting?)

Introduction to SQL

Introduction to SQL

Database Anomalies

Oracle RMAN Compression