Skip to content

Commit d24fb7f

Browse files
committed
convert ownership to postgres
1 parent 85bc04e commit d24fb7f

File tree

9 files changed

+563
-13
lines changed

9 files changed

+563
-13
lines changed

ansible/files/postgresql_config/supautils.conf.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ supautils.policy_grants = '{"postgres":["auth.audit_log_entries","auth.identitie
33
# 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
44
# omitted because may be unsafe: adminpack, amcheck, file_fdw, lo, old_snapshot, pageinspect, pg_buffercache, pg_freespacemap, pg_surgery, pg_visibility
55
# omitted because deprecated: intagg, xml2
6-
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_partman, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_walinspect, pgaudit, pgcrypto, pgjwt, pg_prewarm, pgmq, 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'
6+
7+
# Adding extensions to this list causes them to be owned by supabase_admin vs the default of postgres
8+
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'
79
supautils.privileged_extensions_custom_scripts_path = '/etc/postgresql-custom/extension-custom-scripts'
810
supautils.privileged_extensions_superuser = 'supabase_admin'
911
supautils.privileged_role = 'postgres'

ansible/vars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ postgres_major:
1111

1212
# Full version strings for each major version
1313
postgres_release:
14-
postgres15: "15.8.1.005"
15-
postgres16: "16.3.1.011"
14+
postgres15: "15.8.1.005-staging-1"
15+
postgres16: "16.3.1.011-staging-1"
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: "1.19.0"

flake.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@
135135
./nix/ext/pgroonga.nix
136136
./nix/ext/index_advisor.nix
137137
./nix/ext/wal2json.nix
138-
# pending resolution of a permissions issue. Use 15.5.1.004 on staging to test
139-
# ./nix/ext/pgmq.nix
140-
# ./nix/ext/pg_partman.nix
138+
./nix/ext/pgmq.nix
141139
./nix/ext/pg_repack.nix
142140
./nix/ext/pg-safeupdate.nix
143141
./nix/ext/plpgsql-check.nix
@@ -153,6 +151,7 @@
153151
./nix/ext/pg_hashids.nix
154152
./nix/ext/pgsodium.nix
155153
./nix/ext/pg_graphql.nix
154+
./nix/ext/pg_partman.nix
156155
./nix/ext/pg_stat_monitor.nix
157156
./nix/ext/pg_jsonschema.nix
158157
./nix/ext/pgvector.nix

nix/tests/expected/extensions_sql_interface.out

Lines changed: 133 additions & 5 deletions
Large diffs are not rendered by default.

nix/tests/expected/pg_partman.out

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
create schema if not exists partman_test;
2+
/*
3+
Simple Time Based: 1 Partition Per Day
4+
5+
For native partitioning, you must start with a parent table that has already been set up to be partitioned in the desired type. Currently pg_partman only supports the RANGE type of partitioning (both for time & id). You cannot turn a non-partitioned table into the parent table of a partitioned set, which can make migration a challenge. This document will show you some techniques for how to manage this later. For now, we will start with a brand new table in this example. Any non-unique indexes can also be added to the parent table in PG11+ and they will automatically be created on all child tables.
6+
*/
7+
create table partman_test.time_taptest_table(
8+
col1 int,
9+
col2 text default 'stuff',
10+
col3 timestamptz not null default now()
11+
)
12+
partition by range (col3);
13+
create index on partman_test.time_tap (col3);
14+
ERROR: relation "partman_test.time_tap" does not exist
15+
/*
16+
Unique indexes (including primary keys) cannot be created on a natively partitioned parent unless they include the partition key. For time-based partitioning that generally doesn't work out since that would limit only a single timestamp value in each child table. pg_partman helps to manage this by using a template table to manage properties that currently are not supported by native partitioning. Note that this does not solve the issue of the constraint not being enforced across the entire partition set. See the main documentation to see which properties are managed by the template.
17+
18+
Manually create the template table first so that when we run create_parent() the initial child tables that are created will have a primary key. If you do not supply a template table to pg_partman, it will create one for you in the schema that you installed the extension to. However properties you add to that template are only then applied to newly created child tables after that point. You will have to retroactively apply those properties manually to any child tables that already existed.
19+
*/
20+
create table partman_test.time_taptest_table_template (like partman_test.time_taptest_table);
21+
alter table partman_test.time_taptest_table_template add primary key (col1);
22+
/*
23+
Review tables in the partman_test schema
24+
*/
25+
select
26+
table_name,
27+
table_type
28+
from
29+
information_schema.tables
30+
where
31+
table_schema = 'partman_test'
32+
order by
33+
table_name,
34+
table_type;
35+
table_name | table_type
36+
-----------------------------+------------
37+
time_taptest_table | BASE TABLE
38+
time_taptest_table_template | BASE TABLE
39+
(2 rows)
40+
41+
select public.create_parent(
42+
p_parent_table := 'partman_test.time_taptest_table',
43+
p_control := 'col3',
44+
p_interval := '1 day',
45+
p_template_table := 'partman_test.time_taptest_table_template'
46+
);
47+
create_parent
48+
---------------
49+
t
50+
(1 row)
51+
52+
/*
53+
Review tables in the partman_test schema, which should now include daily partitions
54+
*/
55+
select
56+
-- dates in partition names are variable, so reduced to the prefix
57+
substring(table_name, 1, 21) as table_prefix,
58+
table_type
59+
from
60+
information_schema.tables
61+
where
62+
table_schema = 'partman_test'
63+
order by
64+
table_name;
65+
table_prefix | table_type
66+
-----------------------+------------
67+
time_taptest_table | BASE TABLE
68+
time_taptest_table_de | BASE TABLE
69+
time_taptest_table_p2 | BASE TABLE
70+
time_taptest_table_p2 | BASE TABLE
71+
time_taptest_table_p2 | BASE TABLE
72+
time_taptest_table_p2 | BASE TABLE
73+
time_taptest_table_p2 | BASE TABLE
74+
time_taptest_table_p2 | BASE TABLE
75+
time_taptest_table_p2 | BASE TABLE
76+
time_taptest_table_p2 | BASE TABLE
77+
time_taptest_table_p2 | BASE TABLE
78+
time_taptest_table_te | BASE TABLE
79+
(12 rows)
80+
81+
/*
82+
Confirm maintenance proc runs without issue
83+
*/
84+
call public.run_maintenance_proc();
85+
/*
86+
Make sure the background worker is NOT enabled.
87+
This is intentional. We document using pg_cron to schedule calls to
88+
public.run_maintenance_proc(). That is consistent with other providers.
89+
*/
90+
select
91+
application_name
92+
from
93+
pg_stat_activity
94+
where
95+
application_name = 'pg_partman_bgw';
96+
application_name
97+
------------------
98+
(0 rows)
99+
100+
-- Cleanup
101+
drop schema partman_test cascade;
102+
NOTICE: drop cascades to 2 other objects
103+
DETAIL: drop cascades to table partman_test.time_taptest_table
104+
drop cascades to table partman_test.time_taptest_table_template

nix/tests/expected/pgmq.out

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
msg_id,
24+
read_ct,
25+
message
26+
from
27+
pgmq.send(
28+
queue_name:='foo', -- note: lowercase useage
29+
msg:='{"foo": "bar2"}',
30+
delay:=5
31+
);
32+
ERROR: column "msg_id" does not exist
33+
LINE 2: msg_id,
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+
f
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+
select
115+
pgmq.create_partitioned(
116+
'my_partitioned_queue',
117+
'5 seconds',
118+
'10 seconds'
119+
);
120+
create_partitioned
121+
--------------------
122+
123+
(1 row)
124+
125+
-- Make sure SQLI enabling characters are blocked
126+
select pgmq.create('F--oo');
127+
ERROR: queue name contains invalid characters: $, ;, --, or \'
128+
CONTEXT: PL/pgSQL function pgmq.format_table_name(text,text) line 5 at RAISE
129+
PL/pgSQL function pgmq.create_non_partitioned(text) line 3 during statement block local variable initialization
130+
SQL statement "SELECT pgmq.create_non_partitioned(queue_name)"
131+
PL/pgSQL function pgmq."create"(text) line 3 at PERFORM
132+
select pgmq.create('F$oo');
133+
ERROR: queue name contains invalid characters: $, ;, --, or \'
134+
CONTEXT: PL/pgSQL function pgmq.format_table_name(text,text) line 5 at RAISE
135+
PL/pgSQL function pgmq.create_non_partitioned(text) line 3 during statement block local variable initialization
136+
SQL statement "SELECT pgmq.create_non_partitioned(queue_name)"
137+
PL/pgSQL function pgmq."create"(text) line 3 at PERFORM
138+
select pgmq.create($$F'oo$$);
139+
ERROR: queue name contains invalid characters: $, ;, --, or \'
140+
CONTEXT: PL/pgSQL function pgmq.format_table_name(text,text) line 5 at RAISE
141+
PL/pgSQL function pgmq.create_non_partitioned(text) line 3 during statement block local variable initialization
142+
SQL statement "SELECT pgmq.create_non_partitioned(queue_name)"
143+
PL/pgSQL function pgmq."create"(text) line 3 at PERFORM

nix/tests/prime.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ create extension pg_graphql;
4343
create extension pg_freespacemap;
4444
create extension pg_hashids;
4545
create extension pg_prewarm;
46-
-- create extension pg_partman;
46+
create extension pg_partman;
4747
create extension pg_jsonschema;
4848
create extension pg_repack;
4949
create extension pg_stat_monitor;
@@ -55,7 +55,7 @@ create extension pg_visibility;
5555
create extension pg_walinspect;
5656
create extension pgaudit;
5757
create extension pgcrypto;
58-
-- create extension pgmq;
58+
create extension pgmq;
5959
create extension pgtap;
6060
create extension pgjwt;
6161
create extension pgroonga;

nix/tests/sql/pg_partman.sql

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
create schema if not exists partman_test;
2+
3+
/*
4+
Simple Time Based: 1 Partition Per Day
5+
6+
For native partitioning, you must start with a parent table that has already been set up to be partitioned in the desired type. Currently pg_partman only supports the RANGE type of partitioning (both for time & id). You cannot turn a non-partitioned table into the parent table of a partitioned set, which can make migration a challenge. This document will show you some techniques for how to manage this later. For now, we will start with a brand new table in this example. Any non-unique indexes can also be added to the parent table in PG11+ and they will automatically be created on all child tables.
7+
*/
8+
9+
create table partman_test.time_taptest_table(
10+
col1 int,
11+
col2 text default 'stuff',
12+
col3 timestamptz not null default now()
13+
)
14+
partition by range (col3);
15+
16+
create index on partman_test.time_tap (col3);
17+
18+
/*
19+
Unique indexes (including primary keys) cannot be created on a natively partitioned parent unless they include the partition key. For time-based partitioning that generally doesn't work out since that would limit only a single timestamp value in each child table. pg_partman helps to manage this by using a template table to manage properties that currently are not supported by native partitioning. Note that this does not solve the issue of the constraint not being enforced across the entire partition set. See the main documentation to see which properties are managed by the template.
20+
21+
Manually create the template table first so that when we run create_parent() the initial child tables that are created will have a primary key. If you do not supply a template table to pg_partman, it will create one for you in the schema that you installed the extension to. However properties you add to that template are only then applied to newly created child tables after that point. You will have to retroactively apply those properties manually to any child tables that already existed.
22+
*/
23+
24+
create table partman_test.time_taptest_table_template (like partman_test.time_taptest_table);
25+
26+
alter table partman_test.time_taptest_table_template add primary key (col1);
27+
28+
/*
29+
Review tables in the partman_test schema
30+
*/
31+
32+
select
33+
table_name,
34+
table_type
35+
from
36+
information_schema.tables
37+
where
38+
table_schema = 'partman_test'
39+
order by
40+
table_name,
41+
table_type;
42+
43+
44+
select public.create_parent(
45+
p_parent_table := 'partman_test.time_taptest_table',
46+
p_control := 'col3',
47+
p_interval := '1 day',
48+
p_template_table := 'partman_test.time_taptest_table_template'
49+
);
50+
51+
/*
52+
Review tables in the partman_test schema, which should now include daily partitions
53+
*/
54+
55+
select
56+
-- dates in partition names are variable, so reduced to the prefix
57+
substring(table_name, 1, 21) as table_prefix,
58+
table_type
59+
from
60+
information_schema.tables
61+
where
62+
table_schema = 'partman_test'
63+
order by
64+
table_name;
65+
66+
67+
/*
68+
Confirm maintenance proc runs without issue
69+
*/
70+
call public.run_maintenance_proc();
71+
72+
/*
73+
Make sure the background worker is NOT enabled.
74+
This is intentional. We document using pg_cron to schedule calls to
75+
public.run_maintenance_proc(). That is consistent with other providers.
76+
*/
77+
select
78+
application_name
79+
from
80+
pg_stat_activity
81+
where
82+
application_name = 'pg_partman_bgw';
83+
84+
-- Cleanup
85+
drop schema partman_test cascade;

0 commit comments

Comments
 (0)