Skip to content

Commit cc78dca

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 d2b3854 commit cc78dca

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
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.2/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.3/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.3/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.4/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.4/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.5/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.5/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.6/alpine/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

9.6/docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

docker-entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ if [ "$1" = 'postgres' ]; then
3232
chmod 700 "$PGDATA"
3333
chown -R postgres "$PGDATA"
3434

35+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
36+
if [ "$POSTGRES_XLOG_DIR" ]; then
37+
mkdir -p "$POSTGRES_XLOG_DIR"
38+
chmod 700 "$POSTGRES_XLOG_DIR"
39+
chown -R postgres "$POSTGRES_XLOG_DIR"
40+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
41+
fi
42+
3543
mkdir -p /run/postgresql
3644
chmod g+s /run/postgresql
3745
chown -R postgres /run/postgresql

0 commit comments

Comments
 (0)