Skip to content

Commit 1bdc9b7

Browse files
authored
Merge pull request #67 from NikolayS/cursor/add-postgres-version-tests-to-github-actions-42e4
Migrate to GitHub Actions with PostgreSQL 13-18 testing and minimal privilege support
2 parents c2051ae + 1d47ee5 commit 1bdc9b7

File tree

5 files changed

+199
-98
lines changed

5 files changed

+199
-98
lines changed

.circleci/config.yml

Lines changed: 0 additions & 77 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: Test PostgreSQL Versions
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
postgres-version: ['13', '14', '15', '16', '17', '18']
16+
fail-fast: false
17+
18+
services:
19+
postgres:
20+
image: postgres:${{ matrix.postgres-version }}
21+
env:
22+
POSTGRES_PASSWORD: postgres
23+
POSTGRES_DB: test
24+
POSTGRES_HOST_AUTH_METHOD: trust
25+
POSTGRES_INITDB_ARGS: --auth-host=trust --auth-local=trust
26+
options: >-
27+
--health-cmd pg_isready
28+
--health-interval 10s
29+
--health-timeout 5s
30+
--health-retries 5
31+
ports:
32+
- 5432:5432
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Install PostgreSQL client
39+
run: |
40+
# Install default PostgreSQL client (works for all versions)
41+
sudo apt-get update
42+
sudo apt-get install -y postgresql-client
43+
44+
# Verify installation
45+
psql --version
46+
47+
- name: Prepare test database
48+
run: |
49+
# Wait for PostgreSQL to be ready
50+
until pg_isready -h localhost -p 5432 -U postgres; do
51+
echo "Waiting for postgres..."
52+
sleep 2
53+
done
54+
55+
# Check PostgreSQL version
56+
psql -h localhost -U postgres -d test -c 'SELECT version();'
57+
58+
# Create extensions (pg_stat_statements may not work without shared_preload_libraries)
59+
psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pg_stat_statements;' || echo "Warning: pg_stat_statements extension not available"
60+
psql -h localhost -U postgres -d test -c 'CREATE EXTENSION IF NOT EXISTS pgstattuple;'
61+
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+
68+
# Verify extensions
69+
psql -h localhost -U postgres -d test -c 'SELECT extname FROM pg_extension ORDER BY extname;'
70+
71+
# Create test tables for alignment testing (as superuser)
72+
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);"
73+
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;'
80+
81+
- name: Test wide mode
82+
run: |
83+
echo "\set postgres_dba_wide true" > ~/.psqlrc
84+
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
85+
echo "Testing all SQL files in wide mode with minimal privileges..."
86+
for f in sql/*; do
87+
echo " Testing $f..."
88+
if ! psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f" > /dev/null 2>&1; then
89+
echo "❌ FAILED: $f in wide mode"
90+
echo "Error output:"
91+
psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f"
92+
exit 1
93+
fi
94+
done
95+
echo "✅ All tests passed in wide mode"
96+
97+
- name: Test normal mode
98+
run: |
99+
echo "\set postgres_dba_wide false" > ~/.psqlrc
100+
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
101+
echo "Testing all SQL files in normal mode with minimal privileges..."
102+
for f in sql/*; do
103+
echo " Testing $f..."
104+
if ! psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f" > /dev/null 2>&1; then
105+
echo "❌ FAILED: $f in normal mode"
106+
echo "Error output:"
107+
psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f "$f"
108+
exit 1
109+
fi
110+
done
111+
echo "✅ All tests passed in normal mode"
112+
113+
- name: Run regression tests
114+
run: |
115+
echo "\set postgres_dba_wide false" > ~/.psqlrc
116+
echo "\set postgres_dba_interactive_mode false" >> ~/.psqlrc
117+
118+
echo "Running regression tests with minimal privileges..."
119+
120+
echo " Testing 0_node.sql..."
121+
OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/0_node.sql | grep Role)
122+
if [[ "$OUTPUT" == *"Master"* ]]; then
123+
echo " ✓ Role test passed"
124+
else
125+
echo " ✗ Role test failed: $OUTPUT"
126+
exit 1
127+
fi
128+
129+
echo " Testing p1_alignment_padding.sql..."
130+
OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/p1_alignment_padding.sql | grep align)
131+
if [[ "$OUTPUT" == *"align1"* && "$OUTPUT" == *"align2"* && "$OUTPUT" == *"int4, more, int8"* ]]; then
132+
echo " ✓ Alignment padding test passed"
133+
else
134+
echo " ✗ Alignment padding test failed: $OUTPUT"
135+
exit 1
136+
fi
137+
138+
echo " Testing a1_activity.sql..."
139+
OUTPUT=$(psql -h localhost -U dba_user -d test --no-psqlrc -f warmup.psql -f sql/a1_activity.sql | grep User)
140+
if [[ "$OUTPUT" == *"User"* ]]; then
141+
echo " ✓ Activity test passed"
142+
else
143+
echo " ✗ Activity test failed: $OUTPUT"
144+
exit 1
145+
fi
146+
147+
echo "✅ All regression tests passed with minimal privileges"
148+
149+

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The missing set of useful tools for Postgres DBA and mere mortals.
66
<img alt="Demo" src="https://user-images.githubusercontent.com/1345402/74124060-dbe25c00-4b85-11ea-9538-8d3b67f09896.gif">
77

88

9-
:point_right: See also [postgres-checkup](https://gitlab.com/postgres-ai/postgres-checkup), a tool for automated health checks and SQL performance analysis.
9+
:point_right: See also [postgres_ai](https://github.com/postgres-ai/postgres_ai), a comprehensive monitoring and optimization platform that includes automated health checks, SQL performance analysis, and much more.
1010

1111
## Questions?
1212

@@ -34,6 +34,19 @@ sudo apt-get install -y postgresql-client-12
3434

3535
Using alternative psql pager called "pspg" is highly recommended (but not required): https://github.com/okbob/pspg.
3636

37+
## Supported PostgreSQL Versions
38+
39+
**postgres_dba** is tested and supports **PostgreSQL 13-18**, including the latest PostgreSQL 18 release.
40+
41+
-**PostgreSQL 13** - Fully supported
42+
-**PostgreSQL 14** - Fully supported
43+
-**PostgreSQL 15** - Fully supported
44+
-**PostgreSQL 16** - Fully supported
45+
-**PostgreSQL 17** - Fully supported (includes `pg_stat_checkpointer` compatibility)
46+
-**PostgreSQL 18** - Fully supported (latest release)
47+
48+
Older versions (9.6-12) may work but are not actively tested. Some reports may require specific PostgreSQL features introduced in newer versions.
49+
3750
## Installation
3851
The installation is trivial. Clone the repository and put "dba" alias to your `.psqlrc` file (works in bash, zsh, and csh):
3952
```bash

sql/0_node.sql

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ For Postgres versions older than 10, run this first:
88
\set postgres_dba_is_wal_replay_paused pg_is_xlog_replay_paused
99
*/
1010

11+
1112
with data as (
1213
select s.*
1314
from pg_stat_database s
@@ -48,28 +49,41 @@ select 'Started At', pg_postmaster_start_time()::timestamptz(0)::text
4849
union all
4950
select 'Uptime', (now() - pg_postmaster_start_time())::interval(0)::text
5051
union all
51-
select
52-
'Checkpoints',
53-
(select (checkpoints_timed + checkpoints_req)::text from pg_stat_bgwriter)
52+
\if :postgres_dba_pgvers_17plus
53+
select 'Checkpoints', (select (num_timed + num_requested)::text from pg_stat_checkpointer)
5454
union all
55-
select
56-
'Forced Checkpoints',
57-
(
58-
select round(100.0 * checkpoints_req::numeric /
59-
(nullif(checkpoints_timed + checkpoints_req, 0)), 1)::text || '%'
60-
from pg_stat_bgwriter
61-
)
55+
select 'Forced Checkpoints', (
56+
select round(100.0 * num_requested::numeric /
57+
(nullif(num_timed + num_requested, 0)), 1)::text || '%'
58+
from pg_stat_checkpointer
59+
)
6260
union all
63-
select
64-
'Checkpoint MB/sec',
65-
(
66-
select round((nullif(buffers_checkpoint::numeric, 0) /
67-
((1024.0 * 1024 /
68-
(current_setting('block_size')::numeric))
69-
* extract('epoch' from now() - stats_reset)
70-
))::numeric, 6)::text
71-
from pg_stat_bgwriter
72-
)
61+
select 'Checkpoint MiB/sec', (
62+
select round((nullif(buffers_written::numeric, 0) /
63+
((1024.0 * 1024 /
64+
(current_setting('block_size')::numeric))
65+
* extract('epoch' from now() - stats_reset)
66+
))::numeric, 6)::text
67+
from pg_stat_checkpointer
68+
)
69+
\else
70+
select 'Checkpoints', (select (checkpoints_timed + checkpoints_req)::text from pg_stat_bgwriter)
71+
union all
72+
select 'Forced Checkpoints', (
73+
select round(100.0 * checkpoints_req::numeric /
74+
(nullif(checkpoints_timed + checkpoints_req, 0)), 1)::text || '%'
75+
from pg_stat_bgwriter
76+
)
77+
union all
78+
select 'Checkpoint MiB/sec', (
79+
select round((nullif(buffers_checkpoint::numeric, 0) /
80+
((1024.0 * 1024 /
81+
(current_setting('block_size')::numeric))
82+
* extract('epoch' from now() - stats_reset)
83+
))::numeric, 6)::text
84+
from pg_stat_bgwriter
85+
)
86+
\endif
7387
union all
7488
select repeat('-', 33), repeat('-', 88)
7589
union all

warmup.psql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
select 1/0;
55
\endif
66

7+
select current_setting('server_version_num')::integer >= 170000 as postgres_dba_pgvers_17plus \gset
8+
79
select current_setting('server_version_num')::integer >= 130000 as postgres_dba_pgvers_13plus \gset
810

911
select current_setting('server_version_num')::integer >= 100000 as postgres_dba_pgvers_10plus \gset

0 commit comments

Comments
 (0)