PostgreSQL查询数据库中所有表的行数

--联合两层schema并比较对应表的行数是否相等(需在vacuum后才准确,否则会有增删浮动)

SELECT a.relname,a.reltuples merge,b.reltuples center,a.reltuples=b.reltuples FROM (
SELECT relname, reltuples
FROM pg_class r JOIN pg_namespace n
ON (relnamespace = n.oid)
WHERE relkind = 'r' AND n.nspname = 'merge'
) a FULL JOIN (
SELECT relname, reltuples
FROM pg_class r JOIN pg_namespace n
ON (relnamespace = n.oid)
WHERE relkind = 'r' AND n.nspname = 'center'
) b ON a.relname=b.relname

发表评论

电子邮件地址不会被公开。 必填项已用*标注