Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for extensions loading and creation. #399

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 10/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if $PG_INITIALIZED ; then
create_users
fi

create_extensions
process_extending_files \
"${APP_DATA}/src/postgresql-start" \
"${CONTAINER_SCRIPTS_PATH}/start"
Expand Down
9 changes: 9 additions & 0 deletions 10/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Set to an estimate of how much memory is available for disk caching by the opera
**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

**`POSTGRESQL_LIBRARIES`**
A comma-separated list of libraries that Postgres will preload using shared_preload_libraries.

**`POSTGRESQL_EXTENSIONS`**
A space-separated list of extensions to create when the server start. Once created, the extensions will stay even if the variable is cleared.


You can also set the following mount points by passing the `-v /host/dir:/container/dir:Z` flag to Docker.

**`/var/lib/pgsql/data`**
Expand Down
17 changes: 17 additions & 0 deletions 10/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function should_hack_data_sync_retry() {
return 1
}

function generate_postgresql_libraries_config() {
if [ -v POSTGRESQL_LIBRARIES ]; then
echo "shared_preload_libraries='${POSTGRESQL_LIBRARIES}'" >> "${POSTGRESQL_CONFIG_FILE}"
fi
}


# New config is generated every time a container is created. It only contains
# additional custom settings and is included from $PGDATA/postgresql.conf.
function generate_postgresql_config() {
Expand Down Expand Up @@ -171,6 +178,7 @@ function generate_postgresql_config() {
echo "log_filename = '$(basename "${POSTGRESQL_LOG_DESTINATION}")'" >>"${POSTGRESQL_CONFIG_FILE}"
fi

generate_postgresql_libraries_config
(
shopt -s nullglob
for conf in "${APP_DATA}"/src/postgresql-cfg/*.conf; do
Expand Down Expand Up @@ -516,3 +524,12 @@ process_extending_files()
done
done <<<"$(get_matched_files '*.sh' "$@" | sort -u)"
}

create_extensions()
{
if [ -v POSTGRESQL_EXTENSIONS ]; then
for EXT in $POSTGRESQL_EXTENSIONS; do
psql -c "CREATE EXTENSION IF NOT EXISTS ${EXT};"
done
fi
}
1 change: 1 addition & 0 deletions 12/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if $PG_INITIALIZED ; then
create_users
fi

create_extensions
process_extending_files \
"${APP_DATA}/src/postgresql-start" \
"${CONTAINER_SCRIPTS_PATH}/start"
Expand Down
9 changes: 9 additions & 0 deletions 12/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Set to an estimate of how much memory is available for disk caching by the opera
**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

**`POSTGRESQL_LIBRARIES`**
A comma-separated list of libraries that Postgres will preload using shared_preload_libraries.

**`POSTGRESQL_EXTENSIONS`**
A space-separated list of extensions to create when the server start. Once created, the extensions will stay even if the variable is cleared.


You can also set the following mount points by passing the `-v /host/dir:/container/dir:Z` flag to Docker.

**`/var/lib/pgsql/data`**
Expand Down
17 changes: 17 additions & 0 deletions 12/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function should_hack_data_sync_retry() {
return 1
}

function generate_postgresql_libraries_config() {
if [ -v POSTGRESQL_LIBRARIES ]; then
echo "shared_preload_libraries='${POSTGRESQL_LIBRARIES}'" >> "${POSTGRESQL_CONFIG_FILE}"
fi
}


# New config is generated every time a container is created. It only contains
# additional custom settings and is included from $PGDATA/postgresql.conf.
function generate_postgresql_config() {
Expand Down Expand Up @@ -171,6 +178,7 @@ function generate_postgresql_config() {
echo "log_filename = '$(basename "${POSTGRESQL_LOG_DESTINATION}")'" >>"${POSTGRESQL_CONFIG_FILE}"
fi

generate_postgresql_libraries_config
(
shopt -s nullglob
for conf in "${APP_DATA}"/src/postgresql-cfg/*.conf; do
Expand Down Expand Up @@ -516,3 +524,12 @@ process_extending_files()
done
done <<<"$(get_matched_files '*.sh' "$@" | sort -u)"
}

create_extensions()
{
if [ -v POSTGRESQL_EXTENSIONS ]; then
for EXT in $POSTGRESQL_EXTENSIONS; do
psql -c "CREATE EXTENSION IF NOT EXISTS ${EXT};"
done
fi
}
1 change: 1 addition & 0 deletions 13/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if $PG_INITIALIZED ; then
create_users
fi

create_extensions
process_extending_files \
"${APP_DATA}/src/postgresql-start" \
"${CONTAINER_SCRIPTS_PATH}/start"
Expand Down
9 changes: 9 additions & 0 deletions 13/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Set to an estimate of how much memory is available for disk caching by the opera
**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

**`POSTGRESQL_LIBRARIES`**
A comma-separated list of libraries that Postgres will preload using shared_preload_libraries.

**`POSTGRESQL_EXTENSIONS`**
A space-separated list of extensions to create when the server start. Once created, the extensions will stay even if the variable is cleared.


You can also set the following mount points by passing the `-v /host/dir:/container/dir:Z` flag to Docker.

**`/var/lib/pgsql/data`**
Expand Down
17 changes: 17 additions & 0 deletions 13/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function should_hack_data_sync_retry() {
return 1
}

function generate_postgresql_libraries_config() {
if [ -v POSTGRESQL_LIBRARIES ]; then
echo "shared_preload_libraries='${POSTGRESQL_LIBRARIES}'" >> "${POSTGRESQL_CONFIG_FILE}"
fi
}


# New config is generated every time a container is created. It only contains
# additional custom settings and is included from $PGDATA/postgresql.conf.
function generate_postgresql_config() {
Expand Down Expand Up @@ -171,6 +178,7 @@ function generate_postgresql_config() {
echo "log_filename = '$(basename "${POSTGRESQL_LOG_DESTINATION}")'" >>"${POSTGRESQL_CONFIG_FILE}"
fi

generate_postgresql_libraries_config
(
shopt -s nullglob
for conf in "${APP_DATA}"/src/postgresql-cfg/*.conf; do
Expand Down Expand Up @@ -516,3 +524,12 @@ process_extending_files()
done
done <<<"$(get_matched_files '*.sh' "$@" | sort -u)"
}

create_extensions()
{
if [ -v POSTGRESQL_EXTENSIONS ]; then
for EXT in $POSTGRESQL_EXTENSIONS; do
psql -c "CREATE EXTENSION IF NOT EXISTS ${EXT};"
done
fi
}
1 change: 1 addition & 0 deletions 14/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if $PG_INITIALIZED ; then
create_users
fi

create_extensions
process_extending_files \
"${APP_DATA}/src/postgresql-start" \
"${CONTAINER_SCRIPTS_PATH}/start"
Expand Down
9 changes: 9 additions & 0 deletions 14/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Set to an estimate of how much memory is available for disk caching by the opera
**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

**`POSTGRESQL_LIBRARIES`**
A comma-separated list of libraries that Postgres will preload using shared_preload_libraries.

**`POSTGRESQL_EXTENSIONS`**
A space-separated list of extensions to create when the server start. Once created, the extensions will stay even if the variable is cleared.


You can also set the following mount points by passing the `-v /host/dir:/container/dir:Z` flag to Docker.

**`/var/lib/pgsql/data`**
Expand Down
17 changes: 17 additions & 0 deletions 14/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function should_hack_data_sync_retry() {
return 1
}

function generate_postgresql_libraries_config() {
if [ -v POSTGRESQL_LIBRARIES ]; then
echo "shared_preload_libraries='${POSTGRESQL_LIBRARIES}'" >> "${POSTGRESQL_CONFIG_FILE}"
fi
}


# New config is generated every time a container is created. It only contains
# additional custom settings and is included from $PGDATA/postgresql.conf.
function generate_postgresql_config() {
Expand Down Expand Up @@ -171,6 +178,7 @@ function generate_postgresql_config() {
echo "log_filename = '$(basename "${POSTGRESQL_LOG_DESTINATION}")'" >>"${POSTGRESQL_CONFIG_FILE}"
fi

generate_postgresql_libraries_config
(
shopt -s nullglob
for conf in "${APP_DATA}"/src/postgresql-cfg/*.conf; do
Expand Down Expand Up @@ -516,3 +524,12 @@ process_extending_files()
done
done <<<"$(get_matched_files '*.sh' "$@" | sort -u)"
}

create_extensions()
{
if [ -v POSTGRESQL_EXTENSIONS ]; then
for EXT in $POSTGRESQL_EXTENSIONS; do
psql -c "CREATE EXTENSION IF NOT EXISTS ${EXT};"
done
fi
}
1 change: 1 addition & 0 deletions 15/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if $PG_INITIALIZED ; then
create_users
fi

create_extensions
process_extending_files \
"${APP_DATA}/src/postgresql-start" \
"${CONTAINER_SCRIPTS_PATH}/start"
Expand Down
9 changes: 9 additions & 0 deletions 15/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Set to an estimate of how much memory is available for disk caching by the opera
**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

**`POSTGRESQL_LIBRARIES`**
A comma-separated list of libraries that Postgres will preload using shared_preload_libraries.

**`POSTGRESQL_EXTENSIONS`**
A space-separated list of extensions to create when the server start. Once created, the extensions will stay even if the variable is cleared.


You can also set the following mount points by passing the `-v /host/dir:/container/dir:Z` flag to Docker.

**`/var/lib/pgsql/data`**
Expand Down
17 changes: 17 additions & 0 deletions 15/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function should_hack_data_sync_retry() {
return 1
}

function generate_postgresql_libraries_config() {
if [ -v POSTGRESQL_LIBRARIES ]; then
echo "shared_preload_libraries='${POSTGRESQL_LIBRARIES}'" >> "${POSTGRESQL_CONFIG_FILE}"
fi
}


# New config is generated every time a container is created. It only contains
# additional custom settings and is included from $PGDATA/postgresql.conf.
function generate_postgresql_config() {
Expand Down Expand Up @@ -171,6 +178,7 @@ function generate_postgresql_config() {
echo "log_filename = '$(basename "${POSTGRESQL_LOG_DESTINATION}")'" >>"${POSTGRESQL_CONFIG_FILE}"
fi

generate_postgresql_libraries_config
(
shopt -s nullglob
for conf in "${APP_DATA}"/src/postgresql-cfg/*.conf; do
Expand Down Expand Up @@ -516,3 +524,12 @@ process_extending_files()
done
done <<<"$(get_matched_files '*.sh' "$@" | sort -u)"
}

create_extensions()
{
if [ -v POSTGRESQL_EXTENSIONS ]; then
for EXT in $POSTGRESQL_EXTENSIONS; do
psql -c "CREATE EXTENSION IF NOT EXISTS ${EXT};"
done
fi
}
1 change: 1 addition & 0 deletions 16/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if $PG_INITIALIZED ; then
create_users
fi

create_extensions
process_extending_files \
"${APP_DATA}/src/postgresql-start" \
"${CONTAINER_SCRIPTS_PATH}/start"
Expand Down
9 changes: 9 additions & 0 deletions 16/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Set to an estimate of how much memory is available for disk caching by the opera
**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

**`POSTGRESQL_LIBRARIES`**
A comma-separated list of libraries that Postgres will preload using shared_preload_libraries.

**`POSTGRESQL_EXTENSIONS`**
A space-separated list of extensions to create when the server start. Once created, the extensions will stay even if the variable is cleared.


You can also set the following mount points by passing the `-v /host/dir:/container/dir:Z` flag to Docker.

**`/var/lib/pgsql/data`**
Expand Down
17 changes: 17 additions & 0 deletions 16/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function should_hack_data_sync_retry() {
return 1
}

function generate_postgresql_libraries_config() {
if [ -v POSTGRESQL_LIBRARIES ]; then
echo "shared_preload_libraries='${POSTGRESQL_LIBRARIES}'" >> "${POSTGRESQL_CONFIG_FILE}"
fi
}


# New config is generated every time a container is created. It only contains
# additional custom settings and is included from $PGDATA/postgresql.conf.
function generate_postgresql_config() {
Expand Down Expand Up @@ -171,6 +178,7 @@ function generate_postgresql_config() {
echo "log_filename = '$(basename "${POSTGRESQL_LOG_DESTINATION}")'" >>"${POSTGRESQL_CONFIG_FILE}"
fi

generate_postgresql_libraries_config
(
shopt -s nullglob
for conf in "${APP_DATA}"/src/postgresql-cfg/*.conf; do
Expand Down Expand Up @@ -516,3 +524,12 @@ process_extending_files()
done
done <<<"$(get_matched_files '*.sh' "$@" | sort -u)"
}

create_extensions()
{
if [ -v POSTGRESQL_EXTENSIONS ]; then
for EXT in $POSTGRESQL_EXTENSIONS; do
psql -c "CREATE EXTENSION IF NOT EXISTS ${EXT};"
done
fi
}
1 change: 1 addition & 0 deletions src/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if $PG_INITIALIZED ; then
create_users
fi

create_extensions
process_extending_files \
"${APP_DATA}/src/postgresql-start" \
"${CONTAINER_SCRIPTS_PATH}/start"
Expand Down
9 changes: 9 additions & 0 deletions src/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Set to an estimate of how much memory is available for disk caching by the opera
**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

**`POSTGRESQL_LIBRARIES`**
A comma-separated list of libraries that Postgres will preload using shared_preload_libraries.

**`POSTGRESQL_EXTENSIONS`**
A space-separated list of extensions to create when the server start. Once created, the extensions will stay even if the variable is cleared.


You can also set the following mount points by passing the `-v /host/dir:/container/dir:Z` flag to Docker.

**`/var/lib/pgsql/data`**
Expand Down
Loading