Skip to content

Commit 950c49e

Browse files
authored
Merge branch '2.27.x' into release/2.27.1-changelog
2 parents e99021f + 0240f10 commit 950c49e

12 files changed

Lines changed: 56 additions & 5 deletions

.unreleased/pr_9795

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #9795 Delete orphaned compression_settings before migrating catalog table

.unreleased/pr_9800

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #9800 Check hypertable ownership before recompression

.unreleased/pr_9801

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #9801 Fix information leak in policy_reorder_remove

sql/updates/2.18.2--2.19.0.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ INSERT INTO _timescaledb_catalog.compression_algorithm( id, version, name, descr
88
( 6, 1, 'COMPRESSION_ALGORITHM_NULL', 'null')
99
;
1010

11+
-- clean up orphaned compression settings
12+
DELETE FROM _timescaledb_catalog.compression_settings cs
13+
WHERE
14+
NOT EXISTS (SELECT FROM _timescaledb_catalog.hypertable h WHERE format('%I.%I', h.schema_name, h.table_name)::regclass = cs.relid)
15+
AND NOT EXISTS (
16+
SELECT FROM _timescaledb_catalog.chunk cch
17+
JOIN _timescaledb_catalog.chunk ch ON ch.compressed_chunk_id = cch.id
18+
WHERE NOT ch.dropped AND NOT cch.dropped AND format('%I.%I', cch.schema_name, cch.table_name)::regclass = cs.relid
19+
);
20+
1121
-------------------------------
1222
-- Update compression settings
1323
-------------------------------
@@ -95,4 +105,4 @@ CREATE FUNCTION @extschema@.add_continuous_aggregate_policy(
95105
)
96106
RETURNS INTEGER
97107
AS '@MODULE_PATHNAME@', 'ts_update_placeholder'
98-
LANGUAGE C VOLATILE;
108+
LANGUAGE C VOLATILE;

tsl/src/bgw_policy/reorder_api.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,14 @@ policy_reorder_remove(PG_FUNCTION_ARGS)
310310
TS_PREVENT_FUNC_IF_READ_ONLY();
311311

312312
ht = ts_hypertable_cache_get_cache_and_entry(hypertable_oid, CACHE_FLAG_NONE, &hcache);
313+
int32 ht_id = ht->fd.id;
314+
ts_cache_release(&hcache);
315+
316+
ts_hypertable_permissions_check(hypertable_oid, GetUserId());
313317

314318
List *jobs = ts_bgw_job_find_by_proc_and_hypertable_id(POLICY_REORDER_PROC_NAME,
315319
FUNCTIONS_SCHEMA_NAME,
316-
ht->fd.id);
317-
ts_cache_release(&hcache);
320+
ht_id);
318321

319322
if (jobs == NIL)
320323
{
@@ -336,8 +339,6 @@ policy_reorder_remove(PG_FUNCTION_ARGS)
336339
Assert(list_length(jobs) == 1);
337340
BgwJob *job = linitial(jobs);
338341

339-
ts_hypertable_permissions_check(hypertable_oid, GetUserId());
340-
341342
ts_bgw_job_delete_by_id(job->fd.id);
342343

343344
PG_RETURN_NULL();

tsl/src/compression/api.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ tsl_compress_chunk(PG_FUNCTION_ARGS)
886886

887887
TS_PREVENT_FUNC_IF_READ_ONLY();
888888
Chunk *chunk = ts_chunk_get_by_relid(uncompressed_chunk_id, true);
889+
ts_hypertable_permissions_check(chunk->hypertable_relid, GetUserId());
889890

890891
uncompressed_chunk_id = tsl_compress_chunk_wrapper(chunk, if_not_compressed, recompress);
891892

@@ -1029,6 +1030,7 @@ tsl_rebuild_columnstore(PG_FUNCTION_ARGS)
10291030
}
10301031

10311032
Chunk *chunk = ts_chunk_get_by_relid(chunk_relid, true);
1033+
ts_hypertable_permissions_check(chunk->hypertable_relid, GetUserId());
10321034

10331035
if (!ts_chunk_is_compressed(chunk) || ts_chunk_is_frozen(chunk))
10341036
{

tsl/src/compression/recompress.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <postgres.h>
88
#include "debug_point.h"
9+
#include <miscadmin.h>
910
#include <parser/parse_coerce.h>
1011
#include <parser/parse_relation.h>
1112
#include <utils/inval.h>
@@ -22,6 +23,7 @@
2223
#include "create.h"
2324
#include "debug_assert.h"
2425
#include "guc.h"
26+
#include "hypertable.h"
2527
#include "indexing.h"
2628
#include "recompress.h"
2729
#include "ts_catalog/array_utils.h"
@@ -82,6 +84,7 @@ tsl_recompress_chunk_segmentwise(PG_FUNCTION_ARGS)
8284
ts_feature_flag_check(FEATURE_HYPERTABLE_COMPRESSION);
8385
TS_PREVENT_FUNC_IF_READ_ONLY();
8486
Chunk *chunk = ts_chunk_get_by_relid(uncompressed_chunk_id, true);
87+
ts_hypertable_permissions_check(chunk->hypertable_relid, GetUserId());
8588

8689
if (!ts_chunk_is_partial(chunk))
8790
{

tsl/test/expected/compression_permissions-15.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ ERROR: must be owner of table conditions
5959
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER_2
6060
SELECT compress_chunk(show_chunks('conditions'));
6161
ERROR: must be owner of hypertable "conditions"
62+
SELECT compress_chunk(show_chunks('conditions'), recompress => true);
63+
ERROR: must be owner of hypertable "conditions"
6264
SELECT decompress_chunk(show_chunks('conditions'));
6365
ERROR: must be owner of hypertable "conditions"
66+
SELECT show_chunks('conditions') AS chunk LIMIT 1 \gset
67+
CALL _timescaledb_functions.rebuild_columnstore(:'chunk'::regclass);
68+
ERROR: must be owner of hypertable "conditions"
69+
SELECT _timescaledb_functions.recompress_chunk_segmentwise(show_chunks('conditions'));
70+
ERROR: must be owner of hypertable "conditions"
6471
select add_compression_policy('conditions', '1day'::interval);
6572
ERROR: must be owner of hypertable "conditions"
6673
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER

tsl/test/expected/compression_permissions-16.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ ERROR: must be owner of table conditions
5959
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER_2
6060
SELECT compress_chunk(show_chunks('conditions'));
6161
ERROR: must be owner of hypertable "conditions"
62+
SELECT compress_chunk(show_chunks('conditions'), recompress => true);
63+
ERROR: must be owner of hypertable "conditions"
6264
SELECT decompress_chunk(show_chunks('conditions'));
6365
ERROR: must be owner of hypertable "conditions"
66+
SELECT show_chunks('conditions') AS chunk LIMIT 1 \gset
67+
CALL _timescaledb_functions.rebuild_columnstore(:'chunk'::regclass);
68+
ERROR: must be owner of hypertable "conditions"
69+
SELECT _timescaledb_functions.recompress_chunk_segmentwise(show_chunks('conditions'));
70+
ERROR: must be owner of hypertable "conditions"
6471
select add_compression_policy('conditions', '1day'::interval);
6572
ERROR: must be owner of hypertable "conditions"
6673
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER

tsl/test/expected/compression_permissions-17.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ ERROR: must be owner of table conditions
5959
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER_2
6060
SELECT compress_chunk(show_chunks('conditions'));
6161
ERROR: must be owner of hypertable "conditions"
62+
SELECT compress_chunk(show_chunks('conditions'), recompress => true);
63+
ERROR: must be owner of hypertable "conditions"
6264
SELECT decompress_chunk(show_chunks('conditions'));
6365
ERROR: must be owner of hypertable "conditions"
66+
SELECT show_chunks('conditions') AS chunk LIMIT 1 \gset
67+
CALL _timescaledb_functions.rebuild_columnstore(:'chunk'::regclass);
68+
ERROR: must be owner of hypertable "conditions"
69+
SELECT _timescaledb_functions.recompress_chunk_segmentwise(show_chunks('conditions'));
70+
ERROR: must be owner of hypertable "conditions"
6471
select add_compression_policy('conditions', '1day'::interval);
6572
ERROR: must be owner of hypertable "conditions"
6673
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER

0 commit comments

Comments
 (0)