Upgrade of the PostgreSQL Dogu
When developing the PostgreSQL Dogu further, it must be ensured that existing instances can be upgraded to newer versions.
The upgrade path consists of pre-upgrade.sh before the image switch and post-upgrade.sh after the image switch.
General process
During a Dogu upgrade, pre-upgrade.sh is executed first in the old container.
After that, the new image is started and post-upgrade.sh is executed.
At the same time, startup.sh starts the official PostgreSQL entrypoint.
Pre-upgrade (resources/pre-upgrade.sh)
pre-upgrade.sh decides whether a full backup is required.
A backup is created, among other things, for major upgrades or layout migrations.
Important points:
- A full backup using
pg_dumpallis stored under/var/lib/postgresql/backup. - The backup path is stored in config under
migration_backup_path. local_state=upgradingis set so thatstartup.shcan wait for a running upgrade.
Post-upgrade (resources/post-upgrade.sh)
post-upgrade.sh distinguishes between restore cases and regular migrations.
Restore case:
- If
migration_backup_pathis set, the target directory is prepared for restore. - Then
post-upgrade.shexits. - The actual restore runs on the next regular startup via
01-restore.sh.
Regular migration case:
- If no restore is needed and a DB is already initialized,
post-upgrade.shstarts PostgreSQL temporarily. - Then migration scripts from
/docker-entrypoint-initdb.d(fromresources/migrations) are executed manually. - PostgreSQL is stopped again and
local_stateis removed.
Startup (resources/startup.sh)
startup.sh waits as long as local_state=upgrading is set.
After that, it starts /usr/local/bin/docker-entrypoint.sh with Dogu-specific parameters.
Important:
The official entrypoint executes scripts in /docker-entrypoint-initdb.d automatically only for a fresh initialization.
Therefore, for existing data, scripts are called manually in post-upgrade.sh.
Where should new migration scripts be added?
New migration scripts go into resources/migrations/ and are copied in the Dockerfile to /docker-entrypoint-initdb.d/.
Current scripts:
resources/migrations/01-restore.shresources/migrations/02-restrictStatVisibility.shresources/migrations/03-migrateConstraintsOnPartitionedTables.sh
Order and conventions
- Name scripts as
NN-description.sh(01-...,02-..., ...). - Keep scripts idempotent (running them multiple times must not cause problems).
- Set completion markers in Dogu config (for example
restricted_stat_visibility=true) so steps only run once. - Always use
set -o errexit -o nounset -o pipefail.