diff --git a/bitnami/postgresql/11/debian-9/Dockerfile b/bitnami/postgresql/11/debian-9/Dockerfile index dbaffd2cbd7b..13256ffb3b32 100644 --- a/bitnami/postgresql/11/debian-9/Dockerfile +++ b/bitnami/postgresql/11/debian-9/Dockerfile @@ -16,7 +16,7 @@ RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen COPY rootfs / RUN /postunpack.sh ENV BITNAMI_APP_NAME="postgresql" \ - BITNAMI_IMAGE_VERSION="11.5.0-debian-9-r69" \ + BITNAMI_IMAGE_VERSION="11.5.0-debian-9-r70" \ LANG="en_US.UTF-8" \ LANGUAGE="en_US:en" \ NAMI_PREFIX="/.nami" \ diff --git a/bitnami/postgresql/11/debian-9/rootfs/libpostgresql.sh b/bitnami/postgresql/11/debian-9/rootfs/libpostgresql.sh index 16ac9a94344a..e2205057aad9 100644 --- a/bitnami/postgresql/11/debian-9/rootfs/libpostgresql.sh +++ b/bitnami/postgresql/11/debian-9/rootfs/libpostgresql.sh @@ -138,6 +138,11 @@ export POSTGRESQL_REPLICATION_USER="${POSTGRESQL_REPLICATION_USER:-}" export POSTGRESQL_SYNCHRONOUS_COMMIT_MODE="${POSTGRESQL_SYNCHRONOUS_COMMIT_MODE:-on}" export POSTGRESQL_FSYNC="${POSTGRESQL_FSYNC:-on}" export POSTGRESQL_USERNAME="${POSTGRESQL_USERNAME:-postgres}" + +# Version +export POSTGRESQL_VERSION="$(echo "$BITNAMI_IMAGE_VERSION" | grep -oP "^\d+\.\d+\.\d+")" +export POSTGRESQL_MAJOR_VERSION="$(echo "$BITNAMI_IMAGE_VERSION" | grep -oP "^\d+")" + EOF if [[ -f "${POSTGRESQL_PASSWORD_FILE:-}" ]]; then cat <<"EOF" @@ -474,6 +479,30 @@ postgresql_is_file_external() { fi } +######################## +# Remove flags and postmaster files from a previous run (case of container restart) +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_clean_from_restart() { + local -r -a files=( + "$POSTGRESQL_DATA_DIR"/postmaster.pid + "$POSTGRESQL_DATA_DIR"/standby.signal + "$POSTGRESQL_DATA_DIR"/recovery.signal + ) + + for file in "${files[@]}"; do + if [[ -f "$file" ]]; then + postgresql_info "Cleaning stale $file file" + rm "$file" + fi + done +} + ######################## # Ensure PostgreSQL is initialized # Globals: @@ -485,7 +514,7 @@ postgresql_is_file_external() { ######################### postgresql_initialize() { postgresql_info "Initializing PostgreSQL database..." - + postgresql_clean_from_restart # This fixes an issue where the trap would kill the entrypoint.sh, if a PID was left over from a previous run # Exec replaces the process without creating a new one, and when the container is restarted it may have the same PID rm -f "$POSTGRESQL_PID_FILE" @@ -518,11 +547,6 @@ postgresql_initialize() { if ! is_dir_empty "$POSTGRESQL_DATA_DIR"; then postgresql_info "Deploying PostgreSQL with persisted data..." - local -r postmaster_path="$POSTGRESQL_DATA_DIR"/postmaster.pid - if [[ -f "$postmaster_path" ]]; then - postgresql_info "Cleaning stale postmaster.pid file" - rm "$postmaster_path" - fi is_boolean_yes "$create_pghba_file" && postgresql_restrict_pghba is_boolean_yes "$create_conf_file" && postgresql_configure_replication_parameters is_boolean_yes "$create_conf_file" && postgresql_configure_fsync @@ -800,9 +824,15 @@ postgresql_slave_init_db() { ######################### postgresql_configure_recovery() { postgresql_info "Setting up streaming replication slave..." - cp -f "$POSTGRESQL_BASE_DIR/share/recovery.conf.sample" "$POSTGRESQL_RECOVERY_FILE" - chmod 600 "$POSTGRESQL_RECOVERY_FILE" - postgresql_set_property "standby_mode" "on" "$POSTGRESQL_RECOVERY_FILE" - postgresql_set_property "primary_conninfo" "host=${POSTGRESQL_MASTER_HOST} port=${POSTGRESQL_MASTER_PORT_NUMBER} user=${POSTGRESQL_REPLICATION_USER} password=${POSTGRESQL_REPLICATION_PASSWORD} application_name=${POSTGRESQL_CLUSTER_APP_NAME}" "$POSTGRESQL_RECOVERY_FILE" - postgresql_set_property "trigger_file" "/tmp/postgresql.trigger.${POSTGRESQL_MASTER_PORT_NUMBER}" "$POSTGRESQL_RECOVERY_FILE" + if (( POSTGRESQL_MAJOR_VERSION >= 12 )); then + postgresql_set_property "primary_conninfo" "host=${POSTGRESQL_MASTER_HOST} port=${POSTGRESQL_MASTER_PORT_NUMBER} user=${POSTGRESQL_REPLICATION_USER} password=${POSTGRESQL_REPLICATION_PASSWORD} application_name=${POSTGRESQL_CLUSTER_APP_NAME}" "$POSTGRESQL_CONF_FILE" + postgresql_set_property "promote_trigger_file" "/tmp/postgresql.trigger.${POSTGRESQL_MASTER_PORT_NUMBER}" "$POSTGRESQL_CONF_FILE" + touch "$POSTGRESQL_DATA_DIR"/standby.signal + else + cp -f "$POSTGRESQL_BASE_DIR/share/recovery.conf.sample" "$POSTGRESQL_RECOVERY_FILE" + chmod 600 "$POSTGRESQL_RECOVERY_FILE" + postgresql_set_property "standby_mode" "on" "$POSTGRESQL_RECOVERY_FILE" + postgresql_set_property "primary_conninfo" "host=${POSTGRESQL_MASTER_HOST} port=${POSTGRESQL_MASTER_PORT_NUMBER} user=${POSTGRESQL_REPLICATION_USER} password=${POSTGRESQL_REPLICATION_PASSWORD} application_name=${POSTGRESQL_CLUSTER_APP_NAME}" "$POSTGRESQL_RECOVERY_FILE" + postgresql_set_property "trigger_file" "/tmp/postgresql.trigger.${POSTGRESQL_MASTER_PORT_NUMBER}" "$POSTGRESQL_RECOVERY_FILE" + fi } diff --git a/bitnami/postgresql/README.md b/bitnami/postgresql/README.md index 6f7949395a69..3c3ba50f2924 100644 --- a/bitnami/postgresql/README.md +++ b/bitnami/postgresql/README.md @@ -48,7 +48,7 @@ Learn more about the Bitnami tagging policy and the difference between rolling t * [`12-debian-9`, `12.0.0-debian-9-r0`, `12`, `12.0.0`, `12.0.0-r0` (12/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/12.0.0-debian-9-r0/12/debian-9/Dockerfile) * [`12-centos-7`, `12.0.0-centos-7-r1` (12/centos-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/12.0.0-centos-7-r1/12/centos-7/Dockerfile) * [`11-ol-7`, `11.5.0-ol-7-r76` (11/ol-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/11.5.0-ol-7-r76/11/ol-7/Dockerfile) -* [`11-debian-9`, `11.5.0-debian-9-r69`, `11`, `11.5.0`, `11.5.0-r69`, `latest` (11/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/11.5.0-debian-9-r69/11/debian-9/Dockerfile) +* [`11-debian-9`, `11.5.0-debian-9-r70`, `11`, `11.5.0`, `11.5.0-r70`, `latest` (11/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/11.5.0-debian-9-r70/11/debian-9/Dockerfile) * [`11-centos-7`, `11.5.0-centos-7-r71` (11/centos-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/11.5.0-centos-7-r71/11/centos-7/Dockerfile) * [`10-ol-7`, `10.10.0-ol-7-r74` (10/ol-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/10.10.0-ol-7-r74/10/ol-7/Dockerfile) * [`10-debian-9`, `10.10.0-debian-9-r70`, `10`, `10.10.0`, `10.10.0-r70` (10/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/10.10.0-debian-9-r70/10/debian-9/Dockerfile) diff --git a/bitnami/postgresql/docker-compose-replication.yml b/bitnami/postgresql/docker-compose-replication.yml index b8930e85b591..58b3086aa63c 100644 --- a/bitnami/postgresql/docker-compose-replication.yml +++ b/bitnami/postgresql/docker-compose-replication.yml @@ -2,7 +2,7 @@ version: '2' services: postgresql-master: - image: 'bitnami/postgresql:11' + image: 'bitnami/postgresql:12' ports: - '5432' volumes: @@ -16,7 +16,7 @@ services: - POSTGRESQL_DATABASE=my_database - ALLOW_EMPTY_PASSWORD=yes postgresql-slave: - image: 'bitnami/postgresql:11' + image: 'bitnami/postgresql:12' ports: - '5432' depends_on: