Skip to content

Commit c15794e

Browse files
author
Mohit Joshi
committed
Added pg_tde test for server upgrade from 17.5.3 to 17.6.1
1 parent 85f976f commit c15794e

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
3+
INSTALL_DIR_LOWER=$HOME/postgresql/bld_tde/install
4+
INSTALL_DIR_HIGHER=$HOME/postgresql/bld_17.6/install
5+
LOWER_VERSION=17.5.3
6+
HIGHER_VERSION=17.6.1
7+
DATADIR_LOWER=$INSTALL_DIR_LOWER/data_$LOWER_VERSION
8+
DATADIR_HIGHER=$INSTALL_DIR_HIGHER/data_$HIGHER_VERSION
9+
PORT=5432
10+
KEYRING_FILE=/tmp/keyring.file
11+
12+
main_test() {
13+
14+
# Step 1: Kill any running PG server on port 5432
15+
echo "=> Checking for running PostgreSQL on port $PORT"
16+
PG_PID=$(sudo lsof -ti :$PORT || true)
17+
if [ -n "$PG_PID" ]; then
18+
echo "=> Killing process $PG_PID"
19+
kill -9 $PG_PID
20+
fi
21+
22+
# Step 2: Remove keyring file
23+
echo "=> Removing keyring file"
24+
rm -rf "$KEYRING_FILE" $DATADIR_LOWER $DATADIR_HIGHER
25+
26+
# Step 3: Start Server on LOWER_VERSION
27+
$INSTALL_DIR_LOWER/bin/initdb -D $DATADIR_LOWER
28+
29+
# Configure postgresql.conf
30+
echo "shared_preload_libraries = 'pg_tde'" >> "$DATADIR_LOWER/postgresql.conf"
31+
echo "default_table_access_method = 'tde_heap'" >> "$DATADIR_LOWER/postgresql.conf"
32+
echo "listen_addresses = '*'" >> "$DATADIR_LOWER/postgresql.conf"
33+
echo "port = $PORT" >> "$DATADIR_LOWER/postgresql.conf"
34+
echo "logging_collector = on" >> "$DATADIR_LOWER/postgresql.conf"
35+
echo "log_directory = '$DATADIR_LOWER'" >> "$DATADIR_LOWER/postgresql.conf"
36+
echo "log_filename = 'server_$LOWER_VERSION.log'" >> "$DATADIR_LOWER/postgresql.conf"
37+
echo "log_statement = 'all'" >> "$DATADIR_LOWER/postgresql.conf"
38+
39+
$INSTALL_DIR_LOWER/bin/pg_ctl -D $DATADIR_LOWER start
40+
41+
# Enable TDE
42+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "CREATE EXTENSION pg_tde"
43+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "SELECT pg_tde_add_global_key_provider_file('global_file_provider1','$KEYRING_FILE')"
44+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "SELECT pg_tde_create_key_using_global_key_provider('server_key', 'global_file_provider1')"
45+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "SELECT pg_tde_create_key_using_global_key_provider('table_key', 'global_file_provider1')"
46+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "SELECT pg_tde_set_server_key_using_global_key_provider('server_key', 'global_file_provider1')"
47+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "SELECT pg_tde_set_key_using_global_key_provider('table_key', 'global_file_provider1')"
48+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "ALTER SYSTEM SET pg_tde.wal_encrypt='ON'"
49+
50+
# Restart server to enable WAL encryption
51+
$INSTALL_DIR_LOWER/bin/pg_ctl -D $DATADIR_LOWER restart
52+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "SHOW pg_tde.wal_encrypt"
53+
$INSTALL_DIR_LOWER/bin/psql -d postgres -p $PORT -c "SELECT version()"
54+
55+
echo "✅ PostgreSQL Server started on port $PORT"
56+
57+
sysbench /usr/share/sysbench/oltp_insert.lua \
58+
--pgsql-host=localhost \
59+
--pgsql-port=$PORT \
60+
--pgsql-user=`whoami` \
61+
--pgsql-db=postgres \
62+
--db-driver=pgsql \
63+
--time=40 --threads=5 --tables=10 --table-size=1000 prepare
64+
65+
sleep 3
66+
67+
echo " Start the upgrade process...Stop server"
68+
$INSTALL_DIR_LOWER/bin/pg_ctl -D $DATADIR_LOWER stop
69+
cp -R $DATADIR_LOWER $DATADIR_HIGHER
70+
rm -f $DATADIR_HIGHER/postgresql.conf
71+
72+
# Configure postgresql.conf
73+
echo "shared_preload_libraries = 'pg_tde'" >> "$DATADIR_HIGHER/postgresql.conf"
74+
echo "default_table_access_methos = 'tde_heap'" >> "$DATADIR_LOWER/postgresql.conf"
75+
echo "listen_addresses = '*'" >> "$DATADIR_HIGHER/postgresql.conf"
76+
echo "port = $PORT" >> "$DATADIR_HIGHER/postgresql.conf"
77+
echo "logging_collector = on" >> "$DATADIR_HIGHER/postgresql.conf"
78+
echo "log_directory = '$DATADIR_HIGHER'" >> "$DATADIR_HIGHER/postgresql.conf"
79+
echo "log_filename = 'server_$HIGHER_VERSION.log'" >> "$DATADIR_HIGHER/postgresql.conf"
80+
echo "log_statement = 'all'" >> "$DATADIR_HIGHER/postgresql.conf"
81+
82+
echo "Starting PG server $HIGHER_VERSION using $DATADIR_LOWER"
83+
if ! "$INSTALL_DIR_HIGHER/bin/pg_ctl" -D "$DATADIR_HIGHER" -o "-p $PORT" -w start; then
84+
echo "❌ Failed to start PostgreSQL on port $PORT. Exiting as upgrade failed..."
85+
exit 1
86+
else
87+
echo "Server successfully upgraded to $HIGHER_VERSION"
88+
fi
89+
90+
$INSTALL_DIR_HIGHER/bin/psql -d postgres -p $PORT -c "SELECT version()"
91+
$INSTALL_DIR_HIGHER/bin/psql -d postgres -p $PORT -c "SHOW pg_tde.wal_encrypt"
92+
$INSTALL_DIR_HIGHER/bin/psql -d postgres -p $PORT -c "SELECT pg_tde_is_encrypted('sbtest1')"
93+
$INSTALL_DIR_HIGHER/bin/psql -d postgres -p $PORT -c "SELECT pg_tde_is_encrypted('sbtest5')"
94+
$INSTALL_DIR_HIGHER/bin/psql -d postgres -p $PORT -c "SELECT pg_tde_is_encrypted('sbtest10')"
95+
96+
}
97+
98+
99+
# Main test begins here
100+
main_test

0 commit comments

Comments
 (0)