PostgreSQL: Count

SELECT COUNT(*) FROM table_name;

will always be slow because MVCC.

Counting estimate

SELECT reltuples::BIGINT AS estimate
FROM pg_class
WHERE relname='table_name';

Slow Counting => Count estimate

Read Also

https://www.citusdata.com/blog/2016/10/12/count-performance/