Merge pull request #1259 from infosiftr/pgdata-cluster

Change `PGDATA` in 18+ to `/var/lib/postgresql/MAJOR/docker`
This commit is contained in:
yosifkit 2025-06-06 12:01:16 -07:00 committed by GitHub
commit 6ec0e42428
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
56 changed files with 873 additions and 16 deletions

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -190,10 +190,13 @@ RUN set -eux; \
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
ENV PGDATA /var/lib/postgresql/data
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
VOLUME /var/lib/postgresql/data
#
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
#
ENV PGDATA /var/lib/postgresql/18/docker
RUN ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
VOLUME /var/lib/postgresql
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -190,10 +190,13 @@ RUN set -eux; \
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
ENV PGDATA /var/lib/postgresql/data
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
VOLUME /var/lib/postgresql/data
#
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
#
ENV PGDATA /var/lib/postgresql/18/docker
RUN ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
VOLUME /var/lib/postgresql
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

11
18/bookworm/Dockerfile generated
View File

@ -183,10 +183,13 @@ RUN set -eux; \
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
ENV PGDATA /var/lib/postgresql/data
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
VOLUME /var/lib/postgresql/data
#
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
#
ENV PGDATA /var/lib/postgresql/18/docker
RUN ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
VOLUME /var/lib/postgresql
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

11
18/bullseye/Dockerfile generated
View File

@ -183,10 +183,13 @@ RUN set -eux; \
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
ENV PGDATA /var/lib/postgresql/data
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
VOLUME /var/lib/postgresql/data
#
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
#
ENV PGDATA /var/lib/postgresql/18/docker
RUN ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
VOLUME /var/lib/postgresql
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -212,10 +212,20 @@ RUN set -eux; \
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
{{ if .major >= 18 then ( -}}
#
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
#
ENV PGDATA /var/lib/postgresql/{{ .major | tostring }}/docker
RUN ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
VOLUME /var/lib/postgresql
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
{{ ) else ( -}}
ENV PGDATA /var/lib/postgresql/data
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
VOLUME /var/lib/postgresql/data
{{ ) end -}}
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh

View File

@ -183,10 +183,20 @@ RUN set -eux; \
RUN install --verbose --directory --owner postgres --group postgres --mode 3777 /var/run/postgresql
{{ if .major >= 18 then ( -}}
#
# NOTE: in 18+, PGDATA has changed to match the pg_ctlcluster standard directory structure, and the VOLUME has moved from /var/lib/postgresql/data to /var/lib/postgresql
#
ENV PGDATA /var/lib/postgresql/{{ .major | tostring }}/docker
RUN ln -svT . /var/lib/postgresql/data # https://github.com/docker-library/postgres/pull/1259#issuecomment-2215477494
VOLUME /var/lib/postgresql
# ("/var/lib/postgresql" is already pre-created with suitably usable permissions above)
{{ ) else ( -}}
ENV PGDATA /var/lib/postgresql/data
# this 1777 will be replaced by 0700 at runtime (allows semi-arbitrary "--user" values)
RUN install --verbose --directory --owner postgres --group postgres --mode 1777 "$PGDATA"
VOLUME /var/lib/postgresql/data
{{ ) end -}}
COPY docker-entrypoint.sh docker-ensure-initdb.sh /usr/local/bin/
RUN ln -sT docker-ensure-initdb.sh /usr/local/bin/docker-enforce-initdb.sh

View File

@ -33,6 +33,7 @@ fi
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null

View File

@ -154,6 +154,29 @@ docker_verify_minimum_env() {
EOWARN
fi
}
# similar to the above, but errors if there are any "old" databases detected (usually due to upgrades without pg_upgrade)
docker_error_old_databases() {
if [ -n "${OLD_DATABASES[0]:-}" ]; then
cat >&2 <<-EOE
Error: in 18+, these Docker images are configured to store database data in a
format which is compatible with "pg_ctlcluster" (specifically, using
major-version-specific directory names). This better reflects how
PostgreSQL itself works, and how upgrades are to be performed.
See also https://github.com/docker-library/postgres/pull/1259
Counter to that, there appears to be PostgreSQL data in:
${OLD_DATABASES[*]}
This is usually the result of upgrading the Docker image without upgrading
the underlying database using "pg_upgrade" (which requires both versions).
See https://github.com/docker-library/postgres/issues/37 for a (long)
discussion around this process, and suggestions for how to do so.
EOE
exit 1
fi
}
# usage: docker_process_init_files [file [file [...]]]
# ie: docker_process_init_files /always-initdb.d/*
@ -230,9 +253,17 @@ docker_setup_env() {
declare -g DATABASE_ALREADY_EXISTS
: "${DATABASE_ALREADY_EXISTS:=}"
declare -ag OLD_DATABASES=()
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
DATABASE_ALREADY_EXISTS='true'
elif [ "$PGDATA" = "/var/lib/postgresql/$PG_MAJOR/docker" ]; then
# https://github.com/docker-library/postgres/pull/1259
for d in /var/lib/postgresql /var/lib/postgresql/data /var/lib/postgresql/*/docker; do
if [ -s "$d/PG_VERSION" ]; then
OLD_DATABASES+=( "$d" )
fi
done
fi
}
@ -319,6 +350,7 @@ _main() {
# only run initialization on an empty data directory
if [ -z "$DATABASE_ALREADY_EXISTS" ]; then
docker_verify_minimum_env
docker_error_old_databases
# check dir permissions to reduce likelihood of half-initialized database
ls /docker-entrypoint-initdb.d/ > /dev/null