@@ -1097,3 +1097,82 @@ select count(*) from :chunk;
1097
1097
(1 row)
1098
1098
1099
1099
\set ON_ERROR_STOP 1
1100
+ set timescaledb.enable_transparent_decompression=true;
1101
+ -- Test chunk creation with non-owner user
1102
+ CREATE TABLE conditions ( -- create a regular table
1103
+ time timestamptz not null,
1104
+ location text not null,
1105
+ temperature double precision null
1106
+ );
1107
+ select create_hypertable('conditions', 'time'); -- turn it into a hypertable
1108
+ create_hypertable
1109
+ --------------------------
1110
+ (12,public,conditions,t)
1111
+ (1 row)
1112
+
1113
+ -------------------------------------------------------------------------------
1114
+ -- Create a new user and grant privileges to work on conditions
1115
+ -------------------------------------------------------------------------------
1116
+ create role testuser;
1117
+ -- Grant ability to switch to testuser
1118
+ grant testuser to :ROLE_DEFAULT_PERM_USER;
1119
+ grant select,insert,update,delete on conditions to testuser;
1120
+ alter table conditions set (
1121
+ timescaledb.compress,
1122
+ timescaledb.compress_segmentby = 'location,temperature',
1123
+ timescaledb.compress_orderby = 'time'
1124
+ );
1125
+ -------------------------------------------------------------------------------
1126
+ -- Set hypercore access method on the hypertable
1127
+ -------------------------------------------------------------------------------
1128
+ alter table conditions set access method hypercore;
1129
+ -- Switch to testuser and make sure it can insert into conditions
1130
+ set role testuser;
1131
+ select current_user;
1132
+ current_user
1133
+ --------------
1134
+ testuser
1135
+ (1 row)
1136
+
1137
+ select * from show_chunks('conditions') ch
1138
+ join _timescaledb_catalog.compression_settings cs on (cs.relid = ch);
1139
+ ch | relid | compress_relid | segmentby | orderby | orderby_desc | orderby_nullsfirst
1140
+ ----+-------+----------------+-----------+---------+--------------+--------------------
1141
+ (0 rows)
1142
+
1143
+ -- An insert should create a new hypercore chunk, including the compressed chunk
1144
+ insert into conditions values ('2024-01-02', 'school', 99.5);
1145
+ select chunk, amname, cs.compress_relid
1146
+ from show_chunks('conditions') as chunk
1147
+ join pg_class on (pg_class.oid = chunk)
1148
+ join pg_am on (relam = pg_am.oid)
1149
+ join _timescaledb_catalog.compression_settings cs on (cs.relid = chunk);
1150
+ chunk | amname | compress_relid
1151
+ ------------------------------------------+-----------+--------------------------------------------------
1152
+ _timescaledb_internal._hyper_12_49_chunk | hypercore | _timescaledb_internal.compress_hyper_13_50_chunk
1153
+ (1 row)
1154
+
1155
+ -- Data is not compressed
1156
+ select _timescaledb_debug.is_compressed_tid(ctid), * from conditions;
1157
+ is_compressed_tid | time | location | temperature
1158
+ -------------------+------------------------------+----------+-------------
1159
+ f | Tue Jan 02 00:00:00 2024 PST | school | 99.5
1160
+ (1 row)
1161
+
1162
+ select compress_chunk(ch) from show_chunks('conditions') ch;
1163
+ compress_chunk
1164
+ ------------------------------------------
1165
+ _timescaledb_internal._hyper_12_49_chunk
1166
+ (1 row)
1167
+
1168
+ -- Now the data is compressed
1169
+ select _timescaledb_debug.is_compressed_tid(ctid), * from conditions;
1170
+ is_compressed_tid | time | location | temperature
1171
+ -------------------+------------------------------+----------+-------------
1172
+ t | Tue Jan 02 00:00:00 2024 PST | school | 99.5
1173
+ (1 row)
1174
+
1175
+ reset role;
1176
+ -- Need to revoke privileges to drop user
1177
+ revoke all on conditions from testuser;
1178
+ drop role testuser;
0 commit comments