Repository navigation
Use set_config instead of SET LOCAL to avoid Postgres warnings - #294
Open
behruzsaifov wants to merge 1 commit into
Open
behruzsaifov wants to merge 1 commit into
behruzsaifov wants to merge 1 commit into
Conversation
SET LOCAL outside a transaction block makes Postgres log "SET LOCAL can only be used in transaction blocks" on every lock acquisition, even though it works for the rest of the multi-statement command (madelson#90). set_config(..., true) behaves the same way but does not log the warning. The calls are wrapped in a DO block so that the acquire command still returns the lock result as its first result set. Adds a PostgresBehaviorTest case showing that set_config(..., true) behaves like SET LOCAL in the repro from madelson#90. Fixes madelson#289
behruzsaifov
force-pushed
the
postgres-set-config-instead-of-set-local
branch
from
October 21, 2026 10:07
b7abb7c to
507774e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #289.
When the lock is acquired outside a transaction,
SET LOCALmakes Postgres logSET LOCAL can only be used in transaction blockson every acquire, even though it works for the rest of the multi-statement command (#90).This PR replaces the two
SET LOCALstatements inCreateAcquireCommandwithset_config(..., true), which behaves the same way but does not log the warning. The calls are wrapped in aDOblock so that they don't return a result set andExecuteScalarstill reads the lock result.RestoreTimeoutSettingsIfNeededAsyncis unchanged: it only runs inside a transaction, whereSET LOCALdoes not warn.Test
As requested,
PostgresBehaviorTest.TestSetConfigIsLocalBehavesLikeSetLocalOutsideOfTransactionruns the repro from #90 (comment) with bothSET LOCALandset_config(..., true), and checks that:12345ms,'x');0);SET LOCALproduces the warning.I ran the Postgres tests locally (PostgreSQL 18, Debug / net8.0). The new test passes. The tests that fail on my machine fail on
mastertoo:TestDoesNotDetectConnectionBreakViaState(expects exactlyNpgsqlException, PostgreSQL 18 returnsPostgresException), plus cross-process andtoo many clientsfailures from my local setup.