Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
pg_version: [17, 18]
pg_version: [16, 17, 18]
os: [ubuntu-24.04]
compiler: [gcc, clang]
build_type: [debugoptimized]
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
strategy:
fail-fast: false
matrix:
pg_version: [17, 18]
pg_version: [16, 17, 18]
os: [ubuntu-24.04-arm]
compiler: [gcc, clang]
build_type: [debugoptimized]
Expand Down
20 changes: 16 additions & 4 deletions ci_scripts/build-and-install-psp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"
INSTALL_DIR="$SCRIPT_DIR/../../pginst"
PSP_DIR="$SCRIPT_DIR/../../postgres"

PG_VERSION=$(sed -n "s/PACKAGE_VERSION='\\([0-9]*\\).*/\1/p" "$PSP_DIR/configure")

INSTALL_INJECTION_POINTS=0

case "$1" in
debug)
echo "Building with debug option"
ARGS+=" --enable-cassert --enable-injection-points"
ARGS+=" --enable-cassert"
INSTALL_INJECTION_POINTS=1
;;

debugoptimized)
echo "Building with debugoptimized option"
export CFLAGS="-O2"
ARGS+=" --enable-cassert --enable-injection-points"
ARGS+=" --enable-cassert"
INSTALL_INJECTION_POINTS=1
;;

coverage)
echo "Building with coverage option"
ARGS+=" --enable-injection-points --enable-coverage"
ARGS+=" --enable-coverage"
INSTALL_INJECTION_POINTS=1
;;

Expand All @@ -42,8 +44,18 @@ case "$1" in
;;
esac

if [ "$PG_VERSION" -lt 17 ]; then
INSTALL_INJECTION_POINTS=0
fi

if [ "$INSTALL_INJECTION_POINTS" = 1 ]; then
ARGS+=" --enable-injection-points"
fi

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
ARGS+=" --with-liburing"
if [ "$PG_VERSION" -ge 17 ]; then
ARGS+=" --with-liburing"
fi
NCPU=$(nproc)
elif [[ "$OSTYPE" == "darwin"* ]]; then
NCPU=$(sysctl -n hw.ncpu)
Expand Down
185 changes: 185 additions & 0 deletions expected/change_access_method_1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
\! rm -f '/tmp/pg_tde_test_keyring.per'
CREATE EXTENSION pg_tde;
SELECT pg_tde_add_database_key_provider_file('file-vault', '/tmp/pg_tde_test_keyring.per');
pg_tde_add_database_key_provider_file
---------------------------------------

(1 row)

SELECT pg_tde_create_key_using_database_key_provider('test-db-key', 'file-vault');
pg_tde_create_key_using_database_key_provider
-----------------------------------------------

(1 row)

SELECT pg_tde_set_key_using_database_key_provider('test-db-key', 'file-vault');
pg_tde_set_key_using_database_key_provider
--------------------------------------------

(1 row)

CREATE TABLE country_table (
country_id serial primary key,
country_name varchar(32) unique not null,
continent varchar(32) not null
) USING tde_heap;
INSERT INTO country_table (country_name, continent)
VALUES ('Japan', 'Asia'),
('UK', 'Europe'),
('USA', 'North America');
SELECT * FROM country_table;
country_id | country_name | continent
------------+--------------+---------------
1 | Japan | Asia
2 | UK | Europe
3 | USA | North America
(3 rows)

SELECT pg_tde_is_encrypted('country_table');
pg_tde_is_encrypted
---------------------
t
(1 row)

SELECT pg_tde_is_encrypted('country_table_country_id_seq');
pg_tde_is_encrypted
---------------------
t
(1 row)

SELECT pg_tde_is_encrypted('country_table_pkey');
pg_tde_is_encrypted
---------------------
t
(1 row)

-- Try changing the encrypted table to an unencrypted table
ALTER TABLE country_table SET ACCESS METHOD heap;
-- Insert some more data
INSERT INTO country_table (country_name, continent)
VALUES ('France', 'Europe'),
('Germany', 'Europe'),
('Canada', 'North America');
SELECT * FROM country_table;
country_id | country_name | continent
------------+--------------+---------------
1 | Japan | Asia
2 | UK | Europe
3 | USA | North America
4 | France | Europe
5 | Germany | Europe
6 | Canada | North America
(6 rows)

SELECT pg_tde_is_encrypted('country_table');
pg_tde_is_encrypted
---------------------
f
(1 row)

SELECT pg_tde_is_encrypted('country_table_country_id_seq');
pg_tde_is_encrypted
---------------------
f
(1 row)

SELECT pg_tde_is_encrypted('country_table_pkey');
pg_tde_is_encrypted
---------------------
f
(1 row)

-- Change it back to encrypted
ALTER TABLE country_table SET ACCESS METHOD tde_heap;
INSERT INTO country_table (country_name, continent)
VALUES ('China', 'Asia'),
('Brazil', 'South America'),
('Australia', 'Oceania');
SELECT * FROM country_table;
country_id | country_name | continent
------------+--------------+---------------
1 | Japan | Asia
2 | UK | Europe
3 | USA | North America
4 | France | Europe
5 | Germany | Europe
6 | Canada | North America
7 | China | Asia
8 | Brazil | South America
9 | Australia | Oceania
(9 rows)

SELECT pg_tde_is_encrypted('country_table');
pg_tde_is_encrypted
---------------------
t
(1 row)

SELECT pg_tde_is_encrypted('country_table_country_id_seq');
pg_tde_is_encrypted
---------------------
t
(1 row)

SELECT pg_tde_is_encrypted('country_table_pkey');
pg_tde_is_encrypted
---------------------
t
(1 row)

-- Test that we honor the default value
SET default_table_access_method = 'heap';
ALTER TABLE country_table SET ACCESS METHOD DEFAULT;
ERROR: syntax error at or near "DEFAULT"
LINE 1: ALTER TABLE country_table SET ACCESS METHOD DEFAULT;
^
SELECT pg_tde_is_encrypted('country_table');
pg_tde_is_encrypted
---------------------
t
(1 row)

SET default_table_access_method = 'tde_heap';
ALTER TABLE country_table SET ACCESS METHOD DEFAULT;
ERROR: syntax error at or near "DEFAULT"
LINE 1: ALTER TABLE country_table SET ACCESS METHOD DEFAULT;
^
SELECT pg_tde_is_encrypted('country_table');
pg_tde_is_encrypted
---------------------
t
(1 row)

RESET default_table_access_method;
ALTER TABLE country_table ADD y text;
SELECT pg_tde_is_encrypted('pg_toast.pg_toast_' || 'country_table'::regclass::oid);
pg_tde_is_encrypted
---------------------
t
(1 row)

CREATE TABLE country_table2 (
country_id serial primary key,
country_name text unique not null,
continent text not null
);
SET pg_tde.enforce_encryption = on;
CREATE TABLE country_table3 (
country_id serial primary key,
country_name text unique not null,
continent text not null
) USING heap;
ERROR: pg_tde.enforce_encryption is ON, only the tde_heap access method is allowed.
ALTER TABLE country_table SET ACCESS METHOD heap;
ERROR: pg_tde.enforce_encryption is ON, only the tde_heap access method is allowed.
ALTER TABLE country_table2 SET ACCESS METHOD tde_heap;
CREATE TABLE country_table3 (
country_id serial primary key,
country_name text unique not null,
continent text not null
) USING tde_heap;
DROP TABLE country_table;
DROP TABLE country_table2;
DROP TABLE country_table3;
SET pg_tde.enforce_encryption = off;
DROP EXTENSION pg_tde;
Loading
Loading