Skip to content

Add PGBOUNCER_MAX_PREPARED_STATEMENTS config #199

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

Merged
merged 6 commits into from
May 20, 2025

Conversation

habovh
Copy link
Contributor

@habovh habovh commented May 15, 2025

Following issues I had when using this buildpack with Prisma ORM and prepared statements, I am suggesting these changes to add support for max_prepared_statements configuration on pgbouncer.

As it turns out, it seems that if not set, the default value would be 0. This is an issue when using transaction pooling mode, and prevents from using prepared statements in that case.

Giving control to the user on this important configuration seems appropriate, keeping the default value at zero to avoid breaking changes, basically making it an opt-in config.

I updated the *.tgz files but I'm not sure this was needed as I'm not familiar with how build packs work, maybe the changes to bin/gen-pgbouncer-conf.sh were enough. Let me know so I can update my branch accordingly.

Relevant issues:

@edmorley edmorley requested review from a team, binarycleric and troycoll May 15, 2025 10:48
@edmorley
Copy link
Member

Hi - thank you for the PR!

I updated the *.tgz files but I'm not sure this was needed as I'm not familiar with how build packs work, maybe the changes to bin/gen-pgbouncer-conf.sh were enough. Let me know so I can update my branch accordingly.

I'm not on the Heroku Data team (so I'll leave it to them to properly review), but have occasionally contributed to this buildpack in the past. I don't think regenerating those *.tgz is needed for this change - and also we'd need to run the regeneration ourselves due to the risk of accepting potentially arbitrary binaries. So perhaps omit those changes for now? :-)

@edmorley edmorley requested a review from mble-sfdc May 15, 2025 10:54
@habovh habovh force-pushed the feature/max-prepared-statements branch from 0e3e4bd to a1ba9a7 Compare May 15, 2025 13:15
@habovh
Copy link
Contributor Author

habovh commented May 15, 2025

Hi @edmorley, thanks for your comment! It makes sense not to rely on a third-party to regenerate those. I've removed the commit responsible for updating the *.tgz files. Hopefully this can get reviewed & merged soon!

@habovh habovh force-pushed the feature/max-prepared-statements branch from a1ba9a7 to 3ed987b Compare May 15, 2025 13:18
@mble-sfdc
Copy link
Contributor

@habovh I will take a look at this by the end of the week. Main thing this is missing is tests - adding an extension to gen-pgbouncer-conf.bats to verify the new config is rendered correctly would be 🚀

@habovh
Copy link
Contributor Author

habovh commented May 15, 2025

@mble-sfdc ask and you shall receive. I've updated the test suite to include this new configuration.

@habovh
Copy link
Contributor Author

habovh commented May 16, 2025

Also just so everyone is reassured about the default value, here's an excerpt from the SHOW CONFIG; output when run within the heroku-24 container without the changes introduced by this PR:

            key            |                           value                           |                        default                         | changeable 
---------------------------+-----------------------------------------------------------+--------------------------------------------------------+------------
[...]
 max_client_conn           | 100                                                       | 100                                                    | yes
 max_db_connections        | 0                                                         | 0                                                      | yes
 max_packet_size           | 2147483647                                                | 2147483647                                             | yes
 max_prepared_statements   | 0                                                         | 0                                                      | yes
 max_user_connections      | 0                                                         | 0                                                      | yes
 min_pool_size             | 0                                                         | 0                                                      | yes
[...]

As you can see, the default value for max_prepared_statements is 0. What's odd is that the same pgbouncer version running locally on my Mac has a default value of 200. I'm not sure why that is, but it further increased the confusion when trying to understand what was missing to get prepared statements working in tx pooling mode.

Edit: my local version was indeed 1.24.x with the new default.

@mble-sfdc
Copy link
Contributor

mble-sfdc commented May 16, 2025

@habovh many thanks for the testing. The default value of 200 was added in pgbouncer 1.24.0, so that is likely why you are seeing it - this buildpack currently uses 1.23.1.

You'll need to add an entry to Changelog.md under ## Unreleased, something like:

* Add PGBOUNCER_MAX_PREPARED_STATEMENTS config with default of 0 (@habovh)

Then we should be all good.

@habovh
Copy link
Contributor Author

habovh commented May 16, 2025

@mble-sfdc added the suggested entry to the changelog and updated my previous message as well as you pointed out 1.24 brought this new default.

@binarycleric
Copy link
Contributor

This all looks good to me. @mble-sfdc do you feel good about merging this?

@mble-sfdc mble-sfdc merged commit 944f2ae into heroku:main May 20, 2025
6 checks passed
@mble-sfdc
Copy link
Contributor

mble-sfdc commented May 20, 2025

@habovh we will need to do a formal release, but you can set your app to use the buildpack from main. Thanks for your contribution! 💜

@habovh
Copy link
Contributor Author

habovh commented May 20, 2025

@mble-sfdc awesome, I'll keep using my fork until you guys release an update, but I'm thrilled this got merged!

Happy to contribute and I hope this will help people looking to optimize their db connections ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants