Charmed PostgreSQL How-to - Legacy DB Migrate

:warning: NOTE: The document has been simplified and replaced with Charmhub | Deploy Charmed PostgreSQL using Charmhub - The Open Operator Collection and Charmhub | Deploy Charmed PostgreSQL using Charmhub - The Open Operator Collection


How to migrate from legacy PostgreSQL charm

The document describes data migration from legacy PostgreSQL charm (channel latest/stable) to the modern “Charmed PostgreSQL” (channel 14/stable). All other parts of migration (code, libraries, bundles) are NOT a part of this document, please read success story for the entire charm/bundle migration here.

:warning: IMPORTANT: check your charm/application compatibility with PostgreSQL 14!
The modern charm supports PostgreSQL 14 only!

:information_source: Hint: deploy your application with the modern “Charmed PostgreSQL” and relate using a legacy interface pgsql (endpoint db or db-admin). Ensure your application works fine, then consider the data migration!

Scope

The migration scenario, complexity and duration depends on several important answers:

  • is application service downtime allowed?
  • is database size huge?
  • is network connection good enough?
  • is extra compute resources available?

Please collect all the answers before the migration and use one of the following scenarios which fits you best:

  1. (pg_dumpall) Use migration as a chance to archive/clean old databases in your PostgreSQL. Create backup for all databases but migrate the necessary databases only: how-to.

  2. (pg_upgrade) The charm in-place upgrade is impossible!!!

    All above makes simultaneous in-place DB upgrade with charm type/series change technically risky and expensive comparing to other methods described in this document.

  3. (pg_dump)* Create logical dump and restore it. Migrate necessary DBs only: how-to.

    * Hint: Recommended way to migrate on new charm!

  4. (pgbackrest) Create a physical dump in legacy charm and restore in modern one: install pgbackrest, backup to S3, restore from S3 into the new charm: how-to.

Tested charm revisions

  • Legacy PostgreSQL 12, channel: latest/stable, revision 290 on 20.04/amd64.

  • Modern PostgreSQL 14.7, channel: 14/stable, revision 288 on 22.04/amd64.

Known corner cases

  • The legacy charm could deploy PostgreSQL 9.5, 9.6, 10, 11, 12, 14. The modern Charmed PostgreSQL supports PostgreSQL 14 only. The current manual tested on migration from legacy PostgreSQL 12 to the modern Charmed PostgreSQL 14. The migration of previous PostgreSQL versions could be similar but requires extra testing. Please contact us if you need to migrate old versions/series.

  • (TLS) The legacy PostgreSQL had TLS support built-in! Some charms (e.g. mattermost-k8s) works via TLS only (see LP#1997540)! Make sure the modern Charmed PostgreSQL charm related with TLS-certificates operator.

I’ve written a guide for how to achieve this with Nextcloud: [Nextcloud/postgresql] How to migrate Nextcloud to new posgresql (ops) - charm - Charmhub