Skip to content

Commit 34c02de

Browse files
committed
POSTGRES_XLOG_DIR to specify transaction log dir
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.
1 parent 7f792e7 commit 34c02de

11 files changed

+77
-0
lines changed

9.2/alpine/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec su-exec postgres "$BASH_SOURCE" "$@"
4148
fi

9.2/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec gosu postgres "$BASH_SOURCE" "$@"
4148
fi

9.3/alpine/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec su-exec postgres "$BASH_SOURCE" "$@"
4148
fi

9.3/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec gosu postgres "$BASH_SOURCE" "$@"
4148
fi

9.4/alpine/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec su-exec postgres "$BASH_SOURCE" "$@"
4148
fi

9.4/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec gosu postgres "$BASH_SOURCE" "$@"
4148
fi

9.5/alpine/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec su-exec postgres "$BASH_SOURCE" "$@"
4148
fi

9.5/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec gosu postgres "$BASH_SOURCE" "$@"
4148
fi

9.6/alpine/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec su-exec postgres "$BASH_SOURCE" "$@"
4148
fi

9.6/docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec gosu postgres "$BASH_SOURCE" "$@"
4148
fi

docker-entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
3636
mkdir -p /var/run/postgresql
3737
chown -R postgres /var/run/postgresql
3838
chmod g+s /var/run/postgresql
39+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
40+
if [ "$POSTGRES_XLOG_DIR" ]; then
41+
mkdir -p "$POSTGRES_XLOG_DIR"
42+
chmod 700 "$POSTGRES_XLOG_DIR"
43+
chown -R postgres "$POSTGRES_XLOG_DIR"
44+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
45+
fi
3946

4047
exec gosu postgres "$BASH_SOURCE" "$@"
4148
fi

0 commit comments

Comments
 (0)