Index bloat after a bulk delete

Back to list2024-05-21
You

I deleted 12M rows and the index is still the same size. Why?

ChatGPT

Deleting rows marks them dead but leaves index entries until vacuum reclaims the pages, and even then the pages stay allocated to that index. REINDEX INDEX CONCURRENTLY is what actually returns the space.

You

How many database connections should a service with 4 workers open?

ChatGPT

Start from cores, not workers. A pool of about twice the database core count is the usual ceiling, so 8 to 16 for a small instance. Beyond that throughput flattens and latency grows, because the connections queue inside postgres instead of in your pool.

You

Should I store user settings as JSONB or as real columns?

ChatGPT

Columns for anything you filter or join on, JSONB for the long tail nobody queries. The moment you write a WHERE settings->>'plan' = ... that runs often, that key has earned a column and an index.