POSTGIS and TimescaleDB (inc. toolkit for hyperfunctions) image built for amd64 and arm64 using timescale/timescaledb-ha base image with:
- OR specific ENV variables and a healthcheck added
- Easy configuration of
max_connectionsusingPOSTGRES_MAX_CONNECTIONSenvironment variable (set to-1to disable this setting) - Sessions left idle in a transaction for more than 10 minutes are terminated, as they prevent autovacuum removing dead rows
and cause table bloat; configure using
POSTGRES_IDLE_IN_TRANSACTION_SESSION_TIMEOUTenvironment variable with a PostgreSQL time value e.g.30min(set to0to disable this setting) - Memory settings with defaults sized for a 4 GB host giving PostgreSQL a ~768 MB container memory limit (see below)
- Diagnostics logging of slow statements (with their plans), lock waits and temp file spills (see below)
- Less frequent checkpoints and compressed WAL full page images to reduce WAL volume and disk writes (see below)
- PGDATA path set to match old Alpine image (for ease of DB migration)
- POSTGRES user UID and GID changed to match old Alpine image (for ease of DB migration)
- Auto upgrade of database with PG major version changes from previous PG major version; can be disabled using
OR_DISABLE_AUTO_UPGRADE=true - Auto upgrade of timescaleDB extension when a new version is available in the container; can be disabled using
OR_DISABLE_AUTO_UPGRADE=true - Slimmed images using slim toolkit to reduce image size by ~60%
These environment variables are passed to PostgreSQL as -c arguments. They come before any arguments in the container
command, so a -c given there takes precedence. Set a variable to an empty value or -1 to leave the setting to
postgresql.conf / ALTER SYSTEM instead.
The memory defaults suit a 4 GB host where PostgreSQL has a ~768 MB container memory limit. For other limits, scale them:
shared_buffers ~25% of the limit, effective_cache_size ~75% and maintenance_work_mem ~1/12.
| Environment variable | PostgreSQL setting | Default |
|---|---|---|
POSTGRES_MAX_CONNECTIONS |
max_connections |
50 |
POSTGRES_IDLE_IN_TRANSACTION_SESSION_TIMEOUT |
idle_in_transaction_session_timeout |
10min |
POSTGRES_SHARED_BUFFERS |
shared_buffers |
192MB |
POSTGRES_EFFECTIVE_CACHE_SIZE |
effective_cache_size |
576MB |
POSTGRES_MAINTENANCE_WORK_MEM |
maintenance_work_mem |
64MB |
POSTGRES_WORK_MEM |
work_mem |
4MB |
POSTGRES_WAL_COMPRESSION |
wal_compression (lz4, zstd, pglz or off) |
lz4 |
POSTGRES_CHECKPOINT_TIMEOUT |
checkpoint_timeout |
15min |
POSTGRES_MAX_WAL_SIZE |
max_wal_size |
1GB |
POSTGRES_TIMESCALEDB_TELEMETRY_LEVEL |
timescaledb.telemetry_level (off or basic) |
off |
POSTGRES_LOG_LINE_PREFIX |
log_line_prefix (backend PID and client host; Docker adds the timestamp) |
[%p] [%h] |
POSTGRES_LOG_MIN_DURATION_STATEMENT |
log_min_duration_statement, and auto_explain.log_min_duration with auto_explain loaded through session_preload_libraries |
5s |
POSTGRES_LOG_LOCK_WAITS |
log_lock_waits |
on |
POSTGRES_LOG_TEMP_FILES |
log_temp_files |
10MB |
POSTGRES_LOG_CHECKPOINTS |
log_checkpoints |
off |
The first change to a page after each checkpoint writes the whole 8 kB page to WAL (a full page image), which can be
half or more of all WAL written. The WAL defaults reduce this by checkpointing every 15 minutes instead of PostgreSQL's
default 5 and compressing the page images; the cost is up to 15 minutes of WAL to replay after a crash. If
pg_stat_checkpointer.num_requested grows, checkpoints are being forced by WAL volume, so raise max_wal_size.
shared_buffers does not live in /dev/shm, so the container's shm_size does not need to grow with it; /dev/shm is
only used for dynamic shared memory such as parallel query.
- Docker must be installed and running
- slim toolkit must be installed for image optimization
Install slim toolkit via the install script:
curl -sL https://raw.githubusercontent.com/slimtoolkit/slim/master/scripts/install-slim.sh | sudo -E bash -Or via Homebrew (macOS):
brew install docker-slimFor more installation options, see the slim toolkit documentation.
- Build the Docker image (replace
17with desired PostgreSQL major version):
docker build --build-arg PG_MAJOR=17 -t openremote/postgresql:pg17 .- Slim the image using the provided script:
# Usage: ./slim-image.sh <source-image> <target-image> <architecture>
# Architecture: amd64 or arm64 (auto-detected if omitted)
./slim-image.sh openremote/postgresql:pg17 openremote/postgresql:pg17-slim- Optionally replace the original with the slimmed version:
docker tag openremote/postgresql:pg17-slim openremote/postgresql:pg17NOTE: If you change the version of container you use then make sure you have backed up your DB first as this container will try to auto upgrade your DB and/or TimescaleDB extension; this auto upgrade functionality can be disabled using OR_DISABLE_AUTO_UPGRADE=true
This image supports automatic upgrades from the previous PostgreSQL major version. When the container starts with an existing database from a supported older version, it will:
- Upgrade TimescaleDB extensions on the old PostgreSQL version
- Run
pg_upgradeto migrate the database to the new PostgreSQL version - Upgrade TimescaleDB extensions on the new PostgreSQL version
If automatic upgrade is not supported for your database version (e.g., skipping multiple major versions), you will need to perform a manual upgrade. Follow these steps:
- Backup your database using
pg_dumporpg_dumpall - Upgrade TimescaleDB first (if installed) - this must be done before PostgreSQL upgrade
- Use pg_upgrade to migrate between PostgreSQL versions, or restore from backup to a fresh database
# On the old container, dump the database
docker exec -it <old_container> pg_dumpall -U postgres > backup.sql
# Start the new container with a fresh data directory
docker run -d --name new_postgres -v /path/to/new/data:/var/lib/postgresql/data openremote/postgresql:latest
# Restore the backup
docker exec -i new_postgres psql -U postgres < backup.sql