-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tde keys and keyring when chaging tablespace
When a relation moved to a new location it causes the change of relfilenode id for it. Hence we must re-encrypt and store its internal key with the new id. Also, we have to store the changed internal key in the new physical location, and copy there principal key info and keyring data. Fixes https://perconadev.atlassian.net/browse/PG-1038
- Loading branch information
Showing
17 changed files
with
271 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
// TODO | ||
\set tde_am tde_heap | ||
\i sql/tablespace.inc | ||
CREATE EXTENSION pg_tde; | ||
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per'); | ||
pg_tde_add_key_provider_file | ||
------------------------------ | ||
1 | ||
(1 row) | ||
|
||
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault'); | ||
pg_tde_set_principal_key | ||
-------------------------- | ||
t | ||
(1 row) | ||
|
||
CREATE TABLE test(num1 bigint, num2 double precision, t text) USING :tde_am; | ||
INSERT INTO test(num1, num2, t) | ||
SELECT round(random()*100), random(), 'text' | ||
FROM generate_series(1, 10) s(i); | ||
CREATE INDEX test_idx ON test(num1); | ||
SET allow_in_place_tablespaces = true; | ||
CREATE TABLESPACE test_tblspace LOCATION ''; | ||
ALTER TABLE test SET TABLESPACE test_tblspace; | ||
SELECT count(*) FROM test; | ||
count | ||
------- | ||
10 | ||
(1 row) | ||
|
||
ALTER TABLE test SET TABLESPACE pg_default; | ||
REINDEX (TABLESPACE test_tblspace, CONCURRENTLY) TABLE test; | ||
INSERT INTO test VALUES (110, 2); | ||
SELECT * FROM test WHERE num1=110; | ||
num1 | num2 | t | ||
------+------+--- | ||
110 | 2 | | ||
(1 row) | ||
|
||
DROP TABLE test; | ||
DROP TABLESPACE test_tblspace; | ||
DROP EXTENSION pg_tde; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
\set tde_am tde_heap_basic | ||
\i sql/tablespace.inc | ||
CREATE EXTENSION pg_tde; | ||
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per'); | ||
pg_tde_add_key_provider_file | ||
------------------------------ | ||
1 | ||
(1 row) | ||
|
||
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault'); | ||
pg_tde_set_principal_key | ||
-------------------------- | ||
t | ||
(1 row) | ||
|
||
CREATE TABLE test(num1 bigint, num2 double precision, t text) USING :tde_am; | ||
INSERT INTO test(num1, num2, t) | ||
SELECT round(random()*100), random(), 'text' | ||
FROM generate_series(1, 10) s(i); | ||
CREATE INDEX test_idx ON test(num1); | ||
SET allow_in_place_tablespaces = true; | ||
CREATE TABLESPACE test_tblspace LOCATION ''; | ||
ALTER TABLE test SET TABLESPACE test_tblspace; | ||
SELECT count(*) FROM test; | ||
count | ||
------- | ||
10 | ||
(1 row) | ||
|
||
ALTER TABLE test SET TABLESPACE pg_default; | ||
REINDEX (TABLESPACE test_tblspace, CONCURRENTLY) TABLE test; | ||
INSERT INTO test VALUES (110, 2); | ||
SELECT * FROM test WHERE num1=110; | ||
num1 | num2 | t | ||
------+------+--- | ||
110 | 2 | | ||
(1 row) | ||
|
||
DROP TABLE test; | ||
DROP TABLESPACE test_tblspace; | ||
DROP EXTENSION pg_tde; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
CREATE EXTENSION pg_tde; | ||
|
||
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per'); | ||
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault'); | ||
|
||
CREATE TABLE test(num1 bigint, num2 double precision, t text) USING :tde_am; | ||
INSERT INTO test(num1, num2, t) | ||
SELECT round(random()*100), random(), 'text' | ||
FROM generate_series(1, 10) s(i); | ||
CREATE INDEX test_idx ON test(num1); | ||
|
||
SET allow_in_place_tablespaces = true; | ||
CREATE TABLESPACE test_tblspace LOCATION ''; | ||
|
||
ALTER TABLE test SET TABLESPACE test_tblspace; | ||
SELECT count(*) FROM test; | ||
ALTER TABLE test SET TABLESPACE pg_default; | ||
|
||
REINDEX (TABLESPACE test_tblspace, CONCURRENTLY) TABLE test; | ||
INSERT INTO test VALUES (110, 2); | ||
|
||
SELECT * FROM test WHERE num1=110; | ||
|
||
DROP TABLE test; | ||
DROP TABLESPACE test_tblspace; | ||
DROP EXTENSION pg_tde; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,2 @@ | ||
CREATE EXTENSION pg_tde; | ||
|
||
SELECT * FROM pg_tde_principal_key_info(); | ||
|
||
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per'); | ||
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault'); | ||
|
||
|
||
CREATE TABLE test(num1 bigint, num2 double precision, t text); | ||
INSERT INTO test(num1, num2, t) | ||
SELECT round(random()*100), random(), 'text' | ||
FROM generate_series(1, 10) s(i); | ||
CREATE INDEX test_idx ON test(num1); | ||
|
||
SET allow_in_place_tablespaces = true; | ||
CREATE TABLESPACE test_tblspace LOCATION ''; | ||
|
||
ALTER TABLE test SET TABLESPACE test_tblspace; | ||
ALTER TABLE test SET TABLESPACE pg_default; | ||
|
||
REINDEX (TABLESPACE test_tblspace, CONCURRENTLY) TABLE test; | ||
INSERT INTO test VALUES (10, 2); | ||
|
||
DROP TABLE test; | ||
DROP TABLESPACE test_tblspace; | ||
DROP EXTENSION pg_tde; | ||
\set tde_am tde_heap | ||
\i sql/tablespace.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
\set tde_am tde_heap_basic | ||
\i sql/tablespace.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.