Skip to content

Commit

Permalink
Merge pull request #261 from dutow/amrename
Browse files Browse the repository at this point in the history
Renaming access methods
  • Loading branch information
dutow authored Aug 21, 2024
2 parents a5bef05 + bf936b0 commit 4fb220c
Show file tree
Hide file tree
Showing 45 changed files with 137 additions and 72 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ FUNCTION pg_tde_set_principal_key (
SELECT pg_tde_set_principal_key('my-principal-key','file');
```

7. You are all set to create encrypted tables. For that, specify `USING pg_tde_basic` access method in the `CREATE TABLE` statement.
7. You are all set to create encrypted tables. For that, specify `USING tde_heap_basic` access method in the `CREATE TABLE` statement.
**For example**:
```sql
CREATE TABLE albums (
album_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
artist_id INTEGER,
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde_basic;
) USING tde_heap_basic;
```

## Build from source
Expand Down Expand Up @@ -166,7 +166,7 @@ The extension provides the following helper functions:

### pg_tde_is_encrypted(tablename)

Returns `t` if the table is encrypted (uses the pg_tde_basic access method), or `f` otherwise.
Returns `t` if the table is encrypted (uses the tde_heap_basic access method), or `f` otherwise.

## Base commit

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/release-notes/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Beta (2024-06-30)

With this version, the access method for `pg_tde` extension is renamed `pg_tde_basic`. Use this access method name to create tables. Find guidelines in [Test TDE](../test.md) tutorial.
With this version, the access method for `pg_tde` extension is renamed `tde_heap_basic`. Use this access method name to create tables. Find guidelines in [Test TDE](../test.md) tutorial.

The Beta version introduces the following bug fixes and improvements:

Expand Down
8 changes: 4 additions & 4 deletions documentation/docs/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

To check if the data is encrypted, do the following:

1. Create a table in the database for which you have [enabled `pg_tde`](setup.md). Enabling `pg_tde` extension creates the table access method `pg_tde_basic`. To enable data encryption, create the table using this access method as follows:
1. Create a table in the database for which you have [enabled `pg_tde`](setup.md). Enabling `pg_tde` extension creates the table access method `tde_heap_basic`. To enable data encryption, create the table using this access method as follows:

```sql
CREATE TABLE <table_name> (<field> <datatype>) USING pg_tde_basic;
CREATE TABLE <table_name> (<field> <datatype>) USING tde_heap_basic;
```

!!! hint

You can enable data encryption by default by setting the `default_table_access_method` to `pg_tde_basic`:
You can enable data encryption by default by setting the `default_table_access_method` to `tde_heap_basic`:

```sql
SET default_table_access_method = pg_tde_basic;
SET default_table_access_method = tde_heap_basic;
```

2. Run the following function:
Expand Down
4 changes: 2 additions & 2 deletions expected/change_access_method.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
country_id serial primary key,
country_name text unique not null,
continent text not null
) using pg_tde_basic;
) using tde_heap_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
Expand Down Expand Up @@ -60,7 +60,7 @@ SELECT pg_tde_is_encrypted('country_table');
(1 row)

-- Change it back to encrypted
ALTER TABLE country_table SET access method pg_tde_basic;
ALTER TABLE country_table SET access method tde_heap_basic;
INSERT INTO country_table (country_name, continent)
VALUES ('China', 'Asia'),
('Brazil', 'South America'),
Expand Down
2 changes: 1 addition & 1 deletion expected/insert_update_delete.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE albums (
artist VARCHAR(256),
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde_basic;
) USING tde_heap_basic;
INSERT INTO albums (artist, title, released) VALUES
('Graindelavoix', 'Jisquin The Undead', '2021-06-12'),
('Graindelavoix', 'Tenebrae Responsoria - Carlo Gesualdo', '2019-08-06'),
Expand Down
2 changes: 1 addition & 1 deletion expected/move_large_tuples.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE sbtest2(
id SERIAL,
k TEXT STORAGE PLAIN,
PRIMARY KEY (id)
) USING pg_tde_basic;
) USING tde_heap_basic;
INSERT INTO sbtest2(k) VALUES(repeat('a', 2500));
INSERT INTO sbtest2(k) VALUES(repeat('b', 2500));
INSERT INTO sbtest2(k) VALUES(repeat('c', 2500));
Expand Down
4 changes: 2 additions & 2 deletions expected/multi_insert.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CREATE TABLE albums (
artist_id INTEGER,
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde_basic;
) USING tde_heap_basic;
COPY albums FROM stdin CSV HEADER;
SELECT * FROM albums;
album_id | artist_id | title | released
Expand Down Expand Up @@ -69,7 +69,7 @@ CREATE TABLE Towns (
name TEXT NOT NULL,
department VARCHAR(4) NOT NULL,
UNIQUE (code, department)
) USING pg_tde_basic;
) USING tde_heap_basic;
COPY towns (id, code, article, name, department) FROM stdin;
SELECT count(*) FROM towns;
count
Expand Down
2 changes: 1 addition & 1 deletion expected/non_sorted_off_compact.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CREATE TABLE sbtest1(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde_basic;
) USING tde_heap_basic;
INSERT INTO sbtest1(k) VALUES
(1),
(2),
Expand Down
8 changes: 4 additions & 4 deletions expected/pg_tde_is_encrypted.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ CREATE TABLE test_enc(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde_basic;
) USING tde_heap_basic;
CREATE TABLE test_norm(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING heap;
SELECT amname FROM pg_class INNER JOIN pg_am ON pg_am.oid = pg_class.relam WHERE relname = 'test_enc';
amname
--------------
pg_tde_basic
amname
----------------
tde_heap_basic
(1 row)

SELECT amname FROM pg_class INNER JOIN pg_am ON pg_am.oid = pg_class.relam WHERE relname = 'test_norm';
Expand Down
6 changes: 3 additions & 3 deletions expected/test_issue_153_fix.out
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CREATE TABLE dept (
deptno NUMERIC(2) NOT NULL CONSTRAINT dept_pk PRIMARY KEY,
dname VARCHAR(14) CONSTRAINT dept_dname_uq UNIQUE,
loc VARCHAR(13)
)using pg_tde_basic;
)using tde_heap_basic;
--
-- Create the 'emp' table
--
Expand All @@ -46,7 +46,7 @@ CREATE TABLE emp (
comm NUMERIC(7,2),
deptno NUMERIC(2) CONSTRAINT emp_ref_dept_fk
REFERENCES dept(deptno)
)using pg_tde_basic;
)using tde_heap_basic;
--
-- Create the 'jobhist' table
--
Expand All @@ -65,7 +65,7 @@ CREATE TABLE jobhist (
CONSTRAINT jobhist_ref_dept_fk FOREIGN KEY (deptno)
REFERENCES dept (deptno) ON DELETE SET NULL,
CONSTRAINT jobhist_date_chk CHECK (startdate <= enddate)
)using pg_tde_basic;
)using tde_heap_basic;
--
-- Create the 'salesemp' view
--
Expand Down
2 changes: 1 addition & 1 deletion expected/toast_decrypt.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
t
(1 row)

CREATE TABLE src (f1 TEXT STORAGE EXTERNAL) USING pg_tde_basic;
CREATE TABLE src (f1 TEXT STORAGE EXTERNAL) USING tde_heap_basic;
INSERT INTO src VALUES(repeat('abcdeF',1000));
SELECT * FROM src;
f1
Expand Down
6 changes: 3 additions & 3 deletions expected/toast_extended_storage.out

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions expected/trigger_on_view.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
--
-- 2 -- Test triggers on a join view
--
SET default_table_access_method TO 'pg_tde_basic';
SET default_table_access_method TO 'tde_heap_basic';
DROP VIEW IF EXISTS city_view CASCADE;
NOTICE: view "city_view" does not exist, skipping
DROP TABLE IF exists country_table CASCADE;
Expand All @@ -25,7 +25,7 @@ NOTICE: table "city_table" does not exist, skipping
country_id serial primary key,
country_name text unique not null,
continent text not null
) using pg_tde_basic;
) using tde_heap_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
Expand All @@ -45,7 +45,7 @@ NOTICE: table "city_table" does not exist, skipping
city_name text not null,
population bigint,
country_id int references country_table
) using pg_tde_basic;
) using tde_heap_basic;

CREATE VIEW city_view AS
SELECT city_id, city_name, population, country_name, continent
Expand Down
2 changes: 1 addition & 1 deletion expected/update_compare_indexes.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');

DROP TABLE IF EXISTS pvactst;
NOTICE: table "pvactst" does not exist, skipping
CREATE TABLE pvactst (i INT, a INT[], p POINT) USING pg_tde_basic;
CREATE TABLE pvactst (i INT, a INT[], p POINT) USING tde_heap_basic;
INSERT INTO pvactst SELECT i, array[1,2,3], point(i, i+1) FROM generate_series(1,1000) i;
CREATE INDEX spgist_pvactst ON pvactst USING spgist (p);
UPDATE pvactst SET i = i WHERE i < 1000;
Expand Down
2 changes: 1 addition & 1 deletion expected/vault_v2_test.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE test_enc(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde_basic;
) USING tde_heap_basic;
INSERT INTO test_enc (k) VALUES (1);
INSERT INTO test_enc (k) VALUES (2);
INSERT INTO test_enc (k) VALUES (3);
Expand Down
10 changes: 5 additions & 5 deletions pg_tde--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ SELECT EXISTS (
SELECT 1
FROM pg_catalog.pg_class
WHERE relname = table_name
AND relam = (SELECT oid FROM pg_catalog.pg_am WHERE amname = 'pg_tde_basic')
AND relam = (SELECT oid FROM pg_catalog.pg_am WHERE amname = 'tde_heap_basic')
)$$
LANGUAGE SQL;

Expand Down Expand Up @@ -199,8 +199,8 @@ LANGUAGE SQL;
CREATE FUNCTION pg_tde_version() RETURNS TEXT AS 'MODULE_PATHNAME' LANGUAGE C;

-- Access method
CREATE ACCESS METHOD pg_tde_basic TYPE TABLE HANDLER pg_tdeam_basic_handler;
COMMENT ON ACCESS METHOD pg_tde_basic IS 'pg_tde table access method';
CREATE ACCESS METHOD tde_heap_basic TYPE TABLE HANDLER pg_tdeam_basic_handler;
COMMENT ON ACCESS METHOD tde_heap_basic IS 'pg_tde table access method';

DO $$
BEGIN
Expand All @@ -210,8 +210,8 @@ DO $$
AS 'MODULE_PATHNAME'
LANGUAGE C;

CREATE ACCESS METHOD pg_tde TYPE TABLE HANDLER pg_tdeam_handler;
COMMENT ON ACCESS METHOD pg_tde IS 'pg_tde table access method';
CREATE ACCESS METHOD tde_heap TYPE TABLE HANDLER pg_tdeam_handler;
COMMENT ON ACCESS METHOD tde_heap IS 'tde_heap table access method';

CREATE OR REPLACE FUNCTION pg_tde_ddl_command_start_capture()
RETURNS event_trigger
Expand Down
4 changes: 2 additions & 2 deletions sql/change_access_method.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
country_id serial primary key,
country_name text unique not null,
continent text not null
) using pg_tde_basic;
) using tde_heap_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
Expand All @@ -30,7 +30,7 @@ SELECT * FROM country_table;
SELECT pg_tde_is_encrypted('country_table');

-- Change it back to encrypted
ALTER TABLE country_table SET access method pg_tde_basic;
ALTER TABLE country_table SET access method tde_heap_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('China', 'Asia'),
Expand Down
2 changes: 1 addition & 1 deletion sql/insert_update_delete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE albums (
artist VARCHAR(256),
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde_basic;
) USING tde_heap_basic;

INSERT INTO albums (artist, title, released) VALUES
('Graindelavoix', 'Jisquin The Undead', '2021-06-12'),
Expand Down
2 changes: 1 addition & 1 deletion sql/move_large_tuples.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CREATE TABLE sbtest2(
id SERIAL,
k TEXT STORAGE PLAIN,
PRIMARY KEY (id)
) USING pg_tde_basic;
) USING tde_heap_basic;

INSERT INTO sbtest2(k) VALUES(repeat('a', 2500));
INSERT INTO sbtest2(k) VALUES(repeat('b', 2500));
Expand Down
4 changes: 2 additions & 2 deletions sql/multi_insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE albums (
artist_id INTEGER,
title TEXT NOT NULL,
released DATE NOT NULL
) USING pg_tde_basic;
) USING tde_heap_basic;

COPY albums FROM stdin CSV HEADER;
album_id,artist_id,title,released
Expand Down Expand Up @@ -56,7 +56,7 @@ CREATE TABLE Towns (
name TEXT NOT NULL,
department VARCHAR(4) NOT NULL,
UNIQUE (code, department)
) USING pg_tde_basic;
) USING tde_heap_basic;

COPY towns (id, code, article, name, department) FROM stdin;
1 001 some_text Abergement-Clémenciat 01
Expand Down
2 changes: 1 addition & 1 deletion sql/non_sorted_off_compact.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE TABLE sbtest1(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde_basic;
) USING tde_heap_basic;

INSERT INTO sbtest1(k) VALUES
(1),
Expand Down
2 changes: 1 addition & 1 deletion sql/pg_tde_is_encrypted.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CREATE TABLE test_enc(
id SERIAL,
k INTEGER DEFAULT '0' NOT NULL,
PRIMARY KEY (id)
) USING pg_tde_basic;
) USING tde_heap_basic;

CREATE TABLE test_norm(
id SERIAL,
Expand Down
6 changes: 3 additions & 3 deletions sql/test_issue_153_fix.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CREATE TABLE dept (
deptno NUMERIC(2) NOT NULL CONSTRAINT dept_pk PRIMARY KEY,
dname VARCHAR(14) CONSTRAINT dept_dname_uq UNIQUE,
loc VARCHAR(13)
)using pg_tde_basic;
)using tde_heap_basic;
--
-- Create the 'emp' table
--
Expand All @@ -36,7 +36,7 @@ CREATE TABLE emp (
comm NUMERIC(7,2),
deptno NUMERIC(2) CONSTRAINT emp_ref_dept_fk
REFERENCES dept(deptno)
)using pg_tde_basic;
)using tde_heap_basic;
--
-- Create the 'jobhist' table
--
Expand All @@ -55,7 +55,7 @@ CREATE TABLE jobhist (
CONSTRAINT jobhist_ref_dept_fk FOREIGN KEY (deptno)
REFERENCES dept (deptno) ON DELETE SET NULL,
CONSTRAINT jobhist_date_chk CHECK (startdate <= enddate)
)using pg_tde_basic;
)using tde_heap_basic;
--
-- Create the 'salesemp' view
--
Expand Down
2 changes: 1 addition & 1 deletion sql/toast_decrypt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 src (f1 TEXT STORAGE EXTERNAL) USING pg_tde_basic;
CREATE TABLE src (f1 TEXT STORAGE EXTERNAL) USING tde_heap_basic;
INSERT INTO src VALUES(repeat('abcdeF',1000));
SELECT * FROM src;

Expand Down
6 changes: 3 additions & 3 deletions sql/toast_extended_storage.sql

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions sql/trigger_on_view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
--
-- 2 -- Test triggers on a join view
--
SET default_table_access_method TO 'pg_tde_basic';
SET default_table_access_method TO 'tde_heap_basic';

DROP VIEW IF EXISTS city_view CASCADE;
DROP TABLE IF exists country_table CASCADE;
Expand All @@ -16,7 +16,7 @@ DROP TABLE IF exists city_table cascade;
country_id serial primary key,
country_name text unique not null,
continent text not null
) using pg_tde_basic;
) using tde_heap_basic;

INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
Expand All @@ -29,7 +29,7 @@ DROP TABLE IF exists city_table cascade;
city_name text not null,
population bigint,
country_id int references country_table
) using pg_tde_basic;
) using tde_heap_basic;

CREATE VIEW city_view AS
SELECT city_id, city_name, population, country_name, continent
Expand Down
Loading

0 comments on commit 4fb220c

Please sign in to comment.