Skip to content

Commit a6ba86a

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 a6ba86a

11 files changed

+110
-11
lines changed

9.2/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec su-exec postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.2/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec gosu postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.3/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec su-exec postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.3/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec gosu postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.4/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec su-exec postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.4/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec gosu postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.5/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec su-exec postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.5/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec gosu postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.6/alpine/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec su-exec postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

9.6/docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec gosu postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

docker-entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
file_env 'POSTGRES_INITDB_XLOGDIR'
42+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
43+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
46+
file_env 'POSTGRES_INITDB_ARGS'
47+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
48+
fi
49+
4050
exec gosu postgres "$BASH_SOURCE" "$@"
4151
fi
4252

@@ -47,7 +57,6 @@ if [ "$1" = 'postgres' ]; then
4757

4858
# look specifically for PG_VERSION, as it is expected in the DB dir
4959
if [ ! -s "$PGDATA/PG_VERSION" ]; then
50-
file_env 'POSTGRES_INITDB_ARGS'
5160
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
5261

5362
# check password first so we can output the warning before postgres

0 commit comments

Comments
 (0)