Find the row count for all tables in Postgres

via https://stackoverflow.com/a/2611745

  • total count
1
2
3
4
5
6
7
SELECT
  sum(reltuples)
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE
  nspname NOT IN ('pg_catalog', 'information_schema') AND
  relkind='r';
  • summary details
1
2
3
4
5
6
7
8
SELECT
  nspname AS schemaname,relname,reltuples
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE
  nspname NOT IN ('pg_catalog', 'information_schema') AND
  relkind='r'
ORDER BY reltuples DESC;
# NOTE: I am not responsible for any expired content.
create@2021-05-07T04:03:57+08:00
update@2021-05-07T04:04:24+08:00
comment@https://github.com/ferstar/blog/issues/40
加载评论