Skip to main content

Performance and capacity

PostgreMQ capacity depends on the combined database and consumer workload. Publication rate alone is insufficient: fan-out, payload size, retries, processing duration, and retained backlog all change the amount of work.

Measure the deployment with representative data before increasing concurrency or database limits. A result from empty queues does not establish behavior behind a delayed FIFO head or a large offline subscription.

Account for amplification​

A publication stores one JSON payload and delivery state for each selected queue. Five Durable queues mean five delivery histories, even if some subscribers are offline. Exclusive queues receive a delivery only while their subscriptions are live. Retries add claims, settlements, and renewals without adding a new publication.

Long processing durations keep deliveries active longer and require extension. One delayed or failing FIFO head can leave many successors waiting; more workers cannot process those successors out of order. A few hot groups can therefore dominate latency even when other groups progress quickly.

Retention and lagging subscribers determine storage. Completed delivery rows remain until retention; a payload remains while any delivery or DLQ entry references it. Include indexes, WAL, and vacuum work in capacity planning rather than estimating storage from JSON bytes alone.

Establish a baseline​

Run a load test in an isolated database with the same PostgreSQL major version, schema and SDK releases, storage class, and relevant configuration as production.

  1. Declare the expected topic and queue topology before publishing.
  2. Publish representative payload sizes and group distributions at a controlled rate.
  3. Run workers with realistic processing time and downstream limits.
  4. Include retries, a disconnected subscriber, and a delayed or slow group head.
  5. Allow retention and maintenance to run throughout the test.
  6. Record queue age and progress, database resources, pool waits, and maintenance duration during both load and recovery.

Increase the offered rate gradually. The useful limit is where latency, recovery time, or resource headroom no longer meets the application's objective, not simply the maximum observed send rate. Keep workload, versions, hardware, and measurement interval with any published benchmark.

Tune consumers as a system​

Start with bounded handler concurrency and a batch size that does not claim far more work than the process can handle. Batch size is fetch size; handler concurrency is processing capacity. Prefetched work is already claimed and requires lifecycle management.

Increase concurrency only while database and downstream capacity remain available. Reserve pool connections for acknowledgements and renewals as well as business transactions. Count listener connections: Go and TypeScript use their main pool for listeners; Rust opens an additional listener pool.

Choose a visibility timeout with enough margin for database latency and transient interruptions. Very short timeouts increase renewal pressure and the risk of losing ownership under contention. A very long timeout delays recovery after a crash. Automatic extension lets ordinary tasks outlive their initial timeout without making that timeout irrelevant.

Polling controls how quickly work is discovered if a notification is missed. Aggressive polling increases empty claims and database load. Tune it using observed latency requirements and SDK defaults, not as a substitute for a working listener connection.

Protect database health​

Keep application-owned queue transactions short. They retain row locks until commit and can delay claims, grouped publication, or Exclusive lifetime extension. Diagnose long transactions and lock waits before increasing retry limits.

Monitor table growth and PostgreSQL autovacuum. Deleting retained rows makes space reusable; it does not mean data files immediately shrink. Tune vacuum and storage using PostgreSQL's operational guidance and measured churn. Avoid changing PostgreMQ's indexes casually: they support claim, ordering, and retention paths.

Make retention capacity exceed the rate at which eligible completed rows accumulate. Observe execution time and full batches before adjusting size or frequency. Fast maintenance has a different recovery purpose and should keep running during backlog growth.

Use Monitoring for evidence and Concurrency and backpressure for application limits. If progress stops despite apparently available capacity, begin with delivery troubleshooting.