Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will PgBouncer reuse postgresql session sequence cache?

I want to use postgres sequence with cache CREATE SEQUENCE serial CACHE 100. The goal is to improve performance of 3000 usages per second of SELECT nextval('serial'); by ~500 connection/application threads concurrently.

The issue is that I am doing intensive autoscaling and connections will be disconnected and reconnected occasionally leaving "holes" of unused ids in the sequence each time a connection is disconnected.

Well, the good news might be that I am using a PgBouncer heroku buildpack with transaction pool mode.

My question is: will the transaction pool mode solve the "holes" issues that I described, will it reuse the session in a way that the next application connection will take this session from the pool and continue using the cache of the sequence?

like image 651
naviram Avatar asked Oct 21 '25 03:10

naviram


1 Answers

This depends on the setting of server_reset_query. If you have that set to DISCARD ALL, then sequence caches are discarded before a server connected is handed out to a client. But for transaction pooling, the recommended server_reset_query is empty, so you will be able to reuse sequence caches in that case. You can also use a different DISCARD command, depending on your needs.

like image 156
Peter Eisentraut Avatar answered Oct 22 '25 21:10

Peter Eisentraut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!