Internal Functions

Summary
Internal Functions
Low-level event handling
pgq.batch_event_sql(1)Creates SELECT statement that fetches events for this batch.
pgq.batch_event_tables(1)Returns set of table names where this batch events may reside.
pgq.event_retry_raw(12)Allows full control over what goes to retry queue.
pgq.find_tick_helper(6)Helper function for pgq.next_batch_custom() to do extended tick search.
Ticker
pgq.ticker(3)External ticker: Insert a tick with a particular tick_id and timestamp.
pgq.ticker(1)Check if tick is needed for the queue and insert it.
pgq.ticker(0)Creates ticks for all unpaused queues which dont have external ticker.
Periodic maintenence
pgq.maint_retry_events(0)Moves retry events back to main queue.
pgq.maint_rotate_tables_step1(1)Rotate tables for one queue.
pgq.maint_rotate_tables_step2(0)Stores the txid when the rotation was visible.
pgq.maint_tables_to_vacuum(0)Returns list of tablenames that need frequent vacuuming.
pgq.maint_operations(0)Returns list of functions to call for maintenance.
Random utility functions
pgq.grant_perms(1)Make event tables readable by public.
pgq.grant_perms_from(1)Copy grants from one table to another.
pgq.tune_storage(1)Tunes storage settings for queue data tables
pgq.force_tick(2)Simulate lots of events happening to force ticker to tick.
pgq.seq_getval(1)Read current last_val from seq, without affecting it.
pgq.seq_setval(2)Like setval() but does not allow going back.
pgq.quote_fqname(1)Quete fully-qualified object name for SQL.

Low-level event handling

pgq.batch_event_sql(1)

pgq.batch_event_sql(x_batch_id bigint) returns text

Creates SELECT statement that fetches events for this batch.

Parameters

x_batch_idID of a active batch.

Returns

SQL statement.

pgq.batch_event_tables(1)

pgq.batch_event_tables(x_batch_id bigint) returns setof text

Returns set of table names where this batch events may reside.

Parameters

x_batch_idID of a active batch.

pgq.event_retry_raw(12)

pgq.event_retry_raw(x_queue text,
x_consumer text,
x_retry_after timestamptz,
x_ev_id bigint,
x_ev_time timestamptz,
x_ev_retry integer,
x_ev_type text,
x_ev_data text,
x_ev_extra1 text,
x_ev_extra2 text,
x_ev_extra3 text,
x_ev_extra4 text) returns bigint

Allows full control over what goes to retry queue.

Parameters

x_queuename of the queue
x_consumername of the consumer
x_retry_afterwhen the event should be processed again
x_ev_idevent id
x_ev_timecreation time
x_ev_retryretry count
x_ev_typeuser data
x_ev_datauser data
x_ev_extra1user data
x_ev_extra2user data
x_ev_extra3user data
x_ev_extra4user data

Returns

Event ID.

pgq.find_tick_helper(6)

pgq.find_tick_helper(in i_queue_id int4,
in i_prev_tick_id int8,
in i_prev_tick_time timestamptz,
in i_prev_tick_seq int8,
in i_min_count int8,
in i_min_interval interval,
out next_tick_id int8,
out next_tick_time timestamptz,
out next_tick_seq int8) as

Helper function for pgq.next_batch_custom() to do extended tick search.

Ticker

pgq.ticker(3)

pgq.ticker(i_queue_name text,
i_tick_id bigint,
i_orig_timestamp timestamptz,
i_event_seq bigint) returns bigint

External ticker: Insert a tick with a particular tick_id and timestamp.

Parameters

i_queue_nameName of the queue
i_tick_idId of new tick.

Returns

Tick id.

pgq.ticker(1)

pgq.ticker(i_queue_name text) returns bigint

Check if tick is needed for the queue and insert it.

For pgqadm usage.

Parameters

i_queue_nameName of the queue

Returns

Tick id or NULL if no tick was done.

pgq.ticker(0)

pgq.ticker() returns bigint

Creates ticks for all unpaused queues which dont have external ticker.

Returns

Number of queues that were processed.

Periodic maintenence

pgq.maint_retry_events(0)

pgq.maint_retry_events() returns integer

Moves retry events back to main queue.

It moves small amount at a time.  It should be called until it returns 0

Returns

Number of events processed.

pgq.maint_rotate_tables_step1(1)

pgq.maint_rotate_tables_step1(i_queue_name text) returns integer

Rotate tables for one queue.

Parameters

i_queue_nameName of the queue

Returns

0

pgq.maint_rotate_tables_step2(0)

pgq.maint_rotate_tables_step2() returns integer

Stores the txid when the rotation was visible.  It should be called in separate transaction than pgq.maint_rotate_tables_step1()

pgq.maint_tables_to_vacuum(0)

pgq.maint_tables_to_vacuum() returns setof text

Returns list of tablenames that need frequent vacuuming.

The goal is to avoid hardcoding them into maintenance process.

Returns

List of table names.

pgq.maint_operations(0)

pgq.maint_operations(out func_name text,
out func_arg text) returns setof record

Returns list of functions to call for maintenance.

The goal is to avoid hardcoding them into maintenance process.

Function signature

Function should take either 1 or 0 arguments and return 1 if it wants to be called immediately again, 0 if not.

Returns

func_nameFunction to call
func_argOptional argument to function (queue name)

Random utility functions

pgq.grant_perms(1)

pgq.grant_perms(x_queue_name text) returns integer

Make event tables readable by public.

Parameters

x_queue_nameName of the queue.

Returns

nothing

pgq.grant_perms_from(1)

Copy grants from one table to another.  Workaround for missing GRANTS option for CREATE TABLE LIKE.

pgq.tune_storage(1)

pgq.tune_storage(i_queue_name text) returns integer

Tunes storage settings for queue data tables

pgq.force_tick(2)

pgq.force_tick(i_queue_name text) returns bigint

Simulate lots of events happening to force ticker to tick.

Should be called in loop, with some delay until last tick changes or too much time is passed.

Such function is needed because paraller calls of pgq.ticker() are dangerous, and cannot be protected with locks as snapshot is taken before locking.

Parameters

i_queue_nameName of the queue

Returns

Currently last tick id.

pgq.seq_getval(1)

pgq.seq_getval(i_seq_name text) returns bigint

Read current last_val from seq, without affecting it.

Parameters

i_seq_nameName of the sequence

Returns

last value.

pgq.seq_setval(2)

pgq.seq_setval(i_seq_name text,
i_new_value int8) returns bigint

Like setval() but does not allow going back.

Parameters

i_seq_nameName of the sequence
i_new_valuenew value

Returns

current last value.

pgq.quote_fqname(1)

pgq.quote_fqname(i_name text) returns text

Quete fully-qualified object name for SQL.

First dot is taken as schema separator.

If schema is missing, ‘public’ is assumed.

Parameters

i_namefully qualified object name.

Returns

Quoted name.

pgq.batch_event_sql(x_batch_id bigint) returns text
Creates SELECT statement that fetches events for this batch.
pgq.batch_event_tables(x_batch_id bigint) returns setof text
Returns set of table names where this batch events may reside.
pgq.event_retry_raw(x_queue text,
x_consumer text,
x_retry_after timestamptz,
x_ev_id bigint,
x_ev_time timestamptz,
x_ev_retry integer,
x_ev_type text,
x_ev_data text,
x_ev_extra1 text,
x_ev_extra2 text,
x_ev_extra3 text,
x_ev_extra4 text) returns bigint
Allows full control over what goes to retry queue.
pgq.find_tick_helper(in i_queue_id int4,
in i_prev_tick_id int8,
in i_prev_tick_time timestamptz,
in i_prev_tick_seq int8,
in i_min_count int8,
in i_min_interval interval,
out next_tick_id int8,
out next_tick_time timestamptz,
out next_tick_seq int8) as
Helper function for pgq.next_batch_custom() to do extended tick search.
pgq.ticker(i_queue_name text,
i_tick_id bigint,
i_orig_timestamp timestamptz,
i_event_seq bigint) returns bigint
External ticker: Insert a tick with a particular tick_id and timestamp.
pgq.ticker(i_queue_name text) returns bigint
Check if tick is needed for the queue and insert it.
pgq.ticker() returns bigint
Creates ticks for all unpaused queues which dont have external ticker.
pgq.maint_retry_events() returns integer
Moves retry events back to main queue.
pgq.maint_rotate_tables_step1(i_queue_name text) returns integer
Rotate tables for one queue.
pgq.maint_rotate_tables_step2() returns integer
Stores the txid when the rotation was visible.
pgq.maint_tables_to_vacuum() returns setof text
Returns list of tablenames that need frequent vacuuming.
pgq.maint_operations(out func_name text,
out func_arg text) returns setof record
Returns list of functions to call for maintenance.
pgq.grant_perms(x_queue_name text) returns integer
Make event tables readable by public.
pgq.tune_storage(i_queue_name text) returns integer
Tunes storage settings for queue data tables
pgq.force_tick(i_queue_name text) returns bigint
Simulate lots of events happening to force ticker to tick.
pgq.seq_getval(i_seq_name text) returns bigint
Read current last_val from seq, without affecting it.
pgq.seq_setval(i_seq_name text,
i_new_value int8) returns bigint
Like setval() but does not allow going back.
pgq.quote_fqname(i_name text) returns text
Quete fully-qualified object name for SQL.
Close