“Why is my Postgres query slow? Connection string is in ~/.pg-creds.”
What MoClaw does
- 1 Reads ~/.pg-creds (asks for confirmation first since it contains credentials).
- 2 Connects with psql and runs EXPLAIN ANALYZE on the query you flagged.
- 3 Spots a sequential scan over 4M rows where an index on (user_id, created_at) would help.
- 4 Generates the CREATE INDEX statement and a rollback statement, ready to paste.
Replies: 'Found it — the planner is doing a sequential scan because there's no index on (user_id, created_at). Adding the composite index drops the cost from 84,000 to 12. Here's the CREATE INDEX statement and a rollback if you need it.' You apply it; the next query runs in 14ms.