Show which tables are closest to transaction id wraparound

29 Sep 2015

   select scma.nspname as scma,
          tbl.relname as tbl,
          ((select setting from pg_settings where name = 'autovacuum_freeze_max_age')::bigint - age(tbl.relfrozenxid)) as tx_until_forced_autovacuum
     from pg_class as tbl
left join pg_namespace scma on scma.oid = tbl.relnamespace
    where scma.nspname not in ('pg_catalog', 'information_schema')
      and scma.nspname not like 'pg_temp_%'
      and tbl.relkind = 'r'
      and ((select setting from pg_settings where name = 'autovacuum_freeze_max_age')::bigint - age(tbl.relfrozenxid)) < 500000000
 order by tx_until_forced_autovacuum asc;