-
Notifications
You must be signed in to change notification settings - Fork 1.2k
POSTGRES_XLOG_DIR to specify transaction log dir #224
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
Conversation
I just rebased on your latest changes, tests still pass. Please let me know if there is anything I can do to help get this merged. |
When it's used, isn't this directory something the user ought to be persisting as well? |
Definitely. I didn't add another VOLUME because VOLUMEs can't be undefined and not everyone will want multiple VOLUMEs for their data. Additionally, users don't necessarily need another VOLUME to use this. A user could define PGDATA to /var/lib/postgresql/data/pg_data, and POSTGRES_XLOG_DIR to /var/lib/postgresql/data/pg_xlog, and both would be persisted within that volume. But it also gives them the option to attach different volumes to these mount points, or to volumes specified at runtime. The transaction log and the data files have different performance requirements/optimizations, and it's useful to be able to put them on mountpoints which take advantage of the required characteristics. |
So in the case of the xlogdir being a subdirectory of I'm kind of inclined to put the permissions responsibility for this in the hands of the user, since it's already possible to do so today without explicit support for this functionality. To put it another way, if we accept this knob for this directory/flag, which |
The reason I created this fork/pull request is that I didn't find a way to have this work without modifying the upstream image. I initially tried having xlogdir as a subdirectory of $PGDATA. Postgres refuses to allow initdb to occur unless the data directory is empty. This creates problems if you are trying to mount a different volume onto that directory, because then the xlogdir directory exists and it's not an empty directory. I certainly understand the general concern about not wanting to cover every permutation of every use case. That's where things like POSTGRES_INITDB_ARGS allow users to customize the image for themselves at runtime. Once users start having to manually fiddle with permissions just to launch a container, docker ceases to be something which removes administrative burden in the way it ought to, and I don't see a way around it in this case. |
@tianon I just rebased again. I understand the desire to not have complicated support for every potential permutation of how Postgres is used, but I'd also point out that creating directories/setting permissions automatically so postgres can start without intervention does seem to be something that is seen as worth doing already - it's just that the current code doesn't work if you are using a custom transaction log directory. If my commit can be merged as-is, yay! Or if you have alternative suggestions for how I could support this use case, or a more generalized merge-worthy approach I could implement which would cover my use case, I would be pleased to work towards having something which is merge-worthy. |
docker-entrypoint.sh
Outdated
chmod 700 "$POSTGRES_XLOG_DIR" | ||
chown -R postgres "$POSTGRES_XLOG_DIR" | ||
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR" | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience and good-nature, @DanielDent 😞 ❤️
I'm not 100% sold, but I concede that we probably need something for this. Here are my thoughts on the implementation:
- I'd like a blank space above the comment (so that the
/var/run/postgresql
lines are separated from these) - I'd rather name the variable
POSTGRES_INITDB_XLOGDIR
so it makes it more clear what it interacts with (and maps directly to the option it enables) - the
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS ..."
line should start withexport
,
ieexport POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS ..."
- the four-space indent you've got should be tabs (matching the rest of the file) 👍
Happy to take over for any of this if you'd prefer, but want to give you first dibs (and a chance to converse if what I've proposed doesn't make sense or isn't accurate 😄) ❤️
513274c
to
9d0b63f
Compare
Great. I've incorporated your proposed changes. Additionally, I reworked things slightly to support secrets (file_env), which did not exist when I originally made these changes. I can revert that if need be - I suspect the desired interface is 'all environment variables can also be provided as file secrets' but I haven't read a style guide on the subject. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on including file_env
! 👍
Just a couple minor comments and I think we're good to go!
docker-entrypoint.sh
Outdated
@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then | |||
|
|||
# look specifically for PG_VERSION, as it is expected in the DB dir | |||
if [ ! -s "$PGDATA/PG_VERSION" ]; then | |||
file_env 'POSTGRES_INITDB_ARGS' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one needs to stay here in case we didn't hit the [ "$(id -u)" = '0' ]
block for the above if
(it should be harmless to duplicate it -- the function takes care of making sure multi-invocation is safe).
docker-entrypoint.sh
Outdated
@@ -37,6 +37,16 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then | |||
chown -R postgres /var/run/postgresql | |||
chmod g+s /var/run/postgresql | |||
|
|||
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line appears to still be space-indented. 😄
Adds support for the POSTGRES_INITDB_XLOGDIR environment variable, which specifies where the postgres transaction log is stored. For some use cases, being able to place the transaction log on a different volume is useful. Existing support for providing flags via $POSTGRES_INITDB_ARGS is inadequate because of the need to create and chown/chmod the directory prior to running initdb.
Thanks. Re-pushed. |
@tianon ping |
… to where it'll be invoked regardless of our "root" status
Sorry for the delay @DanielDent; I thought of another edge case (users who use |
Thanks for your patience! |
- `memcached`: 1.4.36 - `postgres`: add `POSTGRES_INITDB_XLOGDIR` variable for `--xlogdir` during `initdb` (docker-library/postgres#224) - `pypy`: 5.7.0
docker-library/postgres#224 and docker-library/official-images#2762 added the POSTGRES_XLOG_DIR variable. This adds documentation for that variable.
docker-library/postgres#224 and docker-library/official-images#2762 added the POSTGRES_INITDB_XLOGDIR variable. This adds documentation for that variable.
Adds support for the POSTGRES_XLOG_DIR environment variable, which specifies where the postgres transaction log is stored.
For some use cases, being able to place the transaction log on a different volume is useful.
(Existing support for providing flags via $POSTGRES_INITDB_ARGS is inadequate because of the need to create and chown/chmod the directory prior to running initdb)