From: dwsteele (@dwsteele) <noreply+dwsteele@github.com>
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
Subject: Re: [pgaudit/pgaudit] PR #327: Only flush deferred select/dml audit entries for COPY.
Date: Tue, 28 Jul 2026 03:05:54 +0000
Message-ID: <gh-pgaudit-pgaudit-327-c5099456147@github.com> (raw)
In-Reply-To: <gh-pgaudit-pgaudit-327@github.com>
References: <gh-pgaudit-pgaudit-327@github.com>
> ALTER TABLE … ADD FOREIGN KEY via RI_Initial_Check() is just the case someone happened to hit
True enough. I added an additional test in dbcaa9a4.
> Also worth noting this is the third patch over the same design smell ... That said, not sure there is much else to do than identify and fix.
Agreed. We can't have anything like proper design when we are trying to put together the output from a bunch of different hooks that we have little control over. This has always been really tricky.
> One thing that makes me a little nervous about the fix: gating on T_CopyStmt hard-codes "COPY is the only utility that checks perms via the hook but never reaches ExecutorEnd."
Fair enough, and it turns out there is a more general way to do this: PR #328. Rather than enumerating command tags it uses ereport_on_violation to identify permission checks that are not enforcing. A statement's permission check has to error on violation, so anything passing false is a probe, and RI_Initial_Check() appears to be the in-tree caller that does, across all supported branches.
It also covers a case this PR doesn't: the same misattribution happens with pgaudit.log_rows off, through the non-deferred path, and predates the COPY change entirely. With that in, the T_CopyStmt gate is no longer what prevents the misattribution, so I propose dropping the gate change here and keeping only the tests.
To be clear, I'd prefer to go with PR #328 and drop this one entirely.