> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ankra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Change a Managed PostgreSQL Service

> Resize a running PostgreSQL service, upgrade it to a newer version of its package, roll back an upgrade whose roll failed, and rotate its owner credential, each through a review you confirm.

A managed PostgreSQL service that Ankra runs in your cluster can change after setup in four ways:

* **Resize** it: more or fewer instances, the Standard or Production tier, more storage, other CPU or memory.
* **Upgrade** it to a newer version of its package within the same PostgreSQL major.
* **Roll back** an upgrade whose roll failed, to the version the service ran before.
* **Rotate its owner credential**, the password of the database owner `app`.

Each change takes two steps. Preparing it stores a review that says what will happen to the running database, and changes nothing. Confirming the review by its digest, within 10 minutes, makes the change. The service keeps its name, its data and its connections through all four.

Resizing and upgrading are available through the API, over [MCP](https://docs.ankra.ai/platform/mcp-tools.md) and in Ask Ankra, which asks you to approve each confirmation. Rotating the owner credential is available through the API. The Ankra CLI and the web app have no command or page for these changes yet.

Other services, such as Valkey or OpenSearch, cannot be resized or upgraded yet. To give one of them other settings, [delete it](https://docs.ankra.ai/guides/delete-a-managed-service.md) and set it up again, which starts it with new credentials and none of its data.

***

## Before you start

* **The service is a PostgreSQL service Ankra runs in one of your clusters**, and its installation has finished.
* **Your role allows it:** `applications.deploy` in the project of the service's cluster, and `clusters.read` and `clusters.operate` on the service's cluster. Rotating the owner credential also needs `clusters.read` and `clusters.operate` on the cluster of every application environment connected to the service. The built-in `owner`, `admin` and `operator` roles hold all of them. See [Roles and access](https://docs.ankra.ai/guides/roles-and-access.md).
* **You have the service's id and generation.** Read the service with [Get a managed service instance](https://docs.ankra.ai/api-reference/services/get-a-managed-service-instance.md), or `get_service_instance` over MCP, for its `id` and `generation`. A review is prepared for the generation you read, and a review of any other generation is refused, so read the service again after it changed.

Each person can hold at most 10 reviews of each kind waiting for confirmation, and each organisation 50. A review you do not confirm expires on its own and changes nothing.

***

## Resize the service

A resize changes any of these settings and keeps the others. The ranges are the package's, as under [Managed Service Settings](https://docs.ankra.ai/reference/managed-services.md#postgresql):

| Setting | What it can become |
| - | - |
| `instances` | 1 to 3 |
| `tier` | 0 (Standard) or 1 (Production) |
| `storage_gib` | Larger than now, up to 1000. Storage never shrinks |
| `memory_mib` | 256 to 16384 |
| `cpu_millicores` | 100 to 8000 |

What happens to the running database depends on what changes, and the review says it in its `effects`:

* **CPU or memory.** CloudNativePG restarts each instance with the new values, the replicas first and the primary last after a switchover, so connections to the primary drop once. A single instance is unavailable until it is back, usually under a minute.
* **Tier.** CloudNativePG recreates the instances one at a time, the replicas first and the primary last after a switchover.
* **More instances.** Each new instance is a replica cloned from the primary, which keeps serving while they join. **Fewer instances** removes replicas and their volumes, and the primary keeps serving.
* **Storage.** Every instance's volume grows in place, without a restart where the StorageClass expands volumes online. It can never be made smaller again. A grow is refused up front when a StorageClass of the service's volumes does not allow volume expansion.

The Production tier needs 3 instances and three nodes that can run them, as at setup, and is refused on a playground.

> [tab] API
>
> **1. Prepare the resize**
>
> [Prepare a managed-service resize review](https://docs.ankra.ai/api-reference/services/prepare-a-managed-service-resize-review.md) with the settings to change:
>
> ```bash theme={null}
> curl -X POST https://platform.ankra.app/api/v1/org/service-admission/instances/<instance-id>/reconfigurations \
>   -H "Authorization: Bearer <your-token>" \
>   -H "Content-Type: application/json" \
>   -d '{"expected_generation": <generation>, "parameters": {"storage_gib": 50, "memory_mib": 1024}}'
> ```
>
> The answer carries the resize's `id`, its `plan` and its `digest`. The plan lists each change with its old and new value in `changes`, the stack variables that move in `variables`, and what happens to the database in `effects`. Nothing changes yet.
>
> **2. Confirm it by its digest**
>
> [Confirm a managed-service resize by its digest](https://docs.ankra.ai/api-reference/services/confirm-a-managed-service-resize-by-its-digest.md) within the 10 minutes:
>
> ```bash theme={null}
> curl -X POST https://platform.ankra.app/api/v1/org/service-admission/instances/<instance-id>/reconfigurations/<reconfiguration-id>/confirm \
>   -H "Authorization: Bearer <your-token>" \
>   -H "Content-Type: application/json" \
>   -d '{"digest": "<digest>"}'
> ```
>
> The platform resolves the plan again and refuses when anything it covers changed since the review. It then writes the new size to the service's stack and deploys it, and `operation_id` is that deployment. Confirming again with the same digest returns the same resize.

> [tab] MCP
>
> `prepare_service_reconfiguration` with the service's `instance_id`, the `expected_generation` you read and the `parameters` to change returns the review. `confirm_service_reconfiguration` with its `reconfiguration_id` and `digest` applies it.

***

## Upgrade the service

An upgrade moves the service to a newer version of its own package that runs the same PostgreSQL major, such as a newer PostgreSQL 18 release. Name the version as `target_version_id`, or leave it out to move to the newest version your organisation can use. [List visible package versions](https://docs.ankra.ai/api-reference/services/list-visible-package-versions.md) lists the versions with their ids. Moving to another PostgreSQL major is not available yet.

The review shows the package version, profile version, PostgreSQL image and CloudNativePG cluster chart the service moves from and to, the changelog between them, the disruption, the applications connected, and the stack's backup policy, which the upgrade keeps. The service keeps its name, data, credentials, connections and size.

* **Each instance restarts once onto a new image.** With replicas, CloudNativePG restarts the replicas first, then switches the primary role over and restarts the old primary, so connections to the primary drop once and the service keeps serving. A single instance is unavailable while it restarts. When the image does not change, no instance restarts for an image, and the changelog says what else changes.
* **No backup is taken first.** The most recent restore point is the one the backup policy last took. To have a newer one, take it before you confirm: `ankra cluster stacks restore-points create <service> --cluster <cluster> --wait`.
* **The service must be serving**, and is refused while a resize or retirement review of it is open.

> [tab] API
>
> **1. Prepare the upgrade**
>
> [Prepare a managed-service upgrade review](https://docs.ankra.ai/api-reference/services/prepare-a-managed-service-upgrade-review.md):
>
> ```bash theme={null}
> curl -X POST https://platform.ankra.app/api/v1/org/service-admission/instances/<instance-id>/upgrades \
>   -H "Authorization: Bearer <your-token>" \
>   -H "Content-Type: application/json" \
>   -d '{"expected_generation": <generation>}'
> ```
>
> Add `"target_version_id": "<version-id>"` to move to a version other than the newest. The answer carries the upgrade's `id`, its `plan` and its `digest`, and `backup_observation`, what the platform last saw of the service's backups. Nothing changes yet.
>
> **2. Confirm it by its digest**
>
> [Confirm a managed-service upgrade by its digest](https://docs.ankra.ai/api-reference/services/confirm-a-managed-service-upgrade-by-its-digest.md) within the 10 minutes:
>
> ```bash theme={null}
> curl -X POST https://platform.ankra.app/api/v1/org/service-admission/instances/<instance-id>/upgrades/<upgrade-id>/confirm \
>   -H "Authorization: Bearer <your-token>" \
>   -H "Content-Type: application/json" \
>   -d '{"digest": "<digest>"}'
> ```
>
> The platform resolves the plan again, including that the service is still serving, rolls the new version onto the service's stack in place and deploys it. `operation_id` is that deployment.

> [tab] MCP
>
> `prepare_service_upgrade` with the service's `instance_id` and the `expected_generation` you read, and `target_version_id` for a version other than the newest, returns the review. `confirm_service_upgrade` with its `upgrade_id` and `digest` applies it.

***

## Roll back an upgrade whose roll failed

When the deployment of an upgrade fails or is cancelled and the service stops serving, an upgrade can still be prepared. The way back is to prepare an upgrade again, as above, back to the version the service ran before. Name that version as `target_version_id`: it is `plan.from.package_version_id` in the review of the upgrade that failed, and [List visible package versions](https://docs.ankra.ai/api-reference/services/list-visible-package-versions.md) lists it with its id too. The review then carries `plan.rollback: true`. Preparing to a newer version than the failed one is allowed as well.

A rollback moves back the package version, the profile version, the PostgreSQL image, which restarts the instances when it differs, and the CloudNativePG cluster chart. It does not restore data: the service keeps its data, name, credentials, connections and size as they are. To go back to the data of an earlier moment, [restore the service into a new service](https://docs.ankra.ai/guides/restore-a-managed-postgresql-service.md). A rollback that would move another add-on to an older chart is refused, and names the add-on.

A rollback is offered only while Ankra can show that the roll of the last upgrade failed. While that deployment is still running, or succeeded, the service is refused as not serving, and the refusal says why.

***

## Rotate the owner credential

Rotating changes the password of `app`, the owner of the database `app`, which the service keeps in the Secret `postgresql-app`. Ankra deletes that Secret, and CloudNativePG creates it again with a password it generates in the cluster and sets on `app`. Ankra never sees, stores or logs the password.

Every application connected with the owner credential is affected, and the review names each one:

* **An application on the owner credential** keeps its open connections until they close, but cannot open new ones with the old password. Its next deploy copies the new password into its connection and rolls the pods that read it, so deploy each such application once you have confirmed. There is no period in which both passwords work.
* **An application with a PostgreSQL role of its own** is not affected. See [Which credential your application connects with](https://docs.ankra.ai/guides/connect-to-a-managed-service.md#which-credential-your-application-connects-with).
* **Copies of the password made by hand**, such as the values given to an application on another cluster, stop working, and so does a copy a disconnected application may still hold.

**1. Prepare the rotation**

[Prepare a managed-service owner credential rotation review](https://docs.ankra.ai/api-reference/services/prepare-a-managed-service-owner-credential-rotation-review.md):

```bash theme={null}
curl -X POST https://platform.ankra.app/api/v1/org/service-admission/instances/<instance-id>/credential-rotations \
  -H "Authorization: Bearer <your-token>" \
  -H "Content-Type: application/json" \
  -d '{"expected_generation": <generation>}'
```

The answer carries the rotation's `id`, its `plan` and its `digest`. The plan's `consumers` says, for each connected application environment, whether it is on the owner credential, has a role of its own, has no connection delivered yet, or runs on another cluster, and `breaking` counts those whose connection breaks; the plan's `statements.other_copies` says what else stops working. Nothing changes yet.

**2. Confirm it by its digest**

[Confirm a managed-service owner credential rotation by its digest](https://docs.ankra.ai/api-reference/services/confirm-a-managed-service-owner-credential-rotation-by-its-digest.md) within the 10 minutes:

```bash theme={null}
curl -X POST https://platform.ankra.app/api/v1/org/service-admission/instances/<instance-id>/credential-rotations/<rotation-id>/confirm \
  -H "Authorization: Bearer <your-token>" \
  -H "Content-Type: application/json" \
  -d '{"digest": "<digest>"}'
```

The answer's `effect` says whether the rotation took effect. `taken`: Ankra saw the new Secret, and each application environment on the owner credential now needs a deploy. `awaiting`: Ankra has not seen the new Secret yet, and confirming again reads it again. `lapsed`: the rotation never took effect.

**3. Deploy the applications on the owner credential**

Deploy each application environment the review named as on the owner credential. Until its next deploy, it cannot open new connections to the database.

***

## Troubleshooting

Every change is refused before anything is written, and says why.

| What you see | Cause | Remedy |
| - | - | - |
| `The service changed since it was read` | The service's generation moved since you read it | Read the service again and prepare the review again |
| The review has expired, or has changed, and is to be reviewed again | The 10 minutes passed, or what the review covers moved | Prepare the review again |
| `Only instances, tier, storage_gib, memory_mib and cpu_millicores can be changed on a running service` | The resize names another setting | Leave that setting out |
| `PostgreSQL storage can only grow` | The resize asks for less storage than the service has | Kubernetes cannot shrink a volume in place. To run on less storage, set up a new service from this one's backups and move the applications to it |
| A StorageClass of the service's volumes does not allow volume expansion, or Ankra cannot see the StorageClass or the volume claims | The storage cannot be shown to grow | Use a StorageClass that allows volume expansion, or try again once the cluster is connected and the instances run |
| `The request changes nothing` | Every value is the one the service runs with now | Nothing to do |
| `The service has an open upgrade review` or `an open resize review` | A resize and an upgrade cannot be open together | Confirm the other review, or let it expire |
| `Moving between PostgreSQL majors is a major upgrade, which is not available yet` | The version runs another PostgreSQL major | Choose a version within the major the service runs |
| `The service already runs the newest version of its package` | There is nothing newer | Nothing to do |
| `not serving; upgrade it once it is serving` | The service is not serving, and it is not the failed roll of its last upgrade | Upgrade it once it serves again |
| `resize the service first` | The new version does not allow a setting at the value the service runs with | Resize the service into the new version's range, then upgrade |
| `The service's stack was changed outside Services` | The service's stack was renamed, replaced, is being deleted, or was edited by hand | Change it back so it matches the service again |
| `Ankra cannot see the service's owner credential Secret (postgresql-app)` or `does not see the CloudNativePG operator serving` | The cluster has not synced, or the operator does not run | Try again once the cluster has synced and the operator runs |
| `The service's database Cluster does not read ready` | The database is not healthy, so it could not take a new password | Rotate once the database is healthy |
| `The service's owner credential is already being rotated` | An earlier rotation may still take effect | Prepare the rotation again once it has |

***

## Next steps

> [card] [Managed Service Settings](https://docs.ankra.ai/reference/managed-services.md#postgresql)
>
> Every PostgreSQL setting, its range and what it changes.

> [card] [Restore a PostgreSQL service](https://docs.ankra.ai/guides/restore-a-managed-postgresql-service.md)
>
> Create a new service from the backups of another one, as of a moment you choose.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.