Managing Indexes¶
pGenie can analyze your queries for sequential scan patterns and suggest PostgreSQL indexes that could improve performance.
Running the Index Manager¶
From the root of your project, run:
pGenie will:
- Start a temporary PostgreSQL Docker container.
- Apply all migrations in
migrations/. - Run
EXPLAINon each query inqueries/. - Identify queries that produce sequential scans on large tables where an index could help.
- Print suggested
CREATE INDEXstatements.
Interpreting the Output¶
The command outputs suggested index definitions for any queries where a sequential scan was detected on a predicate column. For example:
These are suggestions based on the query patterns in your queries/ directory. Review them and decide which to add.
Adding Suggested Indexes¶
To apply a suggestion, add a migration:
After adding the migration, run pgn generate (or pgn manage-indexes again) to verify the index is recognized.
Notes¶
- Index suggestions are heuristic. Always review them in the context of your actual data distribution and access patterns.
pgn manage-indexesdoes not modify your project files - it only prints suggestions.- The command uses the same ephemeral Docker container approach as
pgn generate, so Docker must be running.