Why does PostgreSQL sequentially scans the table for
COUNT(*) query, while there is a very small and indexed primary key?
The official wiki pages give an answer to that:
Furthermore, you could try an ANALYZE to rebuild the info for the query planer.
You should get a better performance using
If you need very quick numbers and are not afraid of querying the schema, you can do the following
But don't rely on this values as it is only an "estimated" (although often the exact) number of tuples in the table.