Skip to content

Commit bea1d00

Browse files
NikolaySclaude
andcommitted
Test with minimal privileges (pg_monitor) and add PostgreSQL 18 beta
- Create dba_user with pg_monitor role instead of superuser - Grant minimal necessary privileges (CONNECT, USAGE, SELECT) - Test all SQL files with realistic non-admin user permissions - Add PostgreSQL 18beta1 to test matrix - Ensure postgres_dba works in real-world scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 79b9a0c commit bea1d00

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
postgres-version: ['13', '14', '15', '16', '17']
15+
postgres-version: ['13', '14', '15', '16', '17', '18beta1']
1616
fail-fast: false
1717

1818
services:
@@ -59,24 +59,36 @@ jobs:
5959
psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pg_stat_statements;' || echo "Warning: pg_stat_statements extension not available"
6060
psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pgstattuple;'
6161
62+
# Create minimal privilege user for testing
63+
psql -h localhost -U postgres -d test -c "CREATE USER dba_user;"
64+
psql -h localhost -U postgres -d test -c "GRANT pg_monitor TO dba_user;"
65+
psql -h localhost -U postgres -d test -c "GRANT CONNECT ON DATABASE test TO dba_user;"
66+
psql -h localhost -U postgres -d test -c "GRANT USAGE ON SCHEMA public TO dba_user;"
67+
6268
# Verify extensions
6369
psql -h localhost -U postgres -d test -c 'SELECT extname FROM pg_extension ORDER BY extname;'
6470
65-
# Create test tables for alignment testing
71+
# Create test tables for alignment testing (as superuser)
6672
psql -h localhost -U postgres -d test -c "CREATE TABLE align1 AS SELECT 1::int4, 2::int8, 3::int4 AS more FROM generate_series(1, 100000) _(i);"
6773
psql -h localhost -U postgres -d test -c "CREATE TABLE align2 AS SELECT 1::int4, 3::int4 AS more, 2::int8 FROM generate_series(1, 100000) _(i);"
74+
75+
# Grant access to test tables for dba_user
76+
psql -h localhost -U postgres -d test -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO dba_user;"
77+
78+
# Test connection as dba_user
79+
psql -h localhost -U dba_user -d test -c 'SELECT current_user, session_user;'
6880
6981
- name: Test wide mode
7082
run: |
7183
echo "\set postgres_dba_wide true" > ~/.psqlrc
7284
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
73-
echo "Testing all SQL files in wide mode..."
85+
echo "Testing all SQL files in wide mode with minimal privileges..."
7486
for f in sql/*; do
7587
echo " Testing $f..."
76-
if ! psql -h localhost -U postgres -d test --no-psqlrc -f warmup.psql -f "$f" > /dev/null 2>&1; then
88+
if ! psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f" > /dev/null 2>&1; then
7789
echo "❌ FAILED: $f in wide mode"
7890
echo "Error output:"
79-
psql -h localhost -U postgres -d test --no-psqlrc -f warmup.psql -f "$f"
91+
psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f"
8092
exit 1
8193
fi
8294
done
@@ -86,13 +98,13 @@ jobs:
8698
run: |
8799
echo "\set postgres_dba_wide false" > ~/.psqlrc
88100
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
89-
echo "Testing all SQL files in normal mode..."
101+
echo "Testing all SQL files in normal mode with minimal privileges..."
90102
for f in sql/*; do
91103
echo " Testing $f..."
92-
if ! psql -h localhost -U postgres -d test --no-psqlrc -f warmup.psql -f "$f" > /dev/null 2>&1; then
104+
if ! psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f" > /dev/null 2>&1; then
93105
echo "❌ FAILED: $f in normal mode"
94106
echo "Error output:"
95-
psql -h localhost -U postgres -d test --no-psqlrc -f warmup.psql -f "$f"
107+
psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f"
96108
exit 1
97109
fi
98110
done
@@ -103,10 +115,10 @@ jobs:
103115
echo "\set postgres_dba_wide false" > ~/.psqlrc
104116
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
105117
106-
echo "Running regression tests..."
118+
echo "Running regression tests with minimal privileges..."
107119
108120
echo " Testing 0_node.sql..."
109-
OUTPUT=$(psql -h localhost -U postgres -d test --no-psqlrc -f warmup.psql -f sql/0_node.sql | grep Role)
121+
OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/0_node.sql | grep Role)
110122
if [[ "$OUTPUT" == *"Master"* ]]; then
111123
echo " ✓ Role test passed"
112124
else
@@ -115,7 +127,7 @@ jobs:
115127
fi
116128
117129
echo " Testing p1_alignment_padding.sql..."
118-
OUTPUT=$(psql -h localhost -U postgres -d test --no-psqlrc -f warmup.psql -f sql/p1_alignment_padding.sql | grep align)
130+
OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/p1_alignment_padding.sql | grep align)
119131
if [[ "$OUTPUT" == *"align1"* && "$OUTPUT" == *"align2"* && "$OUTPUT" == *"int4, more, int8"* ]]; then
120132
echo " ✓ Alignment padding test passed"
121133
else
@@ -124,14 +136,14 @@ jobs:
124136
fi
125137
126138
echo " Testing a1_activity.sql..."
127-
OUTPUT=$(psql -h localhost -U postgres -d test --no-psqlrc -f warmup.psql -f sql/a1_activity.sql | grep User)
139+
OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/a1_activity.sql | grep User)
128140
if [[ "$OUTPUT" == *"User"* ]]; then
129141
echo " ✓ Activity test passed"
130142
else
131143
echo " ✗ Activity test failed: $OUTPUT"
132144
exit 1
133145
fi
134146
135-
echo "✅ All regression tests passed"
147+
echo "✅ All regression tests passed with minimal privileges"
136148
137149

0 commit comments

Comments
 (0)