2024-04-04 14:07:18 +02:00
|
|
|
# pg maintenance
|
|
|
|
|
|
|
|
Minimalist periodic maintenance script for PostgreSQL.
|
|
|
|
|
|
|
|
|
|
|
|
## Disclaimer and licensing
|
|
|
|
|
|
|
|
This software has been created for personal purposes and may therefore not suit your needs.
|
|
|
|
However, you may use it under the terms of the [MIT License][mit_license].
|
|
|
|
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
|
|
|
- Python 3
|
|
|
|
- psql / pg_dump
|
|
|
|
- rsync
|
|
|
|
|
|
|
|
|
|
|
|
## Actions
|
|
|
|
|
2024-04-04 14:30:38 +02:00
|
|
|
This script:
|
|
|
|
- runs [VACUUM][doc_vacuum] and [ANALYZE][doc_analyze] on a specified database;
|
|
|
|
- creates compressed backup file and sends it to the destination (requires a destination);
|
|
|
|
- builds a reports and email it to recipients (requires at least one recipient).
|
2024-04-04 14:07:18 +02:00
|
|
|
|
|
|
|
To know more about routine vacuuming, please read [PostgreSQL's documentation][doc_why_vacuum].
|
|
|
|
|
|
|
|
|
|
|
|
## Basic usage
|
|
|
|
|
|
|
|
```
|
|
|
|
pg_maintenance.py --help
|
|
|
|
pg_maintenance.py "db_name" --destination "user@remote:/your/backup/path" --email-recipient "admin@exemple.org"
|
|
|
|
```
|
|
|
|
|
2024-04-04 14:30:38 +02:00
|
|
|
Restore a backup:
|
|
|
|
|
|
|
|
```
|
|
|
|
zstdcat "2024-04-04_db_name.sql.zst" | psql --set ON_ERROR_STOP=on
|
|
|
|
```
|
|
|
|
|
2024-04-04 14:07:18 +02:00
|
|
|
|
|
|
|
[mit_license]: https://opensource.org/license/mit
|
|
|
|
[doc_why_vacuum]: https://www.postgresql.org/docs/current/routine-vacuuming.html
|
|
|
|
[doc_vacuum]: https://www.postgresql.org/docs/current/sql-vacuum.html
|
|
|
|
[doc_analyze]: https://www.postgresql.org/docs/current/sql-analyze.html
|