New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add database configuration to disable advisory locks. #33691
Add database configuration to disable advisory locks. #33691
Conversation
r? @kamipo (@rails-bot has picked a reviewer for you, use r? to override) |
r? @matthewd |
guides/source/configuring.md
Outdated
adapter: postgresql | ||
advisory_locks: false | ||
``` | ||
|
||
If enabled, Active Record will create up to `1000` prepared statements per database connection by default. To modify this behavior you can set `statement_limit` to a different value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a continuation of the preceding discussion of prepared_statements
.
More generally, the above feels a bit heavy-weight for what should be relatively obscure configuration, to me. How about we combine the two: "By default Active Record uses database features like prepared statements and advisory locks. You might need to disable those features if you're using an external connection pooler like PgBouncer: [yaml]"?
@@ -119,6 +126,10 @@ def initialize(connection, logger = nil, config = {}) # :nodoc: | |||
else | |||
@prepared_statements = false | |||
end | |||
|
|||
@advisory_locks = self.class.type_cast_config_to_boolean( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a departure from @prepared_statements
, but I suspect this would be clearer as @advisory_locks_enabled
, particularly for the callers below.
@@ -111,6 +111,7 @@ def supports_virtual_columns? | |||
end | |||
|
|||
def supports_advisory_locks? | |||
return false unless @advisory_locks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just returning @advisory_locks[_enabled]
seems clear enough here
activerecord/CHANGELOG.md
Outdated
|
||
``` | ||
production: | ||
adpater: postgresql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo, and example goes above your name.
62b0da1
to
20bb397
Compare
@matthewd Thank you for reviewing, I've updated the PR as per your comments. |
🤘🏻❤️ |
:logger, | ||
:prepared_statements, | ||
:lock, | ||
:advisory_locks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be :advisory_locks_enabled
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is matching prepared_statements
. I'm fine with either one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instance variable is named @advisory_locks_enabled
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@georgeclaghorn Oops good catch. Thank you for fixing @kamipo 👍
Could this get a version bump (5.2.2 or 5.2.1.1)? Rails repository is very huge to fetch. |
This is only going to be present in Rails 6.0. And no, we only release when we think it is ready, we can't release after every merged PR. |
#31190