From 6a2bfc783edff68fe403a0840093c270875dc620 Mon Sep 17 00:00:00 2001 From: kqr Date: Wed, 22 Jul 2026 09:45:44 +0200 Subject: [PATCH 1/4] fix(trigger): add size threshold to table bloat trigger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Small tables that are frequently rewritten can trivially have > 50 % table bloat even though the absolute size of the bloat is just a few kB. This is the normal, stable, desirable condition for such tables. In those cases, the suggested VACUUM FULL is an incorrect response. The common solution to this is to add a size threshold to the table bloat trigger. There's no strict guidance for such a threshold, and different sources use different thresholds: - pgexperts/pgx_scripts needs 10 MB of table bloat to trigger by default - keithf4/pg_bloat_check lists example triggers of 10 MB and 1 GB - Heroku's documentation suggests a threshold of 100 MB This commit is written with a conservative threshold to catch obvious false alarms without deviating too far from the function's earlier behaviour. --- pgFirstAid.sql | 1 + view_pgFirstAid.sql | 3 ++- view_pgFirstAid_managed.sql | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pgFirstAid.sql b/pgFirstAid.sql index fffb023..5d5bc13 100644 --- a/pgFirstAid.sql +++ b/pgFirstAid.sql @@ -571,6 +571,7 @@ from q where bloat_pct > 50.0 + and bloat_size > pg_size_bytes('10 MB') and schemaname not like all(array['information_schema', 'pg_catalog', 'pg_toast', 'pg_temp%']) order by quote_ident(schemaname), diff --git a/view_pgFirstAid.sql b/view_pgFirstAid.sql index 857dc68..c1e3ec5 100644 --- a/view_pgFirstAid.sql +++ b/view_pgFirstAid.sql @@ -545,7 +545,8 @@ from q where bloat_pct > 50.0 -and schemaname not like all(array['information_schema', 'pg_catalog', 'pg_toast', 'pg_temp%']) + and bloat_size > pg_size_bytes('10 MB') + and schemaname not like all(array['information_schema', 'pg_catalog', 'pg_toast', 'pg_temp%']) order by quote_ident(schemaname), quote_ident(tblname)) diff --git a/view_pgFirstAid_managed.sql b/view_pgFirstAid_managed.sql index e01fd93..17c6e88 100644 --- a/view_pgFirstAid_managed.sql +++ b/view_pgFirstAid_managed.sql @@ -549,7 +549,8 @@ from q where bloat_pct > 50.0 -and schemaname not like all(array['information_schema', 'pg_catalog', 'pg_toast', 'pg_temp%']) + and bloat_size > pg_size_bytes('10 MB') + and schemaname not like all(array['information_schema', 'pg_catalog', 'pg_toast', 'pg_temp%']) order by quote_ident(schemaname), quote_ident(tblname)) From 64735d4bf9c6737b82449dda6a57ca199b6e2b75 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 22 Jul 2026 19:25:47 -0600 Subject: [PATCH 2/4] fix(ci): neon api key empty due to target --- .github/workflows/neon-before-after-validate.yml | 9 +++++---- workflows/neon-before-after-validate.yml | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/neon-before-after-validate.yml b/.github/workflows/neon-before-after-validate.yml index 6544d13..adbd875 100644 --- a/.github/workflows/neon-before-after-validate.yml +++ b/.github/workflows/neon-before-after-validate.yml @@ -32,7 +32,7 @@ # NEON_PROJECT_ID -- from your Neon project's Settings page # # Change files: -# When triggered on pull_request, the workflow auto-discovers .sql files +# When triggered on pull_request_target, the workflow auto-discovers .sql files # under migrations/ and applies them as the change. For app or infra # changes, use workflow_dispatch and either: # (a) pass your SQL files via the `change_files` input, or @@ -42,7 +42,7 @@ name: Neon Before/After Validation on: - pull_request: + pull_request_target: paths: - 'migrations/**' - 'pgFirstAid.sql' @@ -81,6 +81,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha }} - name: Install PostgreSQL client run: | @@ -154,7 +155,7 @@ jobs: echo " Pre-change baseline captured above." echo "" echo " The change being tested:" - echo " ${{ github.event_name == 'pull_request' && format('PR #{0}', github.event.number) || 'manual dispatch' }}" + echo " ${{ github.event_name == 'pull_request_target' && format('PR #{0}', github.event.number) || 'manual dispatch' }}" echo "" echo " Now applying SQL changes..." echo "" @@ -231,7 +232,7 @@ jobs: fi - name: Post PR comment - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'pull_request_target' }} uses: actions/github-script@v7 with: script: | diff --git a/workflows/neon-before-after-validate.yml b/workflows/neon-before-after-validate.yml index 6544d13..adbd875 100644 --- a/workflows/neon-before-after-validate.yml +++ b/workflows/neon-before-after-validate.yml @@ -32,7 +32,7 @@ # NEON_PROJECT_ID -- from your Neon project's Settings page # # Change files: -# When triggered on pull_request, the workflow auto-discovers .sql files +# When triggered on pull_request_target, the workflow auto-discovers .sql files # under migrations/ and applies them as the change. For app or infra # changes, use workflow_dispatch and either: # (a) pass your SQL files via the `change_files` input, or @@ -42,7 +42,7 @@ name: Neon Before/After Validation on: - pull_request: + pull_request_target: paths: - 'migrations/**' - 'pgFirstAid.sql' @@ -81,6 +81,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha }} - name: Install PostgreSQL client run: | @@ -154,7 +155,7 @@ jobs: echo " Pre-change baseline captured above." echo "" echo " The change being tested:" - echo " ${{ github.event_name == 'pull_request' && format('PR #{0}', github.event.number) || 'manual dispatch' }}" + echo " ${{ github.event_name == 'pull_request_target' && format('PR #{0}', github.event.number) || 'manual dispatch' }}" echo "" echo " Now applying SQL changes..." echo "" @@ -231,7 +232,7 @@ jobs: fi - name: Post PR comment - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'pull_request_target' }} uses: actions/github-script@v7 with: script: | From 3e0310ce8a9d0602e6ce1e24b4a0073f133bbbde Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 22 Jul 2026 19:34:27 -0600 Subject: [PATCH 3/4] fix(ci): enable fork PR integration tests via pull_request_target --- .github/workflows/integration-pg-matrix.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-pg-matrix.yml b/.github/workflows/integration-pg-matrix.yml index 638fc89..f059514 100644 --- a/.github/workflows/integration-pg-matrix.yml +++ b/.github/workflows/integration-pg-matrix.yml @@ -2,7 +2,7 @@ name: Python + pgTAP Integration (PG15-PG18) on: workflow_dispatch: - pull_request: + pull_request_target: types: [opened, synchronize] paths: - pgFirstAid.sql @@ -18,7 +18,6 @@ concurrency: jobs: integration: - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false runs-on: [self-hosted, nix, nixos, x86_64-linux] permissions: contents: read @@ -49,6 +48,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha || github.ref }} - name: Add Nix profile paths run: | From 3460fcb6514277c6c9ddde9c80d4686af6f1a518 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 22 Jul 2026 19:38:29 -0600 Subject: [PATCH 4/4] ci: retrigger workflows