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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,18 @@ pgFirstAid is designed to be lightweight and safe to run on production systems:
- Typical execution time: <1 second on most databases
- No locking or blocking of user queries

## Testing

- Query and health-check coverage is validated with pgTAP assertions grouped by severity.
- Integration tests cover live runtime behavior, function/view parity, and checks that need concurrent sessions or timing control.
- A coverage guard ensures every `check_name` in `pgFirstAid.sql` is referenced by at least one pgTAP assertion.
- Managed database validation is exercised through the reusable workflow in `.github/workflows/managed-db-validate.yml`.

## Compatibility

- **PostgreSQL 10+** - Fully supported, but only testing on 15+. This will change as versions are deprecated
- **PostgreSQL 10+** - Supported, with active automated validation focused on PostgreSQL 15-18
- **PostgreSQL 9.x** - Most features work (minor syntax adjustments may be needed)
- Works with all PostgreSQL-compatible databases (Amazon RDS, Aurora, Azure Database, etc.)
- Works with PostgreSQL-compatible databases, including Amazon RDS, Aurora, Azure Database for PostgreSQL, GCP Cloud SQL, and self-hosted PostgreSQL

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion pgFirstAid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ insert
select
'MEDIUM' as severity,
'Table Health' as category,
'Tables larger than 100GB' as check_name,
'Tables larger than 50GB' as check_name,
ts.table_schema || '"."' || ts.table_name as object_name,
'The following table' as description,
ts.size_pretty as current_value,
Expand Down
11 changes: 10 additions & 1 deletion testing/pgTAP/03_high_tests.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BEGIN;
SELECT plan(42);
SELECT plan(44);

SELECT ok(
(SELECT count(*) >= 0 FROM pg_firstAid() WHERE check_name = 'Current Blocked/Blocking Queries'),
Expand Down Expand Up @@ -172,6 +172,15 @@ SELECT ok(
'View executes Table with more than 50 columns check'
);

SELECT ok(
(SELECT count(*) >= 0 FROM pg_firstAid() WHERE check_name = 'Tables larger than 50GB'),
'Function executes Tables larger than 50GB check'
);
SELECT ok(
(SELECT count(*) >= 0 FROM v_pgfirstaid WHERE check_name = 'Tables larger than 50GB'),
'View executes Tables larger than 50GB check'
);
Comment on lines +175 to +182
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

New assertions are tautologies and won’t detect name regressions.

count(*) >= 0 always passes, even if 'Tables larger than 50GB' is absent. For this rename-focused PR, these tests should validate definition presence directly.

🔧 Suggested test fix
-SELECT ok(
-    (SELECT count(*) >= 0 FROM pg_firstAid() WHERE check_name = 'Tables larger than 50GB'),
-    'Function executes Tables larger than 50GB check'
-);
-SELECT ok(
-    (SELECT count(*) >= 0 FROM v_pgfirstaid WHERE check_name = 'Tables larger than 50GB'),
-    'View executes Tables larger than 50GB check'
-);
+SELECT ok(
+    position('Tables larger than 50GB' in pg_get_functiondef('pg_firstaid()'::regprocedure)) > 0,
+    'Function definition includes Tables larger than 50GB check'
+);
+SELECT ok(
+    position('Tables larger than 50GB' in pg_get_viewdef('v_pgfirstaid'::regclass, true)) > 0,
+    'View definition includes Tables larger than 50GB check'
+);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SELECT ok(
(SELECT count(*) >= 0 FROM pg_firstAid() WHERE check_name = 'Tables larger than 50GB'),
'Function executes Tables larger than 50GB check'
);
SELECT ok(
(SELECT count(*) >= 0 FROM v_pgfirstaid WHERE check_name = 'Tables larger than 50GB'),
'View executes Tables larger than 50GB check'
);
SELECT ok(
position('Tables larger than 50GB' in pg_get_functiondef('pg_firstaid()'::regprocedure)) > 0,
'Function definition includes Tables larger than 50GB check'
);
SELECT ok(
position('Tables larger than 50GB' in pg_get_viewdef('v_pgfirstaid'::regclass, true)) > 0,
'View definition includes Tables larger than 50GB check'
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@testing/pgTAP/03_high_tests.sql` around lines 175 - 182, The tests use
tautological assertions (count(*) >= 0) that always pass; update the two
assertions to assert the check exists by verifying count(*) > 0 or using EXISTS
for pg_firstAid() and v_pgfirstaid where check_name = 'Tables larger than 50GB'
so they fail if that check/view row is missing; target the tests calling the
pg_firstAid() function and the v_pgfirstaid view and replace the predicate
accordingly to detect name regressions.


SELECT ok(
(SELECT count(*) >= 0 FROM pg_firstAid() WHERE check_name = 'High Connection Count'),
'Function executes High Connection Count check'
Expand Down
2 changes: 1 addition & 1 deletion view_pgFirstAid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ order by
select
'MEDIUM' as severity,
'Table Health' as category,
'Tables larger than 100GB' as check_name,
'Tables larger than 50GB' as check_name,
ts.table_schema || '"."' || ts.table_name as object_name,
'The following table' as description,
ts.size_pretty as current_value,
Expand Down
2 changes: 1 addition & 1 deletion view_pgFirstAid_managed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ order by
select
'MEDIUM' as severity,
'Table Health' as category,
'Tables larger than 100GB' as check_name,
'Tables larger than 50GB' as check_name,
ts.table_schema || '"."' || ts.table_name as object_name,
'The following table' as description,
ts.size_pretty as current_value,
Expand Down
Loading