Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/NikolayS/PgQue/llms.txt

Use this file to discover all available pages before exploring further.

PgQue exposes three primary observability functions inherited from PgQ, plus a one-stop status() view. All are granted to pgque_reader. This guide explains what each metric means and how to use it for alerting.

Queue health: get_queue_info()

select queue_name, ticker_lag, ev_per_sec, ev_new, last_tick_id
from pgque.get_queue_info('orders');
A healthy queue:
 queue_name | ticker_lag   | ev_per_sec | ev_new | last_tick_id
------------+--------------+------------+--------+--------------
 orders     | 00:00:01.842 |       3.40 |     12 |         1247
ColumnTypeMeaning
queue_nametextQueue name
queue_ntablesintegerNumber of rotation tables (default 3)
queue_cur_tableintegerIndex of the currently active rotation table
queue_rotation_periodintervalHow often the hot table rotates
queue_external_tickerbooleanWhether ticking is driven externally
queue_ticker_pausedbooleanWhether the ticker is paused
queue_ticker_max_countintegerForce a tick after N events
queue_ticker_max_lagintervalMax wall time between ticks
queue_ticker_idle_periodintervalTick interval when idle (default 1 min)
ticker_lagintervalWall time since the last tick
ev_per_secfloat8Recent event ingestion rate
ev_newbigintEvents waiting in the current table for the next tick
last_tick_idbigintMost recent tick id
To inspect all queues at once, call without arguments:
select * from pgque.get_queue_info();

Consumer health: get_consumer_info()

select queue_name, consumer_name, lag, last_seen, pending_events
from pgque.get_consumer_info('orders', 'processor');
A healthy consumer:
 queue_name | consumer_name | lag          | last_seen    | pending_events
------------+---------------+--------------+--------------+----------------
 orders     | processor     | 00:00:00.520 | 00:00:00.201 |              0
A stuck consumer a few hours later:
 queue_name | consumer_name | lag          | last_seen    | pending_events
------------+---------------+--------------+--------------+----------------
 orders     | processor     | 02:15:33.204 | 02:14:59.817 |            847
ColumnTypeMeaning
queue_nametextQueue name
consumer_nametextConsumer name
lagintervalAge of the last finished batch — high means falling behind
last_seenintervalTime since the consumer last processed a batch
last_tickbigintLast tick id the consumer processed
current_batchbigintActive batch id (null if none open)
next_tickbigintNext tick id to process (null if up to date)
pending_eventsbigintEvents waiting for this consumer
Call without arguments to see all consumers across all queues:
select * from pgque.get_consumer_info();

-- Filter to one queue
select * from pgque.get_consumer_info('orders');

Active batch info: get_batch_info()

select * from pgque.get_batch_info(:batch_id);
ColumnTypeMeaning
queue_nametextQueue name
consumer_nametextConsumer that opened the batch
batch_starttimestamptzWhen the batch was opened
batch_endtimestamptzBatch close time (null if still active)
prev_tick_idbigintStart of the tick window
tick_idbigintEnd of the tick window
lagintervalAge of the batch
seq_startbigintEvent sequence start
seq_endbigintEvent sequence end

One-stop health check: status()

select * from pgque.status();
 component  | status      | detail
------------+-------------+----------------------------------
 postgresql | info        | PostgreSQL 17.2 on ...
 pgque      | info        | 0.2.0-rc.1
 pg_cron    | scheduled   | 4 jobs active
 queues     | info        | 3 queues configured
 consumers  | info        | 7 active subscriptions
Run status() first when anything looks wrong.

Red flags to alert on

SignalRed flagCheck
ticker_lagGrowing past queue_ticker_max_lag (default 3 s)Ticker not running — check pg_cron or external scheduler
lagClimbing into minutes or longerConsumer not finishing batches — check the worker
last_seenClimbing into minutes or longerConsumer stopped calling receive — check the worker process
pending_eventsGrowing without bound while lag is highStuck consumer also blocks table rotation

Experimental observability

Load sql/experimental/observability.sql for extended monitoring functions. These are not part of the default install and their APIs may change.
\i sql/experimental/observability.sql
FunctionReturns
pgque.queue_stats()Per-queue depth, age, DLQ count, rotation stats
pgque.consumer_stats()Per-consumer lag, pending events, active batch info
pgque.queue_health()Operational checks: stuck ticker, rotation lag, DLQ growth
pgque.otel_metrics()OTel-compatible metric export rows
pgque.stuck_consumers(threshold)Consumers idle longer than threshold (default 1 hour)
pgque.in_flight(queue)Active batches per consumer with age and estimated event count
pgque.throughput(queue, period, bucket_size)Events/sec bucketed over a time window
pgque.error_rate(queue, period, bucket_size)Retries and dead letters bucketed over a time window

Build docs developers (and LLMs) love