pg.ddx.io  pgaudit/pgaudit GitHub issues and pull requests  
help / color / mirror / Atom feed
From: dwsteele (@dwsteele) <noreply+dwsteele@github.com>
To: pgaudit/pgaudit <noreply+pgaudit-pgaudit@github.com>
Subject: [pgaudit/pgaudit] PR #324: Add exception for fetch statement to stack check.
Date: Fri, 26 Jun 2026 08:46:42 +0000
Message-ID: <gh-pgaudit-pgaudit-324@github.com> (raw)

A fetch statement can be on the stack when another command is executed if the cursor is fetched with a row limit, e.g. JDBC setFetchSize(), which leaves the portal suspended. If this happens the user will get a 'pgaudit stack is not empty' error.

Prevent this by allowing fetch statements on the stack when a new command runs, and add a FETCH case to the stack check test.

inline patch 1: pgaudit.c, t/010_check_stack.pl (+9/-2 lines) download inline-1.patchdiff --git a/pgaudit.c b/pgaudit.c index a1b01d4..1cab0fa 100644 --- a/pgaudit.c +++ b/pgaudit.c @@ -1645,7 +1645,7 @@ pgaudit_ProcessUtility_hook(PlannedStmt *pstmt, { /* * If the stack is not empty then the only allowed entries are call - * statements or open, select, show, and explain cursors + * statements or open, select, show, explain, and fetch cursors */ if (auditEventStack != NULL) { @@ -1656,7 +1656,8 @@ pgaudit_ProcessUtility_hook(PlannedStmt *pstmt, if (nextItem->auditEvent.commandTag != T_SelectStmt && nextItem->auditEvent.commandTag != T_VariableShowStmt && nextItem->auditEvent.commandTag != T_ExplainStmt && - nextItem->auditEvent.commandTag != T_CallStmt) + nextItem->auditEvent.commandTag != T_CallStmt && + nextItem->auditEvent.commandTag != T_FetchStmt) { elog(ERROR, "pgaudit stack is not empty"); } diff --git a/t/010_check_stack.pl b/t/010_check_stack.pl index 8e07121..5563671 100644 --- a/t/010_check_stack.pl +++ b/t/010_check_stack.pl @@ -200,6 +200,12 @@ sub pg_connect stmt => q{CALL pcursor('cc')}, log => qr/AUDIT:.*,CALL,/, }, + { + name => 'FETCH', + setup => ['DECLARE c CURSOR FOR SELECT generate_series(1, 5)'], + stmt => 'FETCH ALL FROM c', + log => qr/AUDIT:.*,FETCH,/, + }, ); # Run each scenario on its own connection: optionally set up state, run the

view thread (7+ messages)  latest in thread

Message-ID: <gh-pgaudit-pgaudit-324@github.com>
Permalink:  ../gh-pgaudit-pgaudit-324@github.com/

 ·  · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox