Backup and recovery
A PostgreMQ backup must preserve topics, queues, payloads, deliveries, dead letters, message-group sequence state (postgremq.message_groups), and migration state together. Restoring group sequences separately from messages can break FIFO ordering. When queue operations share transactions with application data, back up and restore that data within the same consistency boundary.
Restoring a database restores an earlier queue history. It cannot roll back external effects performed after the backup point, and it may make already processed work available again.
Choose the recovery unit
A full database logical backup is a useful reproducible restore path. Physical backups and point-in-time recovery may better meet recovery-time and data-loss objectives for larger deployments. Use PostgreSQL or your provider's supported procedures and test the exact database version and environment involved.
Avoid independently restoring queue tables or only the postgremq schema alongside application data from a different point in time when correctness depends on their transactions. Queue payload and delivery relationships, migration state, and application state must agree.
Use PostgreSQL backup guidance to choose logical or physical recovery and include roles, credentials, extensions, and deployment configuration as required by that method.
Create and rehearse a logical backup
The following uses a custom-format whole-database archive. Select pg_dump and pg_restore versions compatible with both the source and planned restore target. Using tools matching the server's major version is a straightforward rehearsal choice; a newer tool can emit settings an older restore target does not accept.
pg_dump --version
pg_restore --version
pg_dump --format=custom --file=postgremq-database.dump "$DATABASE_URL"
pg_restore --list postgremq-database.dump
Listing the archive checks readability, not restorability. Restore into a new, isolated database with the required roles available. Set RESTORE_DATABASE_URL to that empty database:
: "${RESTORE_DATABASE_URL:?Set the isolated restore target}"
pg_restore --exit-on-error --dbname "$RESTORE_DATABASE_URL" postgremq-database.dump
postgremq status --dsn "$RESTORE_DATABASE_URL"
psql "$RESTORE_DATABASE_URL" -v ON_ERROR_STOP=1 -c 'SELECT postgremq.info();' -c 'SELECT * FROM postgremq.list_queues();' -c 'SELECT * FROM postgremq.queue_metrics();'
Use a CLI whose embedded release is known, and compare the restored current schema version with the version expected in the backup. A restore is not an instruction to migrate to whatever schema the locally installed CLI carries.
Do not point production clients at the rehearsal database. Prevent external side effects when exercising its consumers. Verify representative payloads, retained backlogs, DLQ entries, application rows, and runtime permissions. Record restore duration and any required manual steps.
Account for restored delivery state
A processing delivery may already have passed its visibility deadline by the time a restore finishes. Consumers can recover it under the normal attempt policy; exhausted final attempts require maintenance. Expect redelivery even if an old application once considered that message finished.
Exclusive queues whose stored lifetime has expired cannot be resumed. Recreate session subscriptions deliberately. Running maintenance may remove their retained deliveries once deletion is permitted.
Completed deliveries in a backup reflect completion at that snapshot, not the full processing history after it. External APIs and other databases do not follow the restored PostgreSQL timeline. Reconcile application event IDs and external idempotency records before allowing restored workers to repeat irreversible effects.
Return to service
Stop or isolate traffic to the failed database. Restore through the chosen procedure, then verify schema state, credentials, endpoint routing, and the application's recovery decision. Resume maintenance and monitoring, followed by controlled publication and consumption.
Check queue progress and duplicates during rollout rather than only database readiness. Keep the original evidence and backup until recovery is verified. If the restore fails, preserve its first error and repeat into a fresh isolated target after correcting prerequisites; do not improvise partial table replacement in the live database.