Created
March 23, 2025 20:21
-
-
Save justnoise/e94f542e782cc084c7caec12cdf4c4fd to your computer and use it in GitHub Desktop.
PG concurrent index commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- check on creation status | |
| SELECT * FROM pg_stat_progress_create_index; | |
| -- look for broken indexes | |
| SELECT * FROM pg_class, pg_index WHERE pg_index.indisvalid = false AND pg_index.indexrelid = pg_class.oid; | |
| -- fix | |
| REINDEX INDEX CONCURRENTLY idx_users_email_2019; | |
| -- find unused indexes | |
| select | |
| indexrelid::regclass as index, relid::regclass as table | |
| from | |
| pg_stat_user_indexes | |
| JOIN pg_index USING (indexrelid) | |
| where | |
| idx_scan = 0 and indisunique is false; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment