# Internal Tables

#### Overview

pgq.queue | Queue configuration
pgq.consumer | Consumer names
pgq.subscription | Consumer registrations
pgq.tick | Per-queue snapshots (ticks)
pgq.event_* | Data tables
pgq.retry_queue | Events to be retried later

Standard triggers store events in the pgq.event_* data tables There is one top event table pgq.event_<queue_id> for each queue inherited from pgq.event_template wuith three tables for actual data pgq.event_<queue_id>_0 to pgq.event_<queue_id>_2.

The active table is rotated at interval, so that if all the consubers have passed some poin the oldes one can be emptied using TRUNCATE command for efficiency

Summary

Internal Tables |
pgq.consumer | Name to id lookup for consumers
pgq.queue | Information about available queues
pgq.tick | Snapshots for event batching
pgq.subscription | Consumer registration on a queue.
pgq.event_template | Parent table for all event tables
pgq.retry_queue | Events to be retried.

## pgq.consumer

Name to id lookup for consumers

#### Columns

co_id | consumer’s id for internal usage
co_name | consumer’s id for external usage

## pgq.queue

Information about available queues

#### Columns

queue_id | queue id for internal usage
queue_name | queue name visible outside
queue_ntables | how many data tables the queue has
queue_cur_table | which data table is currently active
queue_rotation_period | period for data table rotation
queue_switch_step1 | tx when rotation happened
queue_switch_step2 | tx after rotation was committed
queue_switch_time | time when switch happened
queue_external_ticker | ticks come from some external sources
queue_ticker_paused | ticker is paused
queue_disable_insert | disallow pgq.insert_event()
queue_ticker_max_count | batch should not contain more events
queue_ticker_max_lag | events should not age more
queue_ticker_idle_period | how often to tick when no events happen
queue_per_tx_limit | Max number of events single TX can insert
queue_data_pfx | prefix for data table names
queue_event_seq | sequence for event id’s
queue_tick_seq | sequence for tick id’s
queue_extra_maint | array of functon names to call during maintenance

## pgq.tick

Snapshots for event batching

#### Columns

tick_queue | queue id whose tick it is
tick_id | ticks id (per-queue)
tick_time | time when tick happened
tick_snapshot | transaction state
tick_event_seq | last value for event seq

## pgq.subscription

Consumer registration on a queue.

#### Columns

sub_id | subscription id for internal usage
sub_queue | queue id
sub_consumer | consumer’s id
sub_last_tick | last tick the consumer processed
sub_batch | shortcut for queue_id/consumer_id/tick_id
sub_next_tick | batch end pos

## pgq.event_template

Parent table for all event tables

#### Columns

ev_id | event’s id, supposed to be unique per queue
ev_time | when the event was inserted
ev_txid | transaction id which inserted the event
ev_owner | subscription id that wanted to retry this
ev_retry | how many times the event has been retried, NULL for new events
ev_type | consumer/producer can specify what the data fields contain
ev_data | data field
ev_extra1 | extra data field
ev_extra2 | extra data field
ev_extra3 | extra data field
ev_extra4 | extra data field

## pgq.retry_queue

Events to be retried. When retry time reaches, they will be put back into main queue.

#### Columns

ev_retry_after | time when it should be re-inserted to main queue
ev_queue | queue id, used to speed up event copy into queue
* | same as pgq.event_template

Close