Upgrading PostgreMQ
A PostgreMQ upgrade can change the database schema, the SDKs used by applications, or both. These components are released independently. A new SDK package does not automatically change the database unless your application explicitly runs migrations.
Plan an upgrade around the schema changes and the clients that will use them. The required rollout order and any downtime depend on that combination.
What changes during an upgrade
| Component | What upgrading it changes | Scope |
|---|---|---|
| PostgreMQ SQL schema | Database functions, tables, indexes, and other objects changed by the release's migrations. | Every application using PostgreMQ in that database. |
| Go, Rust, or TypeScript SDK | Client APIs and behavior inside the application that uses the package. | That application's deployed instances. |
| PostgreMQ CLI | The migration files and commands available to the operator. | Installing the binary alone does not modify a database. |
| PostgreSQL server | The database engine itself. | A separate PostgreSQL upgrade, with its own compatibility and recovery procedure. |
Schema migrations bring an existing installation forward while retaining its data according to the migration's contract. Use the release's migrations rather than reinstalling the complete SQL schema. Review changes to permissions, configuration, maintenance requirements, and delivery behavior as well as API signatures.
Compatibility and rollout order
Record the current schema version, the versions of every deployed SDK, and the intended targets. Read the release notes for each component you plan to change.
A compatible upgrade allows existing clients to continue using the new schema. A change that introduces a new function may require migrating the schema before deploying application code that calls it. A breaking change may require coordinating the schema and client deployments so unsupported combinations never handle traffic.
SDKs check schema compatibility when connecting. Passing that check does not prove that every newer API exists in an older schema or that your application's behavior remains correct. Validate the actual operations used by the application, including transaction-scoped calls and runtime-role permissions.
For a rolling deployment, verify both the old and new application versions against the schema they will encounter during the transition. An application rollback is safe only if the previous client still supports the resulting schema.
Will the upgrade cause downtime
There is no blanket zero-downtime guarantee. A migration's DDL can require locks, and a compatible API change can still block database operations while those locks are held. Long-running application transactions can also delay the migration.
A migration can run with applications online when the release supports the overlap and rehearsal shows acceptable locking and latency. Use a maintenance window when clients cannot safely overlap, a migration requires it, or the observed lock and execution times exceed the application's tolerance.
Rehearse on a restored database with representative data volume and the client versions involved in the rollout. Measure migration time and lock effects, and exercise publishing, consuming, acknowledgement, and application transactions afterward. Merely applying migrations to an empty database does not establish a safe production rollout.
Select the migration tool
The PostgreMQ CLI is distributed with the Go SDK and embeds a specific set of SQL migrations. Choose the CLI release whose embedded target is the schema you intend to install. Its version does not have to match the SQL version number.
Set POSTGREMQ_CLI_VERSION to the selected Go module version, including the leading v, then install it. For example, v0.4.0 is a module version; the repository tag postgremq-go/v0.4.0 is not accepted by go install. This illustrates the version format, not a recommended upgrade target:
: "${POSTGREMQ_CLI_VERSION:?Set the Go module version selected for this upgrade}"
go install "postgremq.dev/postgremq-go/cmd/postgremq@${POSTGREMQ_CLI_VERSION}"
Use the Go toolchain required by the selected release. Make sure the Go binary directory is on your PATH and that postgremq resolves to the installed binary. Record the selected module version with the deployment; the CLI has no version subcommand.
Inspect the target database:
postgremq status --dsn "$DATABASE_URL"
Read these fields:
| Field | Meaning |
|---|---|
| Current version | The schema version recorded in the database. |
| Latest version | The newest migration embedded in this CLI, not the newest release online. |
| Dirty | Whether a migration is in progress or left incomplete. Status does not acquire the migration lock. |
status can exit zero when an upgrade is pending or the database is dirty. Check the fields, rather than relying on the exit code or final “up to date” line. The displayed encoded schema number identifies a migration; use the human-readable release version to find its documentation.
The CLI applies all pending migrations through its embedded target. It has no target-version flag or down-migration command. A clean database newer than the embedded target is left unchanged. Choosing the correct CLI release is therefore part of selecting the upgrade target.
Prepare recovery and the rollout window
Before changing production, establish a recovery point and rehearse restoring it. Back up the whole database when application writes and queue operations share transactions, so they can be restored consistently.
For a PostgreSQL logical backup:
pg_dump --format=custom --file=before-postgremq-upgrade.dump "$DATABASE_URL"
pg_restore --list before-postgremq-upgrade.dump
For a schema upgrade that keeps PostgreSQL on the same major version, use that major's pg_dump and pg_restore. Check both with --version. A newer client can produce an archive that fails to restore on the recovery server. Listing an archive only checks readability; complete a restore rehearsal to validate recovery. Database roles and external maintenance schedules may need their own recovery steps.
If the rollout requires stopping application activity:
- Stop admitting new requests that publish work.
- Close consumers using graceful shutdown and a finite timeout.
- Pause maintenance jobs that touch the schema and let open application transactions finish.
- Record the final backup or recovery point before applying the migration.
Apply migrations
Run as the schema owner or a role with the privileges required by the migration's DDL:
postgremq migrate --dsn "$DATABASE_URL"
The CLI reports the current and embedded target versions, applies pending migrations, and reports success or failure. Save this output with the deployment record.
The Go, Rust, and TypeScript migrators use the same tracking and lock protocol as the CLI. Prefer one explicit deployment step to make migration timing predictable. If applications also migrate at startup, account for their embedded targets in the rollout plan.
Do not rerun the complete SQL install script to upgrade an existing installation. It is intended for fresh installations and refuses an existing migration-tracked schema. An installation originally created from a released complete SQL script can subsequently be upgraded with migrations.
Verify before resuming traffic
Run status again:
postgremq status --dsn "$DATABASE_URL"
Confirm that the current version equals the planned target and that Dirty is false. A successful command against an unintended database is not a successful rollout; use the same verified connection configuration throughout.
With runtime credentials, publish and acknowledge a test message on a dedicated smoke-test topic and queue. Exercise application commit and rollback paths. The Quick start provides equivalent send-and-receive examples in Go, Rust, and TypeScript; use dedicated names so verification does not enter a business queue.
Deploy compatible clients in the planned order, resume paused maintenance jobs and traffic, and check:
- Queue progress and ready-message age, including queues busy before the upgrade.
- New dead letters, failed acknowledgements, and unexpected consumer termination.
- Successful maintenance runs and normal database connection and lock behavior.
If migration fails
Keep the application in the planned rollout state, save the failure output, and inspect status. A dirty state can mean a migration is still running or that one did not finish cleanly. Confirm that no migrator is active before diagnosing a failed migration or repairing metadata. migrate refuses to continue until that state is reconciled. Its recorded version may identify the failed migration rather than the last fully applied one.
Inspect the migration SQL and the actual database objects before repairing tracking metadata:
| Verified database state | Recovery |
|---|---|
| The failed migration's changes are fully applied and validated | Clear the dirty flag for that version, then rerun migration and verification. |
| Its changes are absent or have been completely reversed | Record the actual previous migration version with a clean state, then rerun. Versions need not be consecutive. |
| Some changes are applied and others are not | Complete or reverse the partial changes under a reviewed recovery procedure, or restore the backup. Reconcile version metadata only once the schema is consistent. |
Clearing dirty without reconciling the schema misrepresents an incomplete installation; it does not repair it. SDK discovery checks the schema major, not dirty state, so clients may already connect while a migration is dirty. For the first migration, an empty version table represents no applied migration; do not invent a previous version number. Keep release-specific repair SQL with that release's recovery instructions.
Rollback and forward recovery
PostgreMQ does not provide automatic schema downgrade. If an application release fails against a backward-compatible schema, reverting the application may be sufficient. Otherwise, recovery may require a forward fix or database restore.
A restore can remove database work committed after the recovery point and make previously processed deliveries reappear. It does not undo effects already sent to external systems. Account for those effects before resuming consumers, and verify the recovered schema with the clients that will reconnect.