Postgres [upgrading](docs/maintenance-postgres.md#upgrading-postgresql) and [importing](docs/importing-postgres.md) have been improved to add support for multiple databases and roles.
Previously, the playbook would only take care of the `homeserver` database and `synapse` user.
We now back up and restore all databases and users on the Postgres server.
For now, the playbook only uses that one database (`homeserver`) and that one single user (`synapse`), so it's all the same.
However, in the future, additional components besides Synapse may also make use the Postgres database server.
One such example is the [matrix-appservice-slack](https://github.com/matrix-org/matrix-appservice-slack) bridge, which strongly encourages use of Postgres in its v1.0 release. We are yet to upgrade to it.
@ -40,16 +40,18 @@ To make a back up of the current PostgreSQL database, make sure it's running and
```bash
```bash
docker run \
docker run \
--rm \
--rm \
--networkmatrix \
--network=matrix \
--env-file=/matrix/postgres/env-postgres-psql \
--env-file=/matrix/postgres/env-postgres-psql \
postgres:12.0-alpine \
postgres:12.0-alpine \
pg_dump -h matrix-postgres \
pg_dumpall -h matrix-postgres \
| gzip -c \
| gzip -c \
> /postgres.sql.gz
> /postgres.sql.gz
```
```
If you are using an [external Postgres server](configuring-playbook-external-postgres.md), the above command will not work, because the credentials file (`/matrix/postgres/env-postgres-psql`) is not available.
If you are using an [external Postgres server](configuring-playbook-external-postgres.md), the above command will not work, because the credentials file (`/matrix/postgres/env-postgres-psql`) is not available.
Restoring a backup made this way can be done by [importing it](importing-postgres.md).
## Upgrading PostgreSQL
## Upgrading PostgreSQL
@ -64,7 +66,7 @@ This playbook can upgrade your existing Postgres setup with the following comman
**The old Postgres data directory is backed up** automatically, by renaming to `/matrix/postgres-auto-upgrade-backup`.
**The old Postgres data directory is backed up** automatically, by renaming it to `/matrix/postgres-auto-upgrade-backup`.
To rename to a different path, pass some extra flags to the command above, like this: `--extra-vars="postgres_auto_upgrade_backup_data_path=/another/disk/matrix-postgres-before-upgrade"`
To rename to a different path, pass some extra flags to the command above, like this: `--extra-vars="postgres_auto_upgrade_backup_data_path=/another/disk/matrix-postgres-before-upgrade"`
The auto-upgrade-backup directory stays around forever, until you **manually decide to delete it**.
The auto-upgrade-backup directory stays around forever, until you **manually decide to delete it**.
@ -72,5 +74,4 @@ The auto-upgrade-backup directory stays around forever, until you **manually dec
As part of the upgrade, the database is dumped to `/tmp`, an upgraded and empty Postgres server is started, and then the dump is restored into the new server.
As part of the upgrade, the database is dumped to `/tmp`, an upgraded and empty Postgres server is started, and then the dump is restored into the new server.
To use a different directory for the dump, pass some extra flags to the command above, like this: `--extra-vars="postgres_dump_dir=/directory/to/dump/here"`
To use a different directory for the dump, pass some extra flags to the command above, like this: `--extra-vars="postgres_dump_dir=/directory/to/dump/here"`
**ONLY one database is migrated** (the one specified in `matrix_postgres_db_name`, named `homeserver` by default).
**All databases, roles, etc. on the Postgres server are migrated**.
If you've created other databases in that database instance (something this playbook never does and never advises), data will be lost.