Repository navigation
Add sql_notifications connection config option to disable SQL notifications - #56899
Merged
Merged
Conversation
rosa
force-pushed
the
sql-notifier
branch
2 times, most recently
from
March 4, 2026 16:27
c8f6c78 to
6178cd9
Compare
rafaelfranca
force-pushed
the
sql-notifier
branch
4 times, most recently
from
June 4, 2026 21:41
9f76c01 to
2b132a2
Compare
…ations
This might be useful for gems like Solid Cache, where disabling
instrumentation is beneficial for performance and for practical reasons
where you don't care much about the SQL logs. It could be used like
this:
```yml
cache:
adapter: postgresql
database: myapp_cache
sql_notifications: false
```
This introduces a `NullInstrumenter` into
`ActiveSupport::Notifications`, which is a no-op, stateless and
thread-safe instrumenter that just executes blocks without publishing
anything. We don't need to worry about the per-thread registry for this
one.
This new instrumenter is used in the DB adapter when `sql_notifications`
is disabled.
Additionally, this change skips event buffering for async queries when
`sql_notifications` is disabled. We don't need the event buffer or to
swap the instrumenter stored in the isolated execution state.
rafaelfranca
force-pushed
the
sql-notifier
branch
from
June 4, 2026 23:09
2b132a2 to
c1c9a63
Compare
This was referenced Jul 12, 2026
rosa
added a commit
to rails/solid_queue
that referenced
this pull request
Aug 29, 2026
silence_polling only covers the polling queries; heartbeats, semaphores and maintenance still show up in the logs and reach every sql.active_record subscriber, which is what #210 asked to generalize. Rails 8.2 solves this at the connection level with the sql_notifications option (rails/rails#56899), so document that instead of growing our own list of things to silence. See #210. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CACej2M9mLVDwpE3Bk8V41
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.
Motivation / Background
The motivation for this PR came up when discussing suppressing Active Record notifications with @djmb. This is desirable in gems like Solid Cache, where instrumentation might not be needed once a cache deployment is stable. In that case, it might just add overhead and noise.
Solid Cache has an option to disable instrumentation that reaches into Active Record internals, swapping the current per-thread instrumenter with a new instrumenter with an empty fanout as notifier. The problem of this approach, in addition to reaching into internals, is that it requires all the call sites that could trigger AR instrumentation to be wrapped with
disable_instrumentation.We had the idea of improving this and making the possibility available to other gems like Solid Queue, that use separate database connections by default (via
connects_to).Detail
With this change, you can disable instrumentation per connection, as part of the configuration:
This is similar to the
seedsoption added in #53379.This change introduces a
NullInstrumenterintoActiveSupport::Notifications, which is a no-op, stateless and thread-safe instrumenter that just executes blocks without publishing anything. We don't need to worry about the per-thread registry for this one. This new instrumenter is used in the DB adapter whensql_notificationsis disabled.Additionally, this change skips event buffering for async queries when
sql_notificationsis disabled. We don't need the event buffer or to swap the instrumenter stored in the isolated execution state.Checklist
Before submitting the PR, make sure the following are checked:
[Fix #issue-number]