Fix trigger for ALTER TABLE SET ACCESS METHOD DEFAULT (#321)

1. `cmd->name` is empty (NULL) in the case of `ACCESS METHOD DEFAULT`,
so we should check for NULL before cmp.

2. Make trigger aware of the case when default AM is `tde_heap`

Fixes PG-1106
pull/209/head
Andrew Pogrebnoi 11 months ago committed by GitHub
parent a799c51f18
commit 59960a3712
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      src/pg_tde_event_capture.c
  2. 28
      t/008_tde_heap.pl
  3. 7
      t/expected/008_tde_heap.out

@ -137,11 +137,14 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
AlterTableStmt *stmt = (AlterTableStmt *) parsetree;
ListCell *lcmd;
/* TODO: it might make sense to cehck rd_rel->relkind */
foreach(lcmd, stmt->cmds)
{
{
AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
if(cmd->subtype == AT_SetAccessMethod && strcmp(cmd->name, "tde_heap")==0) {
if (cmd->subtype == AT_SetAccessMethod &&
(cmd->name != NULL && strcmp(cmd->name, "tde_heap")==0) ||
(cmd->name == NULL && strcmp(default_table_access_method, "tde_heap") == 0)
)
{
tdeCurrentCreateEvent.encryptMode = true;
tdeCurrentCreateEvent.eventType = TDE_TABLE_CREATE_EVENT;
tdeCurrentCreateEvent.relation = stmt->relation;

@ -85,6 +85,15 @@ PGTDE::append_to_file($stdout);
$stdout = $node->safe_psql('postgres', 'SELECT * FROM test_enc3 ORDER BY id ASC;', extra_params => ['-a']);
PGTDE::append_to_file($stdout);
$stdout = $node->safe_psql('postgres', 'CREATE TABLE test_enc4(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING heap;', extra_params => ['-a']);
PGTDE::append_to_file($stdout);
$stdout = $node->safe_psql('postgres', 'INSERT INTO test_enc4 (k) VALUES (\'foobar\'),(\'barfoo\');', extra_params => ['-a']);
PGTDE::append_to_file($stdout);
$stdout = $node->safe_psql('postgres', 'SET default_table_access_method = "tde_heap"; ALTER TABLE test_enc4 SET ACCESS METHOD DEFAULT;', extra_params => ['-a']);
PGTDE::append_to_file($stdout);
# Restart the server
PGTDE::append_to_file("-- server restart");
$rt_value = $node->stop();
@ -140,6 +149,22 @@ PGTDE::append_to_file($strings);
# Verify that we can't see the data in the file
my $tablefile4 = $node->safe_psql('postgres', 'SHOW data_directory;');
$tablefile4 .= '/';
$tablefile4 .= $node->safe_psql('postgres', 'SELECT pg_relation_filepath(\'test_enc4\');');
$strings = 'TABLEFILE4 FOUND: ';
$strings .= `(ls $tablefile4 >/dev/null && echo yes) || echo no`;
PGTDE::append_to_file($strings);
$strings = 'CONTAINS FOO (should be empty): ';
$strings .= `strings $tablefile4 | grep foo`;
PGTDE::append_to_file($strings);
$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc;', extra_params => ['-a']);
PGTDE::append_to_file($stdout);
@ -149,6 +174,9 @@ PGTDE::append_to_file($stdout);
$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc3;', extra_params => ['-a']);
PGTDE::append_to_file($stdout);
$stdout = $node->safe_psql('postgres', 'DROP TABLE test_enc4;', extra_params => ['-a']);
PGTDE::append_to_file($stdout);
# DROP EXTENSION
$stdout = $node->safe_psql('postgres', 'DROP EXTENSION pg_tde;', extra_params => ['-a']);
ok($cmdret == 0, "DROP PGTDE EXTENSION");

@ -17,6 +17,9 @@ INSERT INTO test_enc3 (k) VALUES ('foobar'),('barfoo');
SELECT * FROM test_enc3 ORDER BY id ASC;
1|foobar
2|barfoo
CREATE TABLE test_enc4(id SERIAL,k VARCHAR(32),PRIMARY KEY (id)) USING heap;
INSERT INTO test_enc4 (k) VALUES ('foobar'),('barfoo');
SET default_table_access_method = "tde_heap"; ALTER TABLE test_enc4 SET ACCESS METHOD DEFAULT;
-- server restart
SELECT * FROM test_enc ORDER BY id ASC;
1|foobar
@ -29,8 +32,12 @@ TABLEFILE2 FOUND: yes
CONTAINS FOO (should be empty):
TABLEFILE3 FOUND: yes
CONTAINS FOO (should be empty):
TABLEFILE4 FOUND: yes
CONTAINS FOO (should be empty):
DROP TABLE test_enc;
DROP TABLE test_enc2;
DROP TABLE test_enc3;
DROP TABLE test_enc4;
DROP EXTENSION pg_tde;

Loading…
Cancel
Save