Skip to content

Commit bcb9f9a

Browse files
author
Anders Åstrand
committed
fixup! PG-1504 Make partitions inherit encryption status
1 parent 758c638 commit bcb9f9a

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

contrib/pg_tde/expected/partition_table.out

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ SELECT pg_tde_is_encrypted('partition_q4_2024');
8686
t
8787
(1 row)
8888

89-
-- Partition inherits encryption status from parent table
89+
-- Partition inherits encryption status from parent table if default is heap and parent is tde_heap
90+
SET default_table_access_method = "heap";
9091
CREATE TABLE partition_inherit_parent (a int) PARTITION BY RANGE (a) USING tde_heap;
9192
CREATE TABLE partition_inherit_child PARTITION OF partition_inherit_parent FOR VALUES FROM (0) TO (10);
9293
SELECT pg_tde_is_encrypted('partition_inherit_child');
@@ -96,5 +97,18 @@ SELECT pg_tde_is_encrypted('partition_inherit_child');
9697
(1 row)
9798

9899
DROP TABLE partition_inherit_parent;
100+
RESET default_table_access_method;
101+
-- Partition inherits encryption status from parent table if default is tde_heap and parent is heap
102+
SET default_table_access_method = "tde_heap";
103+
CREATE TABLE partition_inherit_parent (a int) PARTITION BY RANGE (a) USING heap;
104+
CREATE TABLE partition_inherit_child PARTITION OF partition_inherit_parent FOR VALUES FROM (0) TO (10);
105+
SELECT pg_tde_is_encrypted('partition_inherit_child');
106+
pg_tde_is_encrypted
107+
---------------------
108+
f
109+
(1 row)
110+
111+
DROP TABLE partition_inherit_parent;
112+
RESET default_table_access_method;
99113
DROP TABLE partitioned_table;
100114
DROP EXTENSION pg_tde;

contrib/pg_tde/sql/partition_table.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@ SELECT pg_tde_is_encrypted('partition_q2_2024');
3131
SELECT pg_tde_is_encrypted('partition_q3_2024');
3232
SELECT pg_tde_is_encrypted('partition_q4_2024');
3333

34-
-- Partition inherits encryption status from parent table
34+
-- Partition inherits encryption status from parent table if default is heap and parent is tde_heap
35+
SET default_table_access_method = "heap";
3536
CREATE TABLE partition_inherit_parent (a int) PARTITION BY RANGE (a) USING tde_heap;
3637
CREATE TABLE partition_inherit_child PARTITION OF partition_inherit_parent FOR VALUES FROM (0) TO (10);
3738
SELECT pg_tde_is_encrypted('partition_inherit_child');
3839
DROP TABLE partition_inherit_parent;
40+
RESET default_table_access_method;
41+
42+
-- Partition inherits encryption status from parent table if default is tde_heap and parent is heap
43+
SET default_table_access_method = "tde_heap";
44+
CREATE TABLE partition_inherit_parent (a int) PARTITION BY RANGE (a) USING heap;
45+
CREATE TABLE partition_inherit_child PARTITION OF partition_inherit_parent FOR VALUES FROM (0) TO (10);
46+
SELECT pg_tde_is_encrypted('partition_inherit_child');
47+
DROP TABLE partition_inherit_parent;
48+
RESET default_table_access_method;
3949

4050
DROP TABLE partitioned_table;
4151
DROP EXTENSION pg_tde;

contrib/pg_tde/src/pg_tde_event_capture.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,17 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
155155
validateCurrentEventTriggerState(true);
156156
tdeCurrentCreateEvent.tid = GetCurrentFullTransactionId();
157157

158-
if (shouldEncryptTable(stmt->accessMethod))
158+
159+
if (stmt->accessMethod && strcmp(stmt->accessMethod, "tde_heap") == 0)
159160
{
161+
/* If access method is explicitly set to tde_heap, always encrypt. */
160162
tdeCurrentCreateEvent.encryptMode = true;
161163
}
162164
else if (!stmt->accessMethod && stmt->partbound)
163165
{
164-
165166
/*
166-
* If this is a partition of a parent table, and no access method
167-
* is specified, access method will be inherited and we need to
167+
* If no access method is specified, and this is a partition of a
168+
* parent table, access method will be inherited and we need to
168169
* deal with setting the encryption status properly.
169170
*
170171
* AccessExclusiveLock might seem excessive, but it's what
@@ -184,6 +185,15 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
184185
tdeCurrentCreateEvent.encryptMode = true;
185186
}
186187
}
188+
else if (!stmt->accessMethod && strcmp(default_table_access_method, "tde_heap") == 0)
189+
{
190+
/*
191+
* If no access method is specified, and this is not a partition
192+
* of a parent table, refer to the default access method to set
193+
* encryption status.
194+
*/
195+
tdeCurrentCreateEvent.encryptMode = true;
196+
}
187197

188198
checkEncryptionStatus();
189199
}

0 commit comments

Comments
 (0)