Skip to content

Commit b2a3803

Browse files
committed
pick pgmq to 15.6
1 parent d4bcb35 commit b2a3803

File tree

6 files changed

+268
-1
lines changed

6 files changed

+268
-1
lines changed

ansible/files/postgresql_config/supautils.conf.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
supautils.extensions_parameter_overrides = '{"pg_cron":{"schema":"pg_catalog"}}'
22
supautils.policy_grants = '{"postgres":["auth.audit_log_entries","auth.identities","auth.refresh_tokens","auth.sessions","auth.users","realtime.messages","storage.buckets","storage.migrations","storage.objects","storage.s3_multipart_uploads","storage.s3_multipart_uploads_parts"]}'
33
supautils.drop_trigger_grants = '{"postgres":["auth.audit_log_entries","auth.identities","auth.refresh_tokens","auth.sessions","auth.users","realtime.messages","storage.buckets","storage.migrations","storage.objects","storage.s3_multipart_uploads","storage.s3_multipart_uploads_parts"]}'
4-
# full list: address_standardizer, address_standardizer_data_us, adminpack, amcheck, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, file_fdw, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intagg, intarray, isn, lo, ltree, moddatetime, old_snapshot, orioledb, pageinspect, pg_buffercache, pg_cron, pg_freespacemap, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_surgery, pg_tle, pg_trgm, pg_visibility, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers, xml2
4+
# full list: address_standardizer, address_standardizer_data_us, adminpack, amcheck, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, file_fdw, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intagg, intarray, isn, lo, ltree, moddatetime, old_snapshot, orioledb, pageinspect, pg_buffercache, pg_cron, pg_freespacemap, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_surgery, pg_tle, pg_trgm, pg_visibility, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgmq, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers, xml2
55
# omitted because may be unsafe: adminpack, amcheck, file_fdw, lo, old_snapshot, pageinspect, pg_buffercache, pg_freespacemap, pg_surgery, pg_visibility
66
# omitted because deprecated: intagg, xml2
7+
# omitted because doesn't require superuser: pgmq
78
supautils.privileged_extensions = 'address_standardizer, address_standardizer_data_us, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intarray, isn, ltree, moddatetime, orioledb, pg_cron, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_walinspect, pgaudit, pgcrypto, pgjwt, pg_prewarm, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgstattuple, pgsodium, pgtap, plcoffee, pljava, plls, plpgsql, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers'
89
supautils.privileged_extensions_custom_scripts_path = '/etc/postgresql-custom/extension-custom-scripts'
910
supautils.privileged_extensions_superuser = 'supabase_admin'

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
./nix/ext/pgroonga.nix
112112
./nix/ext/index_advisor.nix
113113
./nix/ext/wal2json.nix
114+
./nix/ext/pgmq.nix
114115
./nix/ext/pg_repack.nix
115116
./nix/ext/pg-safeupdate.nix
116117
./nix/ext/plpgsql-check.nix

nix/ext/pgmq.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{ lib, stdenv, fetchFromGitHub, postgresql }:
2+
3+
stdenv.mkDerivation rec {
4+
pname = "pgmq";
5+
version = "1.4.4";
6+
buildInputs = [ postgresql ];
7+
src = fetchFromGitHub {
8+
owner = "tembo-io";
9+
repo = pname;
10+
rev = "v${version}";
11+
hash = "sha256-z+8/BqIlHwlMnuIzMz6eylmYbSmhtsNt7TJf/CxbdVw=";
12+
};
13+
14+
buildPhase = ''
15+
cd pgmq-extension
16+
'';
17+
18+
installPhase = ''
19+
mkdir -p $out/{lib,share/postgresql/extension}
20+
21+
mv sql/pgmq.sql $out/share/postgresql/extension/pgmq--${version}.sql
22+
cp sql/*.sql $out/share/postgresql/extension
23+
cp *.control $out/share/postgresql/extension
24+
'';
25+
26+
meta = with lib; {
27+
description = "A lightweight message queue. Like AWS SQS and RSMQ but on Postgres.";
28+
homepage = "https://github.com/tembo-io/pgmq";
29+
maintainers = with maintainers; [ olirice ];
30+
platforms = postgresql.meta.platforms;
31+
license = licenses.postgresql;
32+
};
33+
}

nix/tests/expected/pgmq.out

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
-- Test the standard flow
2+
select
3+
pgmq.create('Foo');
4+
create
5+
--------
6+
7+
(1 row)
8+
9+
select
10+
*
11+
from
12+
pgmq.send(
13+
queue_name:='Foo',
14+
msg:='{"foo": "bar1"}'
15+
);
16+
send
17+
------
18+
1
19+
(1 row)
20+
21+
-- Test queue is not case sensitive
22+
select
23+
*
24+
from
25+
pgmq.send(
26+
queue_name:='foo', -- note: lowercase useage
27+
msg:='{"foo": "bar2"}',
28+
delay:=5
29+
);
30+
send
31+
------
32+
2
33+
(1 row)
34+
35+
select
36+
msg_id,
37+
read_ct,
38+
message
39+
from
40+
pgmq.read(
41+
queue_name:='Foo',
42+
vt:=30,
43+
qty:=2
44+
);
45+
msg_id | read_ct | message
46+
--------+---------+-----------------
47+
1 | 1 | {"foo": "bar1"}
48+
(1 row)
49+
50+
select
51+
msg_id,
52+
read_ct,
53+
message
54+
from
55+
pgmq.pop('Foo');
56+
msg_id | read_ct | message
57+
--------+---------+---------
58+
(0 rows)
59+
60+
-- Archive message with msg_id=2.
61+
select
62+
pgmq.archive(
63+
queue_name:='Foo',
64+
msg_id:=2
65+
);
66+
archive
67+
---------
68+
t
69+
(1 row)
70+
71+
select
72+
pgmq.create('my_queue');
73+
create
74+
--------
75+
76+
(1 row)
77+
78+
select
79+
pgmq.send_batch(
80+
queue_name:='my_queue',
81+
msgs:=array['{"foo": "bar3"}','{"foo": "bar4"}','{"foo": "bar5"}']::jsonb[]
82+
);
83+
send_batch
84+
------------
85+
1
86+
2
87+
3
88+
(3 rows)
89+
90+
select
91+
pgmq.archive(
92+
queue_name:='my_queue',
93+
msg_ids:=array[3, 4, 5]
94+
);
95+
archive
96+
---------
97+
3
98+
(1 row)
99+
100+
select
101+
pgmq.delete('my_queue', 6);
102+
delete
103+
--------
104+
f
105+
(1 row)
106+
107+
select
108+
pgmq.drop_queue('my_queue');
109+
drop_queue
110+
------------
111+
t
112+
(1 row)
113+
114+
/*
115+
-- Disabled until pg_partman goes back into the image
116+
select
117+
pgmq.create_partitioned(
118+
'my_partitioned_queue',
119+
'5 seconds',
120+
'10 seconds'
121+
);
122+
*/
123+
-- Make sure SQLI enabling characters are blocked
124+
select pgmq.create('F--oo');
125+
ERROR: queue name contains invalid characters: $, ;, --, or \'
126+
CONTEXT: PL/pgSQL function pgmq.format_table_name(text,text) line 5 at RAISE
127+
PL/pgSQL function pgmq.create_non_partitioned(text) line 3 during statement block local variable initialization
128+
SQL statement "SELECT pgmq.create_non_partitioned(queue_name)"
129+
PL/pgSQL function pgmq."create"(text) line 3 at PERFORM
130+
select pgmq.create('F$oo');
131+
ERROR: queue name contains invalid characters: $, ;, --, or \'
132+
CONTEXT: PL/pgSQL function pgmq.format_table_name(text,text) line 5 at RAISE
133+
PL/pgSQL function pgmq.create_non_partitioned(text) line 3 during statement block local variable initialization
134+
SQL statement "SELECT pgmq.create_non_partitioned(queue_name)"
135+
PL/pgSQL function pgmq."create"(text) line 3 at PERFORM
136+
select pgmq.create($$F'oo$$);
137+
ERROR: queue name contains invalid characters: $, ;, --, or \'
138+
CONTEXT: PL/pgSQL function pgmq.format_table_name(text,text) line 5 at RAISE
139+
PL/pgSQL function pgmq.create_non_partitioned(text) line 3 during statement block local variable initialization
140+
SQL statement "SELECT pgmq.create_non_partitioned(queue_name)"
141+
PL/pgSQL function pgmq."create"(text) line 3 at PERFORM

nix/tests/prime.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ create extension pg_graphql;
4242
create extension pg_freespacemap;
4343
create extension pg_hashids;
4444
create extension pg_prewarm;
45+
create extension pgmq;
4546
create extension pg_jsonschema;
4647
create extension pg_repack;
4748
create extension pg_stat_monitor;

nix/tests/sql/pgmq.sql

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
-- Test the standard flow
2+
select
3+
pgmq.create('Foo');
4+
5+
select
6+
*
7+
from
8+
pgmq.send(
9+
queue_name:='Foo',
10+
msg:='{"foo": "bar1"}'
11+
);
12+
13+
-- Test queue is not case sensitive
14+
select
15+
*
16+
from
17+
pgmq.send(
18+
queue_name:='foo', -- note: lowercase useage
19+
msg:='{"foo": "bar2"}',
20+
delay:=5
21+
);
22+
23+
select
24+
msg_id,
25+
read_ct,
26+
message
27+
from
28+
pgmq.read(
29+
queue_name:='Foo',
30+
vt:=30,
31+
qty:=2
32+
);
33+
34+
select
35+
msg_id,
36+
read_ct,
37+
message
38+
from
39+
pgmq.pop('Foo');
40+
41+
42+
-- Archive message with msg_id=2.
43+
select
44+
pgmq.archive(
45+
queue_name:='Foo',
46+
msg_id:=2
47+
);
48+
49+
50+
select
51+
pgmq.create('my_queue');
52+
53+
select
54+
pgmq.send_batch(
55+
queue_name:='my_queue',
56+
msgs:=array['{"foo": "bar3"}','{"foo": "bar4"}','{"foo": "bar5"}']::jsonb[]
57+
);
58+
59+
select
60+
pgmq.archive(
61+
queue_name:='my_queue',
62+
msg_ids:=array[3, 4, 5]
63+
);
64+
65+
select
66+
pgmq.delete('my_queue', 6);
67+
68+
69+
select
70+
pgmq.drop_queue('my_queue');
71+
72+
/*
73+
-- Disabled until pg_partman goes back into the image
74+
select
75+
pgmq.create_partitioned(
76+
'my_partitioned_queue',
77+
'5 seconds',
78+
'10 seconds'
79+
);
80+
*/
81+
82+
83+
-- Make sure SQLI enabling characters are blocked
84+
select pgmq.create('F--oo');
85+
select pgmq.create('F$oo');
86+
select pgmq.create($$F'oo$$);
87+
88+
89+
90+

0 commit comments

Comments
 (0)