Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/explanation/interfaces-and-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Adding a relation is accomplished with `juju relate` (or `juju integrate` for Ju

```text
# Deploy Charmed PostgreSQL cluster with 3 nodes
juju deploy postgresql-k8s --channel 16/stable -n 3 --trust
juju deploy postgresql-k8s --channel 16/edge -n 3 --trust

# Deploy the relevant application charms
juju deploy mycharm
Expand Down Expand Up @@ -47,7 +47,7 @@ Check the limitations of legacy interface implementations in [](/explanation/leg
This charm supports legacy interface `pgsql` from the previous [PostgreSQL charm](https://launchpad.net/postgresql-charm):

```text
juju deploy postgresql-k8s --channel 16/stable --trust
juju deploy postgresql-k8s --channel 16/edge --trust
juju deploy finos-waltz-k8s --channel edge
juju relate postgresql-k8s:db finos-waltz-k8s
```
Expand Down
2 changes: 1 addition & 1 deletion docs/explanation/legacy-charm.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Please find the list of supported PostgreSQL [Extensions](/reference/plugins-ext

## Roles supported by modern charm

In the legacy charm, the user could request roles by setting the `roles` field to a comma separated list of desired roles. It is NOT supported by the modern charm implementation of the legacy `pgsql` interface. The same functionality is provided via the modern `postgresql_client` using "[extra-user-roles](/explanation/users)". Please check how to [migrate on the new interface](/how-to/development/integrate-with-your-charm).
In the legacy charm, the user could request roles by setting the `roles` field to a comma separated list of desired roles. It is NOT supported by the modern charm implementation of the legacy `pgsql` interface. The same functionality is provided via the modern `postgresql_client` using "[extra-user-roles](/explanation/users)". Please check how to [migrate on the new interface](/how-to/integrate-with-your-charm).

## Supported PostgreSQL versions by modern charm

Expand Down
18 changes: 18 additions & 0 deletions docs/how-to/data-migration/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Migrate data

For guidance about moving data from a Charmed PostgreSQL 14 database to Charmed PostgreSQL 16, start here:

```{toctree}
:titlesonly:

Migrate data from PostgreSQL 14 to 16 <migrate-data-from-14-to-16>
```

More generic data migration guides:

```{toctree}
:titlesonly:

Migrate data via `pg_dump` <migrate-data-via-pg-dump>
Migrate data via backup/restore <migrate-data-via-backup-restore>
```
110 changes: 110 additions & 0 deletions docs/how-to/data-migration/migrate-data-from-14-to-16.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Migrate data from PostgreSQL 14 to 16

There are two possible ways to migrate data from PostgreSQL 14 to 16 depending on how roles are managed:

**In case of admin roles management**, all database objects ownership are handled manually by the user. In this case, see the more general guide {ref}`migrate-data-via-pg-dump`. Note that you must set `extra-user-roles` to `charmed-admin` once a Juju relation is requested the new database.

**In the case of charm roles management**, all the database objects ownership will be handled by charm automatically. This guide covers how to migrate data from Charmed PostgreSQL 14 to 16 using the new charm roles management setup for client applications managed by Juju. The migrated data from PostgreSQL 14 will be mapped to the corresponding ownership in PostgreSQL 16.

## Prepare PostgreSQL 14 data

First, in order to make sure the latest data is included, remove the relation between the client app and Charmed PostgreSQL 14.

Then, define the following variables for the old database:

```shell
TMP_PATH="~/old-db-dump/"
OLD_DB_NAME="postgresql_test_app_database"
OLD_IP="10.218.34.229"
OLD_USER="operator"
OLD_PASSWORD="fJQYljbthEo2T1gj"
```

Create a dump of the old PostgreSQL 14 database with `pg_dump`:

```shell
mkdir -p "${TMP_PATH}"
PGPASSWORD="${OLD_PASSWORD}" pg_dump -j 4 -Fd -h "${OLD_IP}" -U "${OLD_USER}" -d "${OLD_DB_NAME}" -f "${TMP_PATH}" --compress 9
```

## Set up new PostgreSQL 16 charm

Deploy one unit of Charmed PostgreSQL 16. This will simplify the migration and can be scaled later.

```shell
juju deploy postgresql-k8s --channel 16/edge --trust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be 16/stable here

```

Define the following variables for the new database:

```shell
NEW_DB_NAME="postgresql_test_app_database123"
NEW_IP="10.218.34.56"
NEW_USER="operator"
NEW_PASSWORD="RnnijCiotVeW8O5I"
NEW_OWNER="charmed_${NEW_DB_NAME}_owner"
```

Migrate the following charm features from the old 14 charm to the new 16 charm:
* any necessary charm config options
* enabled charm extensions/plugins

```{note}
Config options and extensions *must* be migrated before restoring the data dump
```

## Create a new database on PostgreSQL 16

```shell
PGPASSWORD="${NEW_PASSWORD}" psql -h "${NEW_IP}" -U "${NEW_USER}" -d postgres -c "CREATE DATABASE ${NEW_DB_NAME}"
```

Create new roles by running the function `set_up_predefined_catalog_roles()` in all databases except `postgres` and `template1`. It will create roles like `charmed_<database-name>_owner`, `..._dml` and others:

```shell
PGPASSWORD="${NEW_PASSWORD}" psql -h "${NEW_IP}" -U "${NEW_USER}" -d "${NEW_DB_NAME}" -c "SELECT set_up_predefined_catalog_roles();"
PGPASSWORD="${NEW_PASSWORD}" psql -h "${NEW_IP}" -U "${NEW_USER}" -d "${NEW_DB_NAME}" -c "ALTER DATABASE ${NEW_DB_NAME} OWNER TO charmed_databases_owner;"
PGPASSWORD="${NEW_PASSWORD}" psql -h "${NEW_IP}" -U "${NEW_USER}" -d "${NEW_DB_NAME}" -c "ALTER SCHEMA public OWNER TO ${NEW_OWNER};"
```

## Migrate data from PostgreSQL 14 to 16

Restore the PostgreSQL 14 database dump into the new 16 database:

```shell
PGPASSWORD="${NEW_PASSWORD}" pg_restore -j 4 -h "${NEW_IP}" -U "${NEW_USER}" -d "${NEW_DB_NAME}" -Fd "${TMP_PATH}" --no-owner
```

### Set up new database ownership

Verify and modify the ownership for each database object in each schema to be equal to `charmed_<database-name>_owner` (`${NEW_OWNER}` above).

For example, to find and fix ownership for all tables, sequences, and views:

```shell
PGPASSWORD="${NEW_PASSWORD}" psql -h "${NEW_IP}" -U "${NEW_USER}" -d "${NEW_DB_NAME}"

mydb=> DO $$
DECLARE
r record;
BEGIN
FOR r IN
SELECT format('ALTER %s %I.%I OWNER TO %I;',
CASE c.relkind
WHEN 'r' THEN 'TABLE'
WHEN 'v' THEN 'VIEW'
WHEN 'm' THEN 'MATERIALIZED VIEW'
WHEN 'S' THEN 'SEQUENCE'
WHEN 'p' THEN 'TABLE'
ELSE NULL END,
n.nspname, c.relname, 'charmed_<database-name>_owner')
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'public'
LOOP
EXECUTE r.format;
END LOOP;
END$$;
```

At this stage, the database has been completely imported. The cluster can be scaled, and the client app can be related to the new PostgreSQL 16 database.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Migrate database data using ‘backup/restore’
(migrate-data-via-backup-restore)=
# Migrate data via backup/restore

This is a guide for migrating data from modern charms. To migrate [legacy charms](/explanation/legacy-charm) data, refer to the guide [Migrate data via pg_dump](/how-to/development/migrate-data-via-pg-dump).
This is a guide for migrating data from modern charms. To migrate [legacy charms](/explanation/legacy-charm) data, refer to the guide [Migrate data via pg_dump](/how-to/data-migration/migrate-data-via-pg-dump).

This Charmed PostgreSQL K8s operator is able to restore its own [backups](/how-to/back-up-and-restore/restore-a-backup) stored on [S3-compatible storage](/how-to/back-up-and-restore/configure-s3-aws). The same restore approach is applicable to [restore backups made by a different installation](/how-to/back-up-and-restore/migrate-a-cluster) of Charmed PostgreSQL, or even another PostgreSQL charm. The backups have to be created manually using [pgBackRest](https://pgbackrest.org/)!

Expand All @@ -21,7 +22,7 @@ Below is the *general approach* to the migration (see warning above!):

1. **Retrieve root/admin-level credentials from the legacy charm.**

See examples [here](/how-to/development/migrate-data-via-pg-dump).
See examples [here](/how-to/data-migration/migrate-data-via-pg-dump).

2. **Install [pgBackRest](https://pgbackrest.org/) inside the old charm OR nearby.**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
# Migrate database data using `pg_dump` / `pg_restore`
(migrate-data-via-pg-dump)=
# Migrate database data using `pg_dump`

This document describes database **data** migration only. To migrate charms on new juju interfaces, refer to the guide [How to integrate a database with my charm](/how-to/development/integrate-with-your-charm).
This document describes database **data** migration only. To migrate charms on new juju interfaces, refer to the guide [How to integrate a database with my charm](/how-to/integrate-with-your-charm).

## Do you need to migrate?

A database migration is only required if the output of the following command is `latest/stable`:

```text
juju show-application postgresql-k8s | yq '.[] | .channel'
```
Migration is **not** necessary if the output above is `14/stable` or `16/edge`.

This guide can be used to copy data between different installations of the same (modern) charm `postgresql-k8s`, but the [backup/restore](/how-to/development/migrate-data-via-backup-restore) is more recommended for migrations between modern charms.

## Summary

The legacy K8s charm are archived in the `latest/stable` channel (read more [here](/explanation/legacy-charm)).
A minor difference in commands might be necessary for different revisions and/or Juju versions, but the general logic remains:

* Deploy the modern charm nearby
Expand Down Expand Up @@ -61,7 +48,7 @@ OLD_DB_USER=$(juju show-unit ${CLIENT_APP} | yq '.[] | .relation-info | select(.
Deploy new PostgreSQL database charm:

```text
juju deploy postgresql-k8s ${NEW_DB_APP} --channel 16/stable --trust
juju deploy postgresql-k8s ${NEW_DB_APP} --channel 16/edge --trust
```

Obtain `operator` user password of new PostgreSQL database from PostgreSQL charm:
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/deploy/aks.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ juju model-config logging-config='<root>=INFO;unit=DEBUG'
The following command deploys PostgreSQL K8s:

```text
juju deploy postgresql-k8s --channel 16/stable --trust -n 3
juju deploy postgresql-k8s --channel 16/edge --trust -n 3
```
Sample output:
```text
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/deploy/canonical-k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ juju bootstrap ck8s

```text
juju add-model postgresql
juju deploy postgresql-k8s --channel 16/stable --trust
juju deploy postgresql-k8s --channel 16/edge --trust
```

follow the deployment progress using:
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/deploy/gke.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ kubectl get pods -n welcome-model
The following commands deploy PostgreSQL K8s and PgBouncer K8s:

```text
juju deploy postgresql-k8s --channel 16/stable --trust
juju deploy postgresql-k8s --channel 16/edge --trust
juju deploy pgbouncer-k8s --trust
```

Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/deploy/multi-az.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The command below demonstrates how to deploy Charmed PostgreSQL K8s with Juju co

```text
export MYAPP="mydatabase" ; \
juju deploy postgresql-k8s --channel 16/stable ${MYAPP} --trust -n 3 \
juju deploy postgresql-k8s --channel 16/edge ${MYAPP} --trust -n 3 \
--constraints="tags=anti-pod.app.kubernetes.io/name=${MYAPP},anti-pod.topology-key=topology.kubernetes.io/zone"
```

Expand Down
10 changes: 0 additions & 10 deletions docs/how-to/development/index.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/how-to/enable-ldap.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Deploy the [GLAuth charm](https://charmhub.io/glauth-k8s):
```text
juju add-model glauth
juju deploy self-signed-certificates
juju deploy postgresql-k8s --channel 16/stable --trust
juju deploy postgresql-k8s --channel 16/edge --trust
juju deploy glauth-k8s --channel edge --trust
```

Expand Down
26 changes: 20 additions & 6 deletions docs/how-to/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,25 @@ Monitoring (COS) <monitoring-cos/index>

## Refresh (upgrade)

In-place upgrades to higher revisions of Charmed PostgreSQL 16:
Instructions for performing an in-place application refresh:

```{toctree}
:titlesonly:

Refresh (upgrade) <upgrade/index>
```

## Data migration

For charm developers looking to support PostgreSQL integrations with their charm:

```{toctree}
:maxdepth: 2
:titlesonly:

Data migration <data-migration/index>
```

## Cross-regional (cluster-cluster) async replication

Walkthrough of a cluster-cluster deployment and its essential operations:
Expand All @@ -83,13 +94,16 @@ How to replicate a subset of data to another PostgreSQL cluster:
Logical replication <logical-replication/index>
```

## Development
## Charm development

For charm developers looking to support PostgreSQL integrations with their charm:
For charm developers looking to support PostgreSQL integrations with their charm

```{toctree}
:maxdepth: 2
:titlesonly:

Development <development/index>
```
Integrate PostgreSQL with your charm <integrate-with-your-charm>
```

Other relevant guides:
* {ref}`migrate-data-via-pg-dump`
* {ref}`migrate-data-via-backup-restore`
2 changes: 1 addition & 1 deletion docs/how-to/integrate-with-another-application.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ relatedlinks: https://documentation.ubuntu.com/juju/3.6/reference/relation/, [po

This guide shows how to integrate Charmed PostgreSQL with both charmed and non-charmed applications.

For developer information about how to integrate your own charmed application with PostgreSQL, see [](/how-to/development/integrate-with-your-charm).
For developer information about how to integrate your own charmed application with PostgreSQL, see [](/how-to/integrate-with-your-charm).

## Integrate with a charmed application

Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/scale-replicas.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This guide will show you how to establish and change the amount of juju units us
To deploy PostgreSQL with multiple replicas, specify the number of desired units with the `-n` option:

```text
juju deploy postgresql-k8s --channel 16/stable -n <number_of_replicas> --trust
juju deploy postgresql-k8s --channel 16/edge -n <number_of_replicas> --trust
```

### Primary vs. leader unit
Expand Down
1 change: 0 additions & 1 deletion docs/reference/contacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ Charmed PostgreSQL K8s is an open source project that warmly welcomes community
* [Git sources for Charmed PostgreSQL K8s](https://github.com/canonical/postgresql-k8s-operator)
* [Canonical Data on Launchpad](https://launchpad.net/~data-platform)
* [Canonical Data on Matrix](https://matrix.to/#/#charmhub-data-platform:ubuntu.com)
* [Mailing list on Launchpad](https://lists.launchpad.net/data-platform/)

6 changes: 3 additions & 3 deletions docs/reference/performance-and-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Pre-deployed application profile change is planned but currently is NOT supporte
You can set the profile during deployment using the `--config` flag. For example:

```text
juju deploy postgresql-k8s --channel 16/stable --trust --config profile=testing
juju deploy postgresql-k8s --channel 16/edge --trust --config profile=testing
```

You can change the profile using the `juju config` action. For example:
Expand All @@ -38,12 +38,12 @@ For a list of all of this charm's config options, see the [Configuration tab](ht
The Juju [`--constraints`](https://juju.is/docs/juju/constraint) flag sets RAM and CPU limits for Kubernetes pods:

```text
juju deploy postgresql-k8s --channel 16/stable --trust --constraints cores=8 mem=16G
juju deploy postgresql-k8s --channel 16/edge --trust --constraints cores=8 mem=16G
```

Juju constraints can be set together with the charm's profile:

```text
juju deploy postgresql-k8s --channel 16/stable --trust --constraints cores=8 mem=16G --config profile=testing
juju deploy postgresql-k8s --channel 16/edge --trust --constraints cores=8 mem=16G --config profile=testing
```