Get table row counts quickly in PostgreSQL
30 Jul 2015
These row counts won't be as exact as
select count(*) from my_table, but they will run a lot quicker.
select n_live_tup as rough_row_count from pg_stat_user_tables where schemaname = 'public' and relname = 'my_table';
select t.reltuples as rough_row_count from pg_class as t join pg_namespace as s on t.relnamespace = s.oid where s.nspname = 'public' and t.relname = 'my_table';