{"id":17680277,"url":"https://github.com/kostya/pg_reindex","last_synced_at":"2025-05-07T13:01:21.466Z","repository":{"id":3530767,"uuid":"4590157","full_name":"kostya/pg_reindex","owner":"kostya","description":"Console utility for gracefully rebuild indexes/pkeys for PostgreSQL, with minimal locking in semi-auto mode.","archived":false,"fork":false,"pushed_at":"2016-08-20T13:28:51.000Z","size":20,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T17:17:45.331Z","etag":null,"topics":["indexes","pkey","postgresql","rebuild","reindex"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kostya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-07T20:36:06.000Z","updated_at":"2024-11-15T23:00:23.000Z","dependencies_parsed_at":"2022-08-21T00:20:57.354Z","dependency_job_id":null,"html_url":"https://github.com/kostya/pg_reindex","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kostya%2Fpg_reindex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kostya%2Fpg_reindex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kostya%2Fpg_reindex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kostya%2Fpg_reindex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kostya","download_url":"https://codeload.github.com/kostya/pg_reindex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252883219,"owners_count":21819157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["indexes","pkey","postgresql","rebuild","reindex"],"created_at":"2024-10-24T09:06:25.049Z","updated_at":"2025-05-07T13:01:21.381Z","avatar_url":"https://github.com/kostya.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pg Reindex\n==========\n\nConsole utility for gracefully rebuild indexes/pkeys for PostgreSQL, with minimal locking in semi-auto mode.\n\nInstall:\n\n    $ gem install pg_reindex\n  \nUsing:\n\n    export PGRE_CFG=/some/path/database.yml\n    pgre --help\n\nDatabase.yml from rails application. User in connection settings should be an owner of relations. And for rebuild pkey, should be a superuser.\n\nTasks:\n\n    pgre dbs                                        # Show list of databases from database.yml\n    pgre install ENV                                # Install function swap_for_pkey to database\n    pgre rebuild ENV (table|index)[,(table|index)]  # rebuild tables,indexes,pkeys\n    pgre tables ENV                                 # Show tables of database\n\nUse case:\n  \n    # Show databases\n    pgre dbs\n\n    # Show tables with indexes, which full size more than 1Gb\n    pgre tables production -s 1000\n\n    # Show process without really rebuild\n    pgre rebuild production users,some_index1\n  \n    # Rebuild indexes \n    pgre rebuild production users --write\n    \n    # Rebuild indexes and no ask confirmation (not recommended)\n    pgre rebuild production users --write --no-ask  \n\n\nExplanation/Warning:\n--------------------\n\nRebuild index produces sqls:\n    \n    1. CREATE INDEX CONCURRENTLY bla2 on some_table USING btree (some_field);\n    2. ANALYZE some_table;\n    3. DROP INDEX bla;\n    4. ALTER INDEX bla2 RENAME TO bla; \n    \n1 can be blocked by long running query(LRQ), or autovacuum (in this case kill autovacuum or wait LRQ).\n**By careful**, if between 1 and (3,4) started LRQ or autovacuum, in this case (3,4) will block all queries on this table. \nIf it happens, and (3,4) not quit after \u003c 30s, you should stop (3,4) by cancel query in PostgreSQL, and later execute manually.\n  \n  \nRebuild pkey produces sqls:\n  \n    1. CREATE UNIQUE INDEX CONCURRENTLY some_table_pkey2 on some_table USING btree (ID);\n    2. ANALYZE some_table;\n    3. SELECT swap_for_pkey('public', 'some_table_pkey', 'some_table_pkey2');\n\n  Same issue with 1 and 3.\n\n\nMIT-LICENCE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkostya%2Fpg_reindex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkostya%2Fpg_reindex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkostya%2Fpg_reindex/lists"}