kopia lustrzana https://github.com/kartoza/docker-postgis
Random optimisations
rodzic
e7e1d9949a
commit
f3264d4db8
|
@ -17,7 +17,7 @@ RUN set -eux \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get -y --no-install-recommends install \
|
&& apt-get -y --no-install-recommends install \
|
||||||
locales gnupg2 wget ca-certificates rpl pwgen software-properties-common iputils-ping \
|
locales gnupg2 wget ca-certificates rpl pwgen software-properties-common iputils-ping \
|
||||||
apt-transport-https curl \
|
apt-transport-https curl gettex \
|
||||||
&& dpkg-divert --local --rename --add /sbin/initctl
|
&& dpkg-divert --local --rename --add /sbin/initctl
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,11 +25,6 @@ RUN set -eux \
|
||||||
RUN apt-get -y update; apt-get -y install build-essential autoconf libxml2-dev zlib1g-dev netcat gdal-bin
|
RUN apt-get -y update; apt-get -y install build-essential autoconf libxml2-dev zlib1g-dev netcat gdal-bin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Temporary - PostgreSQL requires this which is not available in bullseye
|
|
||||||
ADD base_build/gdal_install.sh /gdal_install.sh
|
|
||||||
RUN chmod 0755 /gdal_install.sh;/bin/bash /gdal_install.sh
|
|
||||||
|
|
||||||
# Generating locales takes a long time. Utilize caching by runnig it by itself
|
# Generating locales takes a long time. Utilize caching by runnig it by itself
|
||||||
# early in the build process.
|
# early in the build process.
|
||||||
|
|
||||||
|
|
18
README.md
18
README.md
|
@ -211,6 +211,14 @@ the extension is installed with the image.
|
||||||
|
|
||||||
` Specifies whether extensions will also be installed in template1 database.`
|
` Specifies whether extensions will also be installed in template1 database.`
|
||||||
|
|
||||||
|
### Schema Initialisation
|
||||||
|
* `-e SCHEMA_NAME=<PGSCHEMA>`
|
||||||
|
You can pass a comma separated value of schema names which will be created when the
|
||||||
|
database initialises. The default behaviour is to create the schema in the first
|
||||||
|
database specified in the environment variable `POSTGRES_DBNAME`. If you need to
|
||||||
|
create matching schemas in all the databases that will be created you use
|
||||||
|
the environment variable `ALL_DATABASES=TRUE`
|
||||||
|
|
||||||
#### Configures archive mode
|
#### Configures archive mode
|
||||||
|
|
||||||
This image uses the initial PostgreSQL values which disables the archiving option by default.
|
This image uses the initial PostgreSQL values which disables the archiving option by default.
|
||||||
|
@ -247,10 +255,16 @@ all connections.
|
||||||
|
|
||||||
#### Additional configuration
|
#### Additional configuration
|
||||||
|
|
||||||
You can also define any other configuration to add to `postgres.conf`, separated by '\n' e.g.:
|
You can also define any other configuration to add to `extra.conf`, separated by '\n' e.g.:
|
||||||
|
|
||||||
* `-e EXTRA_CONF="log_destination = 'stderr'\nlogging_collector = on"`
|
* `-e EXTRA_CONF="log_destination = 'stderr'\nlogging_collector = on"`
|
||||||
|
|
||||||
|
You can alternatively mount an extra config file into the setting's folder i.e
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run --name "postgis" -v /data/extra.conf:/settings/extra.conf -p 25432:5432 -d -t kartoza/postgis
|
||||||
|
```
|
||||||
|
|
||||||
If you want to reinitialize the data directory from scratch, you need to do:
|
If you want to reinitialize the data directory from scratch, you need to do:
|
||||||
|
|
||||||
1. Do backup, move data, etc. Any preparations before deleting your data directory.
|
1. Do backup, move data, etc. Any preparations before deleting your data directory.
|
||||||
|
@ -557,4 +571,4 @@ Tim Sutton (tim@kartoza.com)
|
||||||
Gavin Fleming (gavin@kartoza.com)
|
Gavin Fleming (gavin@kartoza.com)
|
||||||
Rizky Maulana (rizky@kartoza.com)
|
Rizky Maulana (rizky@kartoza.com)
|
||||||
Admire Nyakudya (admire@kartoza.com)
|
Admire Nyakudya (admire@kartoza.com)
|
||||||
October 2020
|
March 2021
|
|
@ -1,7 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if [[ ${IMAGE_VERSION} =~ [Bb][Uu][Ll][Ll][Ss][Ee][Yy][Ee] ]]; then
|
|
||||||
wget --progress=bar:force:noscroll -c --no-check-certificate http://ftp.br.debian.org/debian/pool/main/g/gdal/libgdal27_3.1.4+dfsg-1+b1_amd64.deb
|
|
||||||
dpkg -i libgdal27_3.1.4+dfsg-1+b1_amd64.deb
|
|
||||||
fi
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Used solely for docker-compose build
|
# Used solely for docker-compose build
|
||||||
version: '3'
|
version: '3.9'
|
||||||
services:
|
services:
|
||||||
postgis-base:
|
postgis-base:
|
||||||
image: kartoza/postgis:base-${DISTRO}-${IMAGE_VERSION}-${IMAGE_VARIANT}
|
image: kartoza/postgis:base-${DISTRO}-${IMAGE_VERSION}-${IMAGE_VARIANT}
|
||||||
|
|
|
@ -7,7 +7,7 @@ volumes:
|
||||||
services:
|
services:
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: kartoza/postgis:13.1
|
image: kartoza/postgis:13-3.1
|
||||||
volumes:
|
volumes:
|
||||||
- postgis-data:/var/lib/postgresql
|
- postgis-data:/var/lib/postgresql
|
||||||
- dbbackups:/backups
|
- dbbackups:/backups
|
||||||
|
|
|
@ -258,6 +258,10 @@ if [ -z "$PASSWORD_AUTHENTICATION" ]; then
|
||||||
PASSWORD_AUTHENTICATION="scram-sha-256"
|
PASSWORD_AUTHENTICATION="scram-sha-256"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "${ALL_DATABASES}" ]; then
|
||||||
|
ALL_DATABASES=FALSE
|
||||||
|
fi
|
||||||
|
|
||||||
# Compatibility with official postgres variable
|
# Compatibility with official postgres variable
|
||||||
# Official postgres variable gets priority
|
# Official postgres variable gets priority
|
||||||
if [ -n "${POSTGRES_PASSWORD}" ]; then
|
if [ -n "${POSTGRES_PASSWORD}" ]; then
|
||||||
|
|
|
@ -15,10 +15,7 @@ cat $CONF.template > $CONF
|
||||||
sed -i '/data_directory/d' $CONF
|
sed -i '/data_directory/d' $CONF
|
||||||
|
|
||||||
# Create a config to optimise postgis
|
# Create a config to optimise postgis
|
||||||
if [[ -f ${ROOT_CONF}/postgis.conf ]];then
|
cat > ${ROOT_CONF}/postgis.conf <<EOF
|
||||||
rm $CONF/postgis.conf
|
|
||||||
fi
|
|
||||||
cat >> ${ROOT_CONF}/postgis.conf <<EOF
|
|
||||||
data_directory = '${DATADIR}'
|
data_directory = '${DATADIR}'
|
||||||
port = 5432
|
port = 5432
|
||||||
superuser_reserved_connections= 10
|
superuser_reserved_connections= 10
|
||||||
|
@ -42,10 +39,8 @@ echo "include 'postgis.conf'" >> $CONF
|
||||||
|
|
||||||
# Create a config for logical replication
|
# Create a config for logical replication
|
||||||
if [[ "${REPLICATION}" =~ [Tt][Rr][Uu][Ee] && "$WAL_LEVEL" == 'logical' ]]; then
|
if [[ "${REPLICATION}" =~ [Tt][Rr][Uu][Ee] && "$WAL_LEVEL" == 'logical' ]]; then
|
||||||
if [[ -f ${ROOT_CONF}/logical_replication.conf ]];then
|
|
||||||
rm $CONF/logical_replication.conf
|
cat > ${ROOT_CONF}/logical_replication.conf <<EOF
|
||||||
fi
|
|
||||||
cat >> ${ROOT_CONF}/logical_replication.conf <<EOF
|
|
||||||
wal_level = ${WAL_LEVEL}
|
wal_level = ${WAL_LEVEL}
|
||||||
max_wal_senders = ${PG_MAX_WAL_SENDERS}
|
max_wal_senders = ${PG_MAX_WAL_SENDERS}
|
||||||
wal_keep_size = ${PG_WAL_KEEP_SIZE}
|
wal_keep_size = ${PG_WAL_KEEP_SIZE}
|
||||||
|
@ -59,10 +54,8 @@ fi
|
||||||
|
|
||||||
# Create a config for streaming replication
|
# Create a config for streaming replication
|
||||||
if [[ "${REPLICATION}" =~ [Tt][Rr][Uu][Ee] && "$WAL_LEVEL" == 'replica' ]]; then
|
if [[ "${REPLICATION}" =~ [Tt][Rr][Uu][Ee] && "$WAL_LEVEL" == 'replica' ]]; then
|
||||||
if [[ -f ${ROOT_CONF}/streaming_replication.conf ]];then
|
|
||||||
rm $CONF/streaming_replication.conf
|
cat > ${ROOT_CONF}/streaming_replication.conf <<EOF
|
||||||
fi
|
|
||||||
cat >> ${ROOT_CONF}/streaming_replication.conf <<EOF
|
|
||||||
wal_level = ${WAL_LEVEL}
|
wal_level = ${WAL_LEVEL}
|
||||||
archive_mode = ${ARCHIVE_MODE}
|
archive_mode = ${ARCHIVE_MODE}
|
||||||
archive_command = '${ARCHIVE_COMMAND}'
|
archive_command = '${ARCHIVE_COMMAND}'
|
||||||
|
@ -82,14 +75,20 @@ EOF
|
||||||
echo "include 'streaming_replication.conf'" >> $CONF
|
echo "include 'streaming_replication.conf'" >> $CONF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f ${ROOT_CONF}/extra.conf ]];then
|
if [[ ! -f ${ROOT_CONF}/extra.conf ]]; then
|
||||||
rm $CONF/extra.conf
|
# If it doesn't exists, copy from /settings directory if exists
|
||||||
fi
|
if [[ -f /settings/extra.conf ]]; then
|
||||||
|
cp -f /settings/extra.conf ${ROOT_CONF}/extra.conf
|
||||||
|
echo "include 'extra.conf'" >> $CONF
|
||||||
|
else
|
||||||
|
# default value
|
||||||
if [[ ! -z $EXTRA_CONF ]]; then
|
if [[ ! -z $EXTRA_CONF ]]; then
|
||||||
echo -e $EXTRA_CONF >> ${ROOT_CONF}/extra.conf
|
echo -e $EXTRA_CONF >> ${ROOT_CONF}/extra.conf
|
||||||
echo "include 'extra.conf'" >> $CONF
|
echo "include 'extra.conf'" >> $CONF
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# Optimise PostgreSQL shared memory for PostGIS
|
# Optimise PostgreSQL shared memory for PostGIS
|
||||||
# shmall units are pages and shmmax units are bytes(?) equivalent to the desired shared_buffer size set in setup_conf.sh - in this case 500MB
|
# shmall units are pages and shmmax units are bytes(?) equivalent to the desired shared_buffer size set in setup_conf.sh - in this case 500MB
|
||||||
|
|
|
@ -53,8 +53,10 @@ fi
|
||||||
# It will be owned by the docker db user
|
# It will be owned by the docker db user
|
||||||
# Since we now pass a comma separated list in database creation we need to search for all databases as a test
|
# Since we now pass a comma separated list in database creation we need to search for all databases as a test
|
||||||
|
|
||||||
|
|
||||||
for db in $(echo ${POSTGRES_DBNAME} | tr ',' ' '); do
|
for db in $(echo ${POSTGRES_DBNAME} | tr ',' ' '); do
|
||||||
RESULT=`su - postgres -c "psql -t -c \"SELECT count(1) from pg_database where datname='${db}';\""`
|
RESULT=`su - postgres -c "psql -t -c \"SELECT count(1) from pg_database where datname='${db}';\""`
|
||||||
|
|
||||||
if [[ ${RESULT} -eq 0 ]]; then
|
if [[ ${RESULT} -eq 0 ]]; then
|
||||||
echo "Create db ${db}"
|
echo "Create db ${db}"
|
||||||
su - postgres -c "createdb -O ${POSTGRES_USER} ${db}"
|
su - postgres -c "createdb -O ${POSTGRES_USER} ${db}"
|
||||||
|
@ -79,6 +81,21 @@ for db in $(echo ${POSTGRES_DBNAME} | tr ',' ' '); do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Create schemas in the DB
|
||||||
|
for db in $(echo ${POSTGRES_DBNAME} | tr ',' ' '); do
|
||||||
|
for schemas in $(echo ${SCHEMA_NAME} | tr ',' ' '); do
|
||||||
|
SCHEMA_RESULT=`PGPASSWORD=${POSTGRES_PASS} psql -t ${db} -U ${POSTGRES_USER} -p 5432 -h localhost -c "select count(1) from information_schema.schemata where schema_name = '${schemas}' and catalog_name = '${db}';"`
|
||||||
|
if [[ ${SCHEMA_RESULT} -eq 0 ]] && [[ "${ALL_DATABASES}" =~ [Ff][Aa][Ll][Ss][Ee] ]]; then
|
||||||
|
echo "Creating schema ${schemas} in database ${SINGLE_DB}"
|
||||||
|
PGPASSWORD=${POSTGRES_PASS} psql ${SINGLE_DB} -U ${POSTGRES_USER} -p 5432 -h localhost -c " CREATE SCHEMA IF NOT EXISTS ${schemas};"
|
||||||
|
elif [[ ${SCHEMA_RESULT} -eq 0 ]] && [[ "${ALL_DATABASES}" =~ [Tt][Rr][Uu][Ee] ]]; then
|
||||||
|
echo "Creating schema ${schemas} in database ${db}"
|
||||||
|
PGPASSWORD=${POSTGRES_PASS} psql ${db} -U ${POSTGRES_USER} -p 5432 -h localhost -c " CREATE SCHEMA IF NOT EXISTS ${schemas};"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
CRON_LOCKFILE="${ROOT_CONF}/.cron_ext.lock"
|
CRON_LOCKFILE="${ROOT_CONF}/.cron_ext.lock"
|
||||||
if [ ! -f "${CRON_LOCKFILE}" ]; then
|
if [ ! -f "${CRON_LOCKFILE}" ]; then
|
||||||
su - postgres -c "psql -c 'CREATE EXTENSION IF NOT EXISTS pg_cron cascade;' ${SINGLE_DB}"
|
su - postgres -c "psql -c 'CREATE EXTENSION IF NOT EXISTS pg_cron cascade;' ${SINGLE_DB}"
|
||||||
|
|
|
@ -12,6 +12,11 @@ fi
|
||||||
# Reconfigure pg_hba if environment settings changed
|
# Reconfigure pg_hba if environment settings changed
|
||||||
cat ${ROOT_CONF}/pg_hba.conf.template > ${ROOT_CONF}/pg_hba.conf
|
cat ${ROOT_CONF}/pg_hba.conf.template > ${ROOT_CONF}/pg_hba.conf
|
||||||
|
|
||||||
|
# Restrict subnet to docker private network
|
||||||
|
echo "host all all 172.0.0.0/8 ${PASSWORD_AUTHENTICATION}" >> $ROOT_CONF/pg_hba.conf
|
||||||
|
# And allow access from DockerToolbox / Boot to docker on OSX
|
||||||
|
echo "host all all 192.168.0.0/16 ${PASSWORD_AUTHENTICATION}" >> $ROOT_CONF/pg_hba.conf
|
||||||
|
|
||||||
# Custom IP range via docker run -e (https://docs.docker.com/engine/reference/run/#env-environment-variables)
|
# Custom IP range via docker run -e (https://docs.docker.com/engine/reference/run/#env-environment-variables)
|
||||||
# Usage is: docker run [...] -e ALLOW_IP_RANGE='192.168.0.0/16'
|
# Usage is: docker run [...] -e ALLOW_IP_RANGE='192.168.0.0/16'
|
||||||
if [[ "$ALLOW_IP_RANGE" ]]
|
if [[ "$ALLOW_IP_RANGE" ]]
|
||||||
|
|
|
@ -5,12 +5,6 @@ chmod 600 /etc/ssl/private/ssl-cert-snakeoil.key
|
||||||
# These tasks are run as root
|
# These tasks are run as root
|
||||||
source /scripts/env-data.sh
|
source /scripts/env-data.sh
|
||||||
|
|
||||||
|
|
||||||
# Restrict subnet to docker private network
|
|
||||||
echo "host all all 172.0.0.0/8 ${PASSWORD_AUTHENTICATION}" >> $ROOT_CONF/pg_hba.conf
|
|
||||||
# And allow access from DockerToolbox / Boot to docker on OSX
|
|
||||||
echo "host all all 192.168.0.0/16 ${PASSWORD_AUTHENTICATION}" >> $ROOT_CONF/pg_hba.conf
|
|
||||||
|
|
||||||
# Create backup template for conf
|
# Create backup template for conf
|
||||||
cat $CONF > $CONF.template
|
cat $CONF > $CONF.template
|
||||||
cat $ROOT_CONF/pg_hba.conf > $ROOT_CONF/pg_hba.conf.template
|
cat $ROOT_CONF/pg_hba.conf > $ROOT_CONF/pg_hba.conf.template
|
||||||
|
|
Ładowanie…
Reference in New Issue