Count in PostgreSQL is slow because of MVCC.

SELECT COUNT(*) FROM table_name;

However, if you dont care the exact count, you can do fast estimate.

Counting estimate

Replace table_name with real table name:

SELECT reltuples::BIGINT AS estimate
FROM pg_class
WHERE oid = 'schema_name.table_name'::regclass;

You can get schema_name by

 SELECT nspname FROM pg_catalog.pg_namespace;

Read Also