Skip to content

Commit

Permalink
Fix pg_init_privs objsubid handling
Browse files Browse the repository at this point in the history
pg_init_privs can have multiple entries per relation if the relation
has per column privileges. An objsubid different from 0 means that
the entry is for a column privilege. Since we do not currently
restore column privileges we have to ignore those rows otherwise
the update script will fail when tables with column privileges are
present.
  • Loading branch information
svenklemm committed Jun 15, 2021
1 parent e5837a5 commit 02012b4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions sql/updates/post-update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ ON CONFLICT DO NOTHING;
WITH to_update AS (
SELECT objoid, tmpini
FROM pg_class cl JOIN pg_namespace ns ON ns.oid = relnamespace
JOIN pg_init_privs ip ON ip.objoid = cl.oid
JOIN pg_init_privs ip ON ip.objoid = cl.oid AND ip.objsubid = 0
JOIN saved_privs ON tmpnsp = nspname AND tmpname = relname)
UPDATE pg_init_privs
SET initprivs = tmpini
FROM to_update
WHERE to_update.objoid = pg_init_privs.objoid
AND classoid = 'pg_class'::regclass;
AND classoid = 'pg_class'::regclass
AND objsubid = 0;

-- Can only restore permissions on views after they have been rebuilt,
-- so we restore for all types of objects here.
Expand Down
2 changes: 1 addition & 1 deletion sql/updates/pre-update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CREATE TABLE saved_privs(
INSERT INTO saved_privs
SELECT nspname, relname, relacl, initprivs
FROM pg_class cl JOIN pg_namespace ns ON ns.oid = relnamespace
JOIN pg_init_privs ip ON ip.objoid = cl.oid
JOIN pg_init_privs ip ON ip.objoid = cl.oid AND ip.objsubid = 0
WHERE nspname IN ('_timescaledb_catalog', '_timescaledb_config')
OR nspname = '_timescaledb_internal'
AND relname IN ('hypertable_chunk_local_size', 'compressed_chunk_stats',
Expand Down
2 changes: 1 addition & 1 deletion test/sql/updates/post.catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SELECT nspname AS schema,
relname AS name,
unnest(initprivs)::text AS initpriv
FROM pg_class cl JOIN pg_namespace ns ON ns.oid = relnamespace
LEFT JOIN pg_init_privs ON objoid = cl.oid
LEFT JOIN pg_init_privs ON objoid = cl.oid AND objsubid = 0
WHERE classoid = 'pg_class'::regclass
AND nspname IN ('_timescaledb_catalog', '_timescaledb_config')
ORDER BY schema, name, initpriv;
Expand Down

0 comments on commit 02012b4

Please sign in to comment.