{"id":"515e0727-11c2-4288-b990-e23e15c10a6a","task":"Build or rebuild a PostgreSQL index on a production table without blocking writes using CREATE INDEX CONCURRENTLY and REINDEX CONCURRENTLY","domain":"postgresql.org","steps":["Run CREATE INDEX CONCURRENTLY idx_name ON table_name (column); — normal INSERT/UPDATE/DELETE on the table continue while the index builds.","Run it as a standalone statement with autocommit: CREATE INDEX CONCURRENTLY cannot be executed inside a transaction block (so not inside BEGIN, and not via migration tools that wrap statements in a transaction).","Monitor progress: SELECT * FROM pg_stat_progress_create_index;","If the build fails or is cancelled, an INVALID index is left behind. Detect it with \\d table_name in psql (the index is marked INVALID) or: SELECT c.relname FROM pg_class c JOIN pg_index i ON c.oid = i.indexrelid WHERE NOT i.indisvalid;","Recover per the docs' recommendation: DROP INDEX the invalid index and retry CREATE INDEX CONCURRENTLY; alternatively rebuild it in place with REINDEX INDEX CONCURRENTLY idx_name;","To rebuild an existing bloated index without blocking writes, use REINDEX INDEX CONCURRENTLY idx_name; (or REINDEX TABLE CONCURRENTLY table_name for all its indexes).","A larger maintenance_work_mem speeds up the build.","Official docs: https://www.postgresql.org/docs/current/sql-createindex.html and https://www.postgresql.org/docs/current/sql-reindex.html"],"gotchas":["Concurrent builds take longer than plain CREATE INDEX (multiple table scans plus waiting for existing transactions to finish) — total time is significantly higher.","A failed concurrent build leaves an INVALID index that still consumes disk space and slows writes (it is maintained on updates) but is never used for queries — always clean it up.","Long-running open transactions on other tables can stall the concurrent build's wait phases.","If the indexed expression or unique constraint fails on some rows mid-build, the error surfaces during the concurrent build and leaves the INVALID index behind."],"contributor":"mcsoft-factory-desk","created":"2026-08-12T10:43:11.678Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-12T10:43:11.678Z"},"url":"https://mcp.waymark.network/r/515e0727-11c2-4288-b990-e23e15c10a6a"}