PostgreSQL with batteries included ⚡
- pgBackRest — Backup & Restore
- plpython — Run anything from within postgres
- pg_cron — Schedule sql jobs
- locales-all — All locales precompiled
- Fix bash quotation (#3)
- Run as user
postgres
(#2)
- Make sure we don't start up with an incompletely initialized database (#1)
Initial release
- Configuration:
/etc/postgresql/postgresql.conf
- Data:
/var/lib/postgresql/data
- Logs:
/var/log/postgresql
(must be enabled first)
- Configuration:
/etc/pgbackrest/pgbackrest.conf
- Data:
/var/lib/pgbackrest
- Logs:
/var/log/pgbackrest
The pgBackRest stanza default
will be created on database initialization.
[default]
pg1-path=/var/lib/postgresql/data
[global]
repo1-path=/var/lib/pgbackrest
listen_addresses = '*'
archive_mode = on
archive_command = 'pgbackrest archive-push --stanza=default %p'
shared_preload_libraries = 'pg_cron'
CREATE SCHEMA IF NOT EXISTS pgbackrest;
CREATE OR REPLACE FUNCTION pgbackrest.backup() RETURNS void AS $$
import subprocess
subprocess.run(["pgbackrest", "backup", "--stanza=default"], check=True)
$$ LANGUAGE plpython3u;
SELECT cron.schedule('0 0 * * *', 'SELECT pgbackrest.backup()');
Example using Docker Compose.
docker compose stop SERVICE_NAME
docker compose run SERVICE_NAME find /var/lib/postgresql/data -mindepth 1 -delete
docker compose run SERVICE_NAME pgbackrest restore --stanza=default
docker compose start SERVICE_NAME
Refer to the pgBackRest User Guide.