Skip to main content

Schema and storage

Source commit cbff27b8a34e1384384018680e46c20d5c610cc9.

This page describes SQL 0.1.1 for inspection and operations. The public functions are the application contract; table layout, indexes, and triggers are implementation details that can change through migrations. Avoid direct writes that bypass validation, distribution, ownership, or notification behavior.

Stored relationships​

ObjectPurpose
topicsNamed publication destinations.
queuesSubscription settings, generation, and Exclusive lifetime.
messagesOne JSONB payload and publication metadata per message.
queue_messagesDelivery state, attempt count, visibility deadline, ownership token, and completion time per queue/message.
dead_letter_queueRetained failed deliveries with references to queue and payload.
message_groupsGroup sequence state used for ordered publication.
postgremq_migrationsInstalled migration version and dirty state.

Fan-out shares the payload but creates delivery state for each selected queue. Acknowledging one queue does not mutate another queue's progress. Completed delivery history and unreferenced payloads are collected separately.

Identity and ownership​

A message's BIGINT ID identifies the publication. It is not a committed-publication counter: rolled-back work can leave sequence gaps. Do not derive throughput or completeness from differences between message IDs.

Each queue incarnation has a UUID generation. Deleting and recreating a name changes that identity, allowing clients to reject silent replacement. Each claim also has an ownership token; a new attempt can retain the same message ID while changing the token.

Grouped messages carry a group key and sequence. Sequence values express publication order within the topic's group, while head eligibility is evaluated independently per queue. Group state can be pruned after all its payloads disappear; a later use of that key need not continue an eternal sequence number.

Inspection paths​

Use list_topics, list_queues, list_messages, and get_message for supported inspection. list_messages deliberately omits payloads and tokens; fetch the payload only when needed and authorized. DLQ listing and raw queue statistics have separate scopes.

queue_metrics provides state evaluated at one statement timestamp and excludes completed history. Ready rows can still be blocked by group ordering or concurrent locks. See Metrics for the exact definitions.

Retention and constraints​

Queue delivery rows reference payloads. DLQ references preserve messages and can prevent deletion of a queue or a topic's payloads. Acknowledgement does not immediately delete the payload, and an offline subscriber can retain it after other queues complete.

Foreign-key actions determine what deletion can remove:

Referenced parentReferencing childOn parent deletion
topicsqueues, messages, message_groupsCASCADE
queuesqueue_messagesCASCADE
messagesqueue_messagesCASCADE
queuesdead_letter_queueRESTRICT
messagesdead_letter_queueRESTRICT

A topic deletion can therefore cascade through subscriptions, payloads, deliveries, and group state, while either DLQ foreign key can block the affected deletion. The administrative functions add their own preconditions; see delete_topic, delete_queue, and clean_up_topic, including their concurrency boundaries.

queue_messages.status is constrained to pending, processing, or completed, and non-null delivery_attempts must be nonnegative. These two columns are nullable: the CHECK constraints do not reject NULL. Both messages and queue_messages require group_key and group_seq to be either both NULL or both non-NULL.

The cleanup functions delete eligible completed deliveries in bounded batches and then collect payloads with no remaining queue or DLQ reference. Normal cleanup is not equivalent to clean_up_queue, clean_up_topic, or a purge; those operations can discard active work.

Indexes support visibility scans, group-head checks, status counting, completion retention, and reference checks. Monitor their size and PostgreSQL vacuum behavior with the workload. Do not remove an index based only on an idle database's usage counters; it may be needed during backlog or recovery.

Migration metadata​

SQL versions use major × 100000000 + minor × 10000 + patch in migration tracking. info() exposes this encoded version for discovery. A dirty flag means migration state requires investigation; changing metadata does not repair schema objects.

Back up queue state, migration state, and transactionally related application data consistently. See Backup and recovery and Upgrading.