Skip to content

Commit 6d48d68

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 03f4064 commit 6d48d68

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
@@ -10,6 +10,14 @@ if [ "$1" = 'postgres' ]; then
1010
chmod 700 "$PGDATA"
1111
chown -R postgres "$PGDATA"
1212

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
chown -R postgres /run/postgresql

9.2/docker-entrypoint.sh

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

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
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
@@ -10,6 +10,14 @@ if [ "$1" = 'postgres' ]; then
1010
chmod 700 "$PGDATA"
1111
chown -R postgres "$PGDATA"
1212

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
chown -R postgres /run/postgresql

9.3/docker-entrypoint.sh

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

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
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
@@ -10,6 +10,14 @@ if [ "$1" = 'postgres' ]; then
1010
chmod 700 "$PGDATA"
1111
chown -R postgres "$PGDATA"
1212

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
chown -R postgres /run/postgresql

9.4/docker-entrypoint.sh

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

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
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
@@ -10,6 +10,14 @@ if [ "$1" = 'postgres' ]; then
1010
chmod 700 "$PGDATA"
1111
chown -R postgres "$PGDATA"
1212

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
chown -R postgres /run/postgresql

9.5/docker-entrypoint.sh

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

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
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
@@ -10,6 +10,14 @@ if [ "$1" = 'postgres' ]; then
1010
chmod 700 "$PGDATA"
1111
chown -R postgres "$PGDATA"
1212

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
chown -R postgres /run/postgresql

9.6/docker-entrypoint.sh

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

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
chown -R postgres /run/postgresql

docker-entrypoint.sh

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

13+
# Create the transaction log directory before initdb is run (below) so the directory is owend by the correct user
14+
if [ "$POSTGRES_XLOG_DIR" ]; then
15+
mkdir -p "$POSTGRES_XLOG_DIR"
16+
chmod 700 "$POSTGRES_XLOG_DIR"
17+
chown -R postgres "$POSTGRES_XLOG_DIR"
18+
POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_XLOG_DIR"
19+
fi
20+
1321
mkdir -p /run/postgresql
1422
chmod g+s /run/postgresql
1523
chown -R postgres /run/postgresql

0 commit comments

Comments
 (0)