diff --git a/README.md b/README.md index 6a30b87..a67a2c0 100644 --- a/README.md +++ b/README.md @@ -272,6 +272,13 @@ POSTGRES_MULTIPLE_EXTENSIONS=postgis,pgrouting:3.4.0 where `pgrouting:3.4.0` The extension name is fixed with the version name with the delimiter being a colon. +**Note** In some cases, some versions of extensions might not be available for +install. To enable them you can do the following inside the container: +```bash +wget --directory-prefix /usr/share/postgresql/15/extension/ https://raw.githubusercontent.com/postgres/postgres/master/contrib/hstore/hstore--1.1--1.2.sql +``` +Then proceed to install it the normal way. + #### Shared preload libraries Some PostgreSQL extensions require shared_preload_libraries to be specified in the conf files. diff --git a/scripts/env-data.sh b/scripts/env-data.sh index b5ed587..457e217 100644 --- a/scripts/env-data.sh +++ b/scripts/env-data.sh @@ -17,6 +17,7 @@ RECOVERY_CONF="$ROOT_CONF/recovery.conf" POSTGRES="/usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/postgres" INITDB="/usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/initdb" SQLDIR="/usr/share/postgresql/${POSTGRES_MAJOR_VERSION}/contrib/postgis-${POSTGIS_MAJOR}.${POSTGIS_MINOR_RELEASE}/" +EXTDIR="/usr/share/postgresql/${POSTGRES_MAJOR_VERSION}/extension/" SETVARS="POSTGIS_ENABLE_OUTDB_RASTERS=1 POSTGIS_GDAL_ENABLED_DRIVERS=ENABLE_ALL" LOCALONLY="-c listen_addresses='127.0.0.1'" PG_BASEBACKUP="/usr/bin/pg_basebackup" @@ -526,9 +527,25 @@ function extension_install() { psql ${DATABASE} -U ${POSTGRES_USER} -p 5432 -h localhost -c "CREATE EXTENSION IF NOT EXISTS \"${EXTENSION_NAME}\" cascade;" fi else - echo -e "\e[32m [Entrypoint] Installing extension \e[1;31m ${EXTENSION_NAME} \e[32m with version \e[1;31m ${EXTENSION_VERSION} \e[32m in the database : \e[1;31m ${DATABASE} \033[0m" if [[ ${EXTENSION_NAME} != 'pg_cron' ]]; then - psql ${DATABASE} -U ${POSTGRES_USER} -p 5432 -h localhost -c "CREATE EXTENSION IF NOT EXISTS \"${EXTENSION_NAME}\" WITH VERSION '${EXTENSION_VERSION}' cascade;" + pattern="${EXTENSION_NAME}--" + last_numbers=() + for file in "$EXTDIR"/${pattern}*; do + filename=$(basename "$file" .sql) + if [[ "$filename" == *"--"* ]]; then + last_number=$(echo "$filename" | awk -F '--' '{print $NF}') + if [[ ! " ${last_numbers[@]} " =~ " $last_number " ]]; then + last_numbers+=("$last_number") + fi + fi + done + if [[ " ${last_numbers[@]} " =~ " $EXTENSION_VERSION " ]]; then + echo -e "\e[32m [Entrypoint] Installing extension \e[1;31m ${EXTENSION_NAME} \e[32m with version \e[1;31m ${EXTENSION_VERSION} \e[32m in the database : \e[1;31m ${DATABASE} \033[0m" + psql ${DATABASE} -U ${POSTGRES_USER} -p 5432 -h localhost -c "CREATE EXTENSION IF NOT EXISTS \"${EXTENSION_NAME}\" WITH VERSION '${EXTENSION_VERSION}' cascade;" + else + echo -e "\e[32m [Entrypoint] Extension \e[1;31m ${EXTENSION_NAME} \e[32m with version \e[1;31m ${EXTENSION_VERSION} \e[32m is not available for install, available versions to install are \e[1;31m "${last_numbers[@]}" \033[0m" + fi + fi fi