0
0
PostgreSQLquery~5 mins

Analyzing index usage with pg_stat in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the pg_stat_user_indexes view in PostgreSQL?
It shows statistics about index usage for user-created indexes, helping you understand how often indexes are scanned or used.
Click to reveal answer
beginner
Which column in pg_stat_user_indexes tells you how many times an index was scanned?
The idx_scan column shows the number of index scans performed using that index.
Click to reveal answer
intermediate
How can you identify unused indexes using pg_stat_user_indexes?
Indexes with idx_scan value of zero have never been used for scanning and might be candidates for removal.
Click to reveal answer
intermediate
What does a high idx_tup_fetch value indicate in index statistics?
It indicates many table rows were fetched through the index scans, showing the index is actively helping queries.
Click to reveal answer
beginner
Why is it important to analyze index usage with pg_stat_user_indexes?
Because unused or rarely used indexes add overhead to writes and storage without benefit, so analyzing helps optimize performance.
Click to reveal answer
Which PostgreSQL view provides statistics about user index usage?
Apg_stat_activity
Bpg_stat_user_indexes
Cpg_indexes
Dpg_locks
If an index has idx_scan = 0, what does it mean?
AThe index is heavily used
BThe index is being rebuilt
CThe index is corrupted
DThe index has never been scanned
What does a high idx_tup_fetch value indicate?
AIndex is locked
BMany index scans failed
CMany rows fetched via index scans
DIndex is unused
Why might you want to drop an index with zero scans?
AIt wastes storage and slows writes
BIt slows down SELECT queries
CIt causes deadlocks
DIt prevents backups
Which command shows index usage statistics in PostgreSQL?
ASELECT * FROM pg_stat_user_indexes;
BSHOW INDEXES;
CEXPLAIN ANALYZE;
DSELECT * FROM pg_locks;
Explain how you can use pg_stat_user_indexes to find indexes that might be removed to improve performance.
Look for indexes with no scans and consider their cost.
You got /4 concepts.
    Describe what information pg_stat_user_indexes provides about index usage and why it is useful.
    Think about how index stats relate to query performance.
    You got /4 concepts.