{"id":24782571,"url":"https://github.com/levkk/pg-sequence-increaser","last_synced_at":"2025-08-01T00:35:18.557Z","repository":{"id":57452185,"uuid":"233138715","full_name":"levkk/pg-sequence-increaser","owner":"levkk","description":"Set all sequences to a higher value when promoting a PostgreSQL logical replica.","archived":false,"fork":false,"pushed_at":"2020-09-30T15:16:29.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T14:49:03.413Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/levkk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-10T22:10:59.000Z","updated_at":"2020-09-30T15:16:32.000Z","dependencies_parsed_at":"2022-08-26T08:23:23.006Z","dependency_job_id":null,"html_url":"https://github.com/levkk/pg-sequence-increaser","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/levkk/pg-sequence-increaser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levkk%2Fpg-sequence-increaser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levkk%2Fpg-sequence-increaser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levkk%2Fpg-sequence-increaser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levkk%2Fpg-sequence-increaser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/levkk","download_url":"https://codeload.github.com/levkk/pg-sequence-increaser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levkk%2Fpg-sequence-increaser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259944981,"owners_count":22935710,"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":[],"created_at":"2025-01-29T11:18:05.545Z","updated_at":"2025-06-15T08:34:25.631Z","avatar_url":"https://github.com/levkk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg-sequence-increaser\nSet all sequences to a higher value when promoting a PostgreSQL logical replica.\n\n\n## Requirements\n\n1. Python3\n2. `libpq-dev` (for psycopg2). On Mac OS, `brew install postgresql`, on Ubuntu, install `libpq-dev`.\n\n## Installation\n\n### Production\n\n```bash\n$ pip install pg-sequence-increaser\n```\n\n### Development\n\nUsing virtualenv,\n```bash\n$ pip install -r requirements.txt\n```\n\n### Usage\n\nThis tool implements two strategies:\n\n1. Getting the sequences and their desired values from the logical replica alone (called \"max-id-on-replica\"),\n2. getting the sequences and their desired values from the primary database, i.e. the publisher; this is called \"primary-sequences\".\n\n#### Max Id on Replica\n\nWe get the sequences from `information_schema.default_value`. Any `default_value` that has `nextval('some_sequence_name')`, we assume that's a sequence and extract the table name, the associated column and the sequence name. Then, we run `MAX(column_name)` to get the last value inserted into that table, likely from the sequence; we then move the sequence forward to the `MAX(column_name) + increment_by`. This strategy has the advantage of using the replica as the source of truth and not requiring the publisher to be online.\n\n\n```bash\n$ pgseqmover --replica-url=postgres://localhost:5432/my_db --queries-only\n```\nwill print the queries you can then run manually. Those queries will increase all sequences by 1000.\n\n#### Primary Sequences\n\nWe get the sequences from the primary (publisher). After all, that's where we are replicating from in the first place. We use `pg_sequences` view and get both the name and the `last_value` from there as well. We then set the sequences on the replica to what they are on the primary + `increment_by`. This strategy has the advantage of using the primary database as the source of truth in case replica lag is non-zero during promotion which is bad, but possible. This requires the primary to be available during promotion of the replica.\n\n\n```bash\n$ pgseqmover --replica-url=postgres://replica-db:5432/my_db --primary-url=postgres://primary-db:5432/my_db --queries-only --strategy=primary-sequences\n```\nwill print the queries you can then run manually. Those queries will increase all sequences by 1000.\n\n#### Arguments\n\nThis also accepts optional arguments:\n\n1. `--dry-run` which will show the queries it will run but not actually do anything; this is the default behavior,\n2. `--debug` will show _all_ queries it's running; can be combined with `--dry-run`,\n3. `--increment-by` overrides the default increase by value of 1000 to any value (even negative ones).\n4. `--strategy` picks the strategy to use for increasing sequences. Your options are: `primary-sequences` and `max-id-on-replica`, both explained above.\n5. `--queries-only` will only print the queries that will move the sequences and not do anything else. Less pretty version of `--dry-run`, but good for `pgseqmover --queries-only \u003e ~/Desktop/queries_to_run.sql` use case.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevkk%2Fpg-sequence-increaser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevkk%2Fpg-sequence-increaser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevkk%2Fpg-sequence-increaser/lists"}