Skip to main content

Roles and permissions

PostgreMQ functions normally run with the caller's privileges. Granting function execution alone is therefore insufficient for an application that must read and update queue state. info() is the exception: it can report the schema version without granting runtime roles access to migration tracking.

Separate schema ownership from application use. The supported runtime grants below allow operating PostgreMQ across the schema; they are not per-topic, per-queue, or tenant authorization.

Runtime access​

Provision the login using your normal credential-management process. As the installation owner, grant an existing postgremq_app role:

GRANT USAGE ON SCHEMA postgremq TO postgremq_app;
GRANT SELECT, INSERT, UPDATE, DELETE ON
postgremq.topics, postgremq.queues, postgremq.messages,
postgremq.message_groups, postgremq.queue_messages,
postgremq.dead_letter_queue
TO postgremq_app;
GRANT USAGE ON SEQUENCE postgremq.messages_id_seq TO postgremq_app;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA postgremq TO postgremq_app;

These grants include reading payloads and modifying other queues' state. Naming queues after tenants does not isolate tenants from a login with these privileges. Put authorization in the application or use an appropriate database boundary; do not present narrower publisher-only grants as supported without validating every invoked function and trigger.

PostgreSQL normally grants function execution to PUBLIC. If you restrict it, do so as an intentional installation policy and grant execution to every required runtime and maintenance role:

REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA postgremq FROM PUBLIC;

Review privileges after upgrades. Existing-object grants do not automatically cover every future object. If using default privileges, configure them for the role that actually creates migration objects, then test the resulting installation.

Maintenance and schema ownership​

The installer needs to create and alter the schema's objects and manage migration state. Keep that role for controlled installation and upgrades.

A maintenance login needs access to the queue tables it reads and deletes from, plus the functions it invokes. The broad runtime grants above are a practical baseline for a dedicated maintenance role. They do not provide strict separation of duties: that role can alter queue state. A deployment requiring narrower rights must validate the exact job path and upgrade behavior.

Runtime connections need not be able to read or update postgremq.postgremq_migrations. Schema status inspection and migration require separate access; do not widen runtime privileges simply to run the CLI under an application login.

Metrics access​

A metrics-only role can inspect queue counts without reading payloads:

GRANT USAGE ON SCHEMA postgremq TO postgremq_metrics;
GRANT SELECT ON postgremq.queues, postgremq.queue_messages,
postgremq.dead_letter_queue TO postgremq_metrics;
GRANT EXECUTE ON FUNCTION postgremq.queue_metrics() TO postgremq_metrics;

It needs neither postgremq.messages nor application tables. Run SELECT * FROM postgremq.queue_metrics() while authenticated as that login to verify access. A successful query as the owner does not verify the monitoring role.

Validate the boundary​

Test application startup, publication, consumption, acknowledgement, and an application-owned transaction using the intended runtime credentials. Check that the metrics role can scrape queue state and cannot read payloads. Also verify the roles' effective memberships; inherited permissions can defeat a seemingly restricted grant list.

Use PostgreSQL authentication and TLS configuration appropriate to the deployment. Keep DSNs out of application logs and shell history, and apply payload access and backup controls to the database itself. PostgreMQ does not add a separate authentication service or encrypt payloads independently of PostgreSQL.