PostgreSQL Transaction Pooling vs Session Pooling

b-e-a-f
HOBBY

3 months ago

Hello, I'm currently trying to use Bun + ElysiaJS (adding this context in case anyone else runs into this issue). I'm running into an interesting error:
prepared statement ";.string.string" already exists

I actually reached out to the Bun team initially because I had assumed maybe it was a Bun issue.
https://github.com/oven-sh/bun/issues/17173

However, they've asked me whether or not I'm using transaction pooling or session pooling. I'm genuinely not sure what the default is set to for railway, and this is not a searchable setting on my database. What is the default for Railway's PostgreSQL db? Where can I find this in the future?

Also adding the nixpacks tag since it is the default for Railway's postgresql databases.

Solved

0 Replies

b-e-a-f
HOBBY

3 months ago

c74d4143-faff-4947-823a-6f31b414bdf5


3 months ago

Afaik the default postgres service doesn't include any type of connection pooling functionality so that's maybe why it's failing since Bun may be not closing/opening connections properly? Or maybe it's related to Bun using prepared statements by default?

But I'm just guessing here and I would try to deploy a Pgbouncer in front of your postgres DB (https://railway.com/template/OpUzwe, it's very lightweight) together with the suggested config in the gh issue: prepare: false


b-e-a-f
HOBBY

3 months ago

I like this idea actually, and it might be the solution. I think what you mean to say (or maybe I misinterpreted) is: if I do use PgBouncer then I likely will not have to set prepare: false. Because I can setup PgBouncer to do session pooling. Does that sound right to you?


3 months ago

Yep! But if it doesn't work with just PgBouncer you can also try adding that config


b-e-a-f
HOBBY

3 months ago

I'm going to try this and get back to you. If it works I'll add it to the github issue so other people can find this solution!


b-e-a-f
HOBBY

3 months ago

Looks like I'm back to not being able to connect to my database, after adding PgBouncer and restarting :/
https://discord.com/channels/713503345364697088/1365619106249838613


b-e-a-f
HOBBY

3 months ago

34386048:error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT:..\..\third_party\boringssl\src\crypto\fipsmodule\cipher\e_[aes.c.inc:1065](aes.c.inc:1065):


3 months ago

Did u restart it or did u redeploy?


3 months ago

Do you have any data on it? Otherwise you can deploy a new one and point pgbouncer to it


3 months ago

Also make sure to follow the instructions at the bottom of the Pgbouncer template page


b-e-a-f
HOBBY

3 months ago

Yeah it unfortunately has nothing to do with PgBouncer. Last time I restarted my db it did this as well.


b-e-a-f
HOBBY

3 months ago

I redeployed and restarted several times <:Sadge:762395417526403113>


b-e-a-f
HOBBY

3 months ago

Hey again 😅, still can't access my database. Is this something that we can resolve?


b-e-a-f
HOBBY

3 months ago

Okay server back after restarting & redeploying several times


3 months ago

Can you confirm that the pgbouncer and the bun queries are working as intended?


3 months ago

Sorry for not being of much help with this bug, never seen this issue tbh.


b-e-a-f
HOBBY

3 months ago

Adding PGBouncer didn't fix the issue :(. I am starting to believe it's a bun issue. I tried deploying with prepare: false and now my project crashes.

https://github.com/oven-sh/bun/issues/17173#issuecomment-2847477067


b-e-a-f
HOBBY

3 months ago

Oh it seems my server is running bun v1.1.43 …. Maybe that's the issue


3 months ago

You can also try explaining that you are just running postgres with ssl enabled since that's what Railway deploys



b-e-a-f
HOBBY

3 months ago

Hmm. Okay. Do you know the easiest way to update bun to latest without having to edit nixpacks configurations? If I have to run bun upgrade somewhere where would I do that?



b-e-a-f
HOBBY

3 months ago

<:SadCat:1065694982826102804>


3 months ago

oh, you're using nixpacks?


b-e-a-f
HOBBY

3 months ago

Yeah, it's the default.


3 months ago

what about 🌠 Railpack 🌠? https://railpack.com/languages/node/#bun


3 months ago

the new kid in town


b-e-a-f
HOBBY

3 months ago

Ohhhhh this has what I'm looking for too. You can set the version of bun in a variable


b-e-a-f
HOBBY

3 months ago

Ahhhh!!! It worked


b-e-a-f
HOBBY

3 months ago

nixpacks is using a really old version of bun


b-e-a-f
HOBBY

3 months ago

Hey thanks @Medim for your help, I think swapping to railpack is the solution for now. I also commented on the issue in case anyone else is running bun on railway.


3 months ago

Everything works fine now?


b-e-a-f
HOBBY

3 months ago

Yeah. I'm also just going to keep PGBouncer because bun docs say to use it.


b-e-a-f
HOBBY

3 months ago

It may be unnecessary


b-e-a-f
HOBBY

3 months ago

!s


3 months ago

cool! Can I mark this thread as solved?


b-e-a-f
HOBBY

3 months ago

Yes please!


3 months ago

!s


Status changed to Solved medim 3 months ago