Skip to content

Commit d09a98c

Browse files
committed
Added pg_tde helper scripts
1 parent abb869d commit d09a98c

23 files changed

+243
-440
lines changed

postgresql/tests/change_pg_tde_key_provider.sh

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
#!/bin/bash
22

3-
set -e # Exit immediately if a command exits with a non-zero status
4-
set -u # Treat unset variables as an error
5-
set -o pipefail # Prevent errors in a pipeline from being masked
6-
73
# Set variable
84
export INSTALL_DIR=/home/mohit.joshi/postgresql/pg_tde/bld_tde/install
95
export PGDATA=$INSTALL_DIR/data
106
export LOG_FILE=$PGDATA/server.log
117
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
128

13-
# initate the database
14-
initialize_server() {
15-
PG_PID=$(lsof -ti :5432) || true
16-
if [[ $PG_PID != "" ]]; then
17-
kill -9 $PG_PID
18-
fi
19-
rm -rf $PGDATA
20-
$INSTALL_DIR/bin/initdb -D $PGDATA
21-
cat > "$PGDATA/postgresql.conf" <<SQL
22-
shared_preload_libraries = 'pg_tde'
23-
default_table_access_method='tde_heap'
24-
SQL
25-
}
9+
source "$(dirname "${BASH_SOURCE[0]}")/helper_scripts/initialize_server.sh"
2610

2711
start_server() {
2812
$INSTALL_DIR/bin/pg_ctl -D $PGDATA start -o "-p 5432" -l $LOG_FILE

postgresql/tests/crash_recovery_key_decrypt_error.sh

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,9 @@ export DB_NAME="sbtest"
88
export TABLE_PREFIX="ddl_test"
99
export TOTAL_TABLES=20
1010

11-
# initate the database
12-
initialize_server() {
13-
PG_PID=$(lsof -ti :5432) || true
14-
if [[ -n "$PG_PID" ]]; then
15-
kill -9 $PG_PID
16-
fi
17-
rm -rf $PGDATA
18-
$INSTALL_DIR/bin/initdb -D $PGDATA
19-
cat > "$PGDATA/postgresql.conf" <<SQL
20-
shared_preload_libraries = 'pg_tde'
21-
log_statement = 'all'
22-
log_directory = '$PGDATA'
23-
SQL
24-
}
25-
26-
start_server() {
27-
$INSTALL_DIR/bin/pg_ctl -D $PGDATA -l $LOG_FILE start
28-
$INSTALL_DIR/bin/createdb $DB_NAME
29-
$INSTALL_DIR/bin/psql -d $DB_NAME -c"CREATE EXTENSION pg_tde;"
30-
$INSTALL_DIR/bin/psql -d $DB_NAME -c"SELECT pg_tde_add_global_key_provider_file('global_keyring','$PGDATA/keyring.file');"
31-
$INSTALL_DIR/bin/psql -d $DB_NAME -c"SELECT pg_tde_add_database_key_provider_file('local_keyring','$PGDATA/keyring.file');"
32-
$INSTALL_DIR/bin/psql -d $DB_NAME -c"SELECT pg_tde_set_server_key_using_global_key_provider('wal_key','global_keyring');"
33-
$INSTALL_DIR/bin/psql -d $DB_NAME -c"SELECT pg_tde_set_key_using_database_key_provider('table_key','local_keyring');"
34-
PG_PID=$(lsof -ti :5432)
35-
}
36-
11+
source "$(dirname "${BASH_SOURCE[0]}")/helper_scripts/initialize_server.sh"
12+
source "$(dirname "${BASH_SOURCE[0]}")/helper_scripts/start_server.sh"
13+
source "$(dirname "${BASH_SOURCE[0]}")/helper_scripts/enable_tde.sh"
3714

3815
# Create multiple tables
3916
create_tables() {
@@ -221,10 +198,17 @@ crash_server() {
221198
kill -9 $PG_PID
222199
}
223200

224-
# Main load and DDL loop
201+
# Create data directory
225202
initialize_server
203+
# Start PG server and save PID
226204
start_server
227-
create_tables # Create initial tables
205+
PG_PID=$(lsof -ti :5432)
206+
# Create a new database
207+
$INSTALL_DIR/bin/createdb $DB_NAME
208+
# Enable TDE
209+
enable_tde
210+
# Create initial tables
211+
create_tables
228212

229213
for i in {1..20}; do
230214
echo "########################################"

postgresql/tests/ddl_load_stress_test_smgr_encryption.sh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,7 @@ LOG_FILE=$PGDATA/server.log
77
DB_NAME="sbtest"
88
TABLE_PREFIX="ddl_test"
99
TOTAL_TABLES=20
10-
11-
# initate the database
12-
initialize_server() {
13-
PG_PID=$(lsof -ti :5432) || true
14-
if [[ -n "$PG_PID" ]]; then
15-
kill -9 $PG_PID
16-
fi
17-
rm -rf $PGDATA
18-
$INSTALL_DIR/bin/initdb -D $PGDATA
19-
cat > "$PGDATA/postgresql.conf" <<SQL
20-
shared_preload_libraries = 'pg_tde'
21-
log_statement = 'all'
22-
log_directory = '$PGDATA'
23-
SQL
24-
}
10+
source "$(dirname "${BASH_SOURCE[0]}")/helper_scripts/initialize_server.sh"
2511

2612
start_server() {
2713
$INSTALL_DIR/bin/pg_ctl -D $PGDATA -l $LOG_FILE start

postgresql/tests/ddl_load_stress_test_wal_encryption.sh

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
11
#!/bin/bash
22

3-
set -e # Exit immediately if a command exits with a non-zero status
4-
set -u # Treat unset variables as an error
5-
set -o pipefail # Prevent errors in a pipeline from being masked
6-
73
# Set variable
8-
export INSTALL_DIR=/home/mohit.joshi/postgresql/pg_tde/bld_tde_17.4/install
9-
export PGDATA=$INSTALL_DIR/data
10-
export LOG_FILE=$PGDATA/server.log
11-
export DB_NAME="sbtest"
12-
export TABLE_PREFIX="ddl_test"
13-
export TOTAL_TABLES=20
14-
15-
# initate the database
16-
initialize_server() {
17-
PG_PID=$(sudo -u postgres lsof -ti :5432) || true
18-
if [[ -n "$PG_PID" ]]; then
19-
sudo -u postgres kill -9 $PG_PID
20-
fi
21-
sudo rm -rf $PGDATA
22-
sudo mkdir $PGDATA
23-
sudo chown postgres:postgres $PGDATA
24-
sudo -u postgres bash <<EOF
25-
$INSTALL_DIR/bin/initdb -D $PGDATA
26-
cat > "$PGDATA/postgresql.conf" <<SQL
27-
shared_preload_libraries = 'pg_tde'
28-
SQL
29-
EOF
30-
}
4+
INSTALL_DIR=/home/mohit.joshi/postgresql/pg_tde/bld_tde/install
5+
PGDATA=$INSTALL_DIR/data
6+
LOG_FILE=$PGDATA/server.log
7+
DB_NAME="sbtest"
8+
TABLE_PREFIX="ddl_test"
9+
TOTAL_TABLES=20
10+
11+
source "$(dirname "${BASH_SOURCE[0]}")/helper_scripts/initialize_server.sh"
3112

3213
start_server() {
3314
sudo -u postgres bash <<EOF

postgresql/tests/compare_primary_replica_tables.sh renamed to postgresql/tests/helper_scripts/compare_primary_replica_tables.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# Configuration
4-
INSTALL_DIR="/home/mohit.joshi/postgresql/pg_tde/bld_tde_17.4/install"
4+
INSTALL_DIR="/home/mohit.joshi/postgresql/pg_tde/bld_tde/install"
55
PRIMARY_PORT="5432"
66
REPLICA_PORT="5433"
77
DB_NAME="sbtest"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
enable_tde() {
4+
local install_dir="${INSTALL_DIR:-$HOME/postgresql/install}"
5+
local pgdata="${PGDATA:-$HOME/pgdata}"
6+
local db_name="${DB_NAME:-postgres}"
7+
local keyring_file="${KEYRING_FILE:-$pgdata/keyring.file}"
8+
9+
if [[ ! -x "$install_dir/bin/psql" ]]; then
10+
echo "Error: psql not found at $install_dir/bin/psql"
11+
return 1
12+
fi
13+
14+
echo "=> Enabling Transparent Data Encryption (TDE) on database: $db_name"
15+
"$install_dir/bin/psql" -d "$db_name" -c "CREATE EXTENSION IF NOT EXISTS pg_tde;"
16+
"$install_dir/bin/psql" -d "$db_name" -c "SELECT pg_tde_add_global_key_provider_file('global_keyring', '$keyring_file');"
17+
"$install_dir/bin/psql" -d "$db_name" -c "SELECT pg_tde_add_database_key_provider_file('local_keyring', '$keyring_file');"
18+
"$install_dir/bin/psql" -d "$db_name" -c "SELECT pg_tde_set_server_key_using_global_key_provider('wal_key', 'global_keyring');"
19+
"$install_dir/bin/psql" -d "$db_name" -c "SELECT pg_tde_set_key_using_database_key_provider('table_key', 'local_keyring');"
20+
echo ".. TDE enabled"
21+
}
File renamed without changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
initialize_server() {
4+
# Allow overriding via env variables or use defaults
5+
local port="${PORT:-5432}"
6+
local data_dir="${PGDATA:-$HOME/postgresql/pg_tde/bld_tde/install/data}"
7+
local install_dir="${INSTALL_DIR:-$HOME/postgresql/pg_tde/bld_tde/install}"
8+
9+
# Kill PostgreSQL if running on common ports (5432–5434)
10+
local pg_pids
11+
pg_pids=$(lsof -ti :5432 -ti :5433 -ti :5434 2>/dev/null)
12+
if [[ -n "$pg_pids" ]]; then
13+
echo "Killing PostgreSQL processes: $pg_pids"
14+
kill -9 $pg_pids
15+
fi
16+
17+
# Clean up data directory
18+
if [[ -d "$data_dir" ]]; then
19+
echo "Removing old data directory: $data_dir"
20+
rm -rf "$data_dir"
21+
fi
22+
23+
echo "Initializing database at $data_dir"
24+
"$install_dir/bin/initdb" -D "$data_dir" > /dev/null 2>&1
25+
if [[ $? -ne 0 ]]; then
26+
echo "Error: initdb failed"
27+
return 1
28+
fi
29+
30+
# Write basic postgresql.conf
31+
cat > "$data_dir/postgresql.conf" <<EOF
32+
port = $port
33+
listen_addresses = '*'
34+
shared_preload_libraries = 'pg_tde'
35+
logging_collector = on
36+
log_directory = '$data_dir'
37+
log_filename = 'server.log'
38+
log_statement = 'all'
39+
EOF
40+
41+
echo "Server initialized on port $port with data dir $data_dir"
42+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
restart_server() {
4+
local install_dir="${INSTALL_DIR:-$HOME/postgresql/pg_tde/bld_tde/install}"
5+
local data_dir="${PGDATA:-$install_dir/data}"
6+
local log_file="${LOG_FILE:-$data_dir/server.log}"
7+
8+
if [[ ! -x "$install_dir/bin/pg_ctl" ]]; then
9+
echo "Error: pg_ctl not found at $install_dir/bin/pg_ctl"
10+
return 1
11+
fi
12+
13+
if [[ ! -d "$data_dir" ]]; then
14+
echo "Error: PGDATA directory does not exist: $data_dir"
15+
return 1
16+
fi
17+
18+
echo "Starting PostgreSQL server..."
19+
"$install_dir/bin/pg_ctl" -D "$data_dir" -l "$log_file" restart
20+
}
21+

postgresql/tests/setup_kmip.sh renamed to postgresql/tests/helper_scripts/setup_kmip.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# Set Kmip configuration
21
#! /bin/bash
3-
setup_kmip() {
2+
start_kmip_server() {
43
# Kill and existing kmip server
54
sudo pkill -9 kmip
65
# Start KMIP server
@@ -27,5 +26,3 @@ setup_kmip() {
2726
# Sleep for 30 sec to fully initialize the KMIP server
2827
sleep 30
2928
}
30-
31-
setup_kmip

0 commit comments

Comments
 (0)