-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow CLI flags to be specified by environment variable #152
Merged
Conversation
This file contains 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
Allow the flags: * `--postgres-url` * `--schema` * `--pgroll-schema` To be set via these env vars: * `PGROLL_PG_URL` * `PGROLL_SCHEMA` * `PGROLL_STATE_SCHEMA`
ca8e897
to
dac4f07
Compare
Change LGTM, can you update the docs to explain the new env vars? |
The docs for the env vars are included in the new |
Set the session `lock_timeout` for the connection used by `pgroll` to run DDL operations. The need to set `lock_timeout` for DDL operations to achieve zero downtime migrations is well documented [[1](https://xata.io/blog/postgres-schema-changes-pita#locking-gotchas)], [[2](https://medium.com/paypal-tech/postgresql-at-scale-database-schema-changes-without-downtime-20d3749ed680#00dc)]. When a DDL transaction attempts to take an `ACCESS EXCLUSIVE` lock on a table while another transaction holds a conflicting lock (such as a long-running `SELECT` query's `ACCESS SHARE` lock), other queries will queue up behind the DDL transaction until it is able to obtain the exclusive lock thus locking out reads from the table and causing downtime. By setting a `lock_timeout` the DDL transaction will abort if it is unable to acquire the lock before the timeout, freeing any other queries that were queued behind it. The approach taken here is to set the `lock_timeout` at the session level. This assumes that `pgroll` has a direct connection to the Postgres instance rather than going through a connection pooler like PGBouncer. PGBouncer's statement or transaction mode may swap out the connection between transactions/statements meaning that the lock timeout may not be applied correctly. See [[3](https://jpcamara.com/2023/04/12/pgbouncer-is-useful.html)] for a more detailed discussion of PGBouncer's behaviour here. The new `--lock-timeout` flag (and `PGROLL_LOCK_TIMEOUT` env var) is used to control the timeout duration. Fixes #65
exekias
approved these changes
Oct 2, 2023
andrew-farries
added a commit
that referenced
this pull request
Nov 22, 2023
Fix the `pgroll status` command so that it shows the status for the correct schema (ie the one set by the `--schema` flag, or `"public"` by default). Prior to this the command would show the status for the `--pgroll-schema` (`"pgroll"` by default). This appears to have been broken since #152.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bind command line arguments to env vars. Allow the flags:
--postgres-url
--schema
--pgroll-schema
To be set via these env vars:
PGROLL_PG_URL
PGROLL_SCHEMA
PGROLL_STATE_SCHEMA
If a flag is specified both via a CLI flag and an env var the CLI flag takes priority.