Skip to content

Commit 513274c

Browse files
committed
POSTGRES_INITDB_XLOGDIR to specify xlog log dir
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.
1 parent 7f792e7 commit 513274c

11 files changed

+88
-0
lines changed

9.2/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec su-exec postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.2/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec gosu postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.3/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec su-exec postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.3/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec gosu postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.4/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec su-exec postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.4/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec gosu postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.5/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec su-exec postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.5/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec gosu postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.6/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec su-exec postgres "$BASH_SOURCE" "$@"
4149
fi
4250

9.6/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec gosu postgres "$BASH_SOURCE" "$@"
4149
fi
4250

docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
3939

40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
44+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
45+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_XLOGDIR --xlogdir $POSTGRES_INITDB_XLOGDIR"
46+
fi
47+
4048
exec gosu postgres "$BASH_SOURCE" "$@"
4149
fi
4250

0 commit comments

Comments
 (0)