Postgres drops connection when inactive, is this by default?
I'm developing a node app using AdonisJS@5 and on a prolonged inactivity period (more than 5 hours) the database drops the connection, I wanted to know if this is expected and by design on railway
Solution:Jump to solution
Straight up
pool.min: 0
as you said
In my config/database.ts
```typescript
// My other imports...19 Replies
Project ID:
54c2ba8f-05f3-48a7-8347-7fe20afe05a8
54c2ba8f-05f3-48a7-8347-7fe20afe05a8
Nope, we don't "pause" databases (unless you exceed trial limits, which you didn't). Some questions to help narrow this down:
- Are you able to connect to the db externally when this happens?
- Are you pooling connections/prematurely releasing them ahead of next query?
- Can you elaborate on what "drops the connection" mean here? What error are you seeing from your application?
- ^ anything in your database logs on Railway (database -> Logs tab) that would suggest it's dropping connections within similar timestamp ranges?
Are you able to connect to the db externally when this happens?Yeah, the app eventually re-connects after we try to perform 1 request,
Are you pooling connections/prematurely releasing them ahead of next query?I'll have to do some digging because we are using a ORM to handle queries
Can you elaborate on what "drops the connection" mean here? What error are you seeing from your application? ^ anything in your database logs on Railway (database -> Logs tab) that would suggest it's dropping connections within similar timestamp ranges?I'm just digging into this problem so I'm not discarding the posibility of the framework being at fault
👍 could also try increasing conn timeout and see if that helps
Will try that, with the info that the db doesn't drop the connection narrows my problem
Thanks!
would you be using knex or something that uses knex?
adonis uses lucid
https://github.com/adonisjs/lucid
GitHub
GitHub - adonisjs/lucid: AdonisJS SQL ORM. Supports PostgreSQL, MyS...
AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more - GitHub - adonisjs/lucid: AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
Aaand it has
knex
declared as a dependencyread the note from knex
https://knexjs.org/guide/#pool
you'll need a way to pass
pool.min: 0
to knex through lucid
lucid's docs are not great, so I have yet to find out how to do that, but I imagine it wouldn't be hard for you to figure outI totally agree on this one, awesome thank you!
hey where you able to find a way to set pool.min to 0?
Yeah, its on the basic pool config
Solution
Straight up
pool.min: 0
as you said
In my config/database.ts
awsome, and you havent had any issues since?
We just deployed it so I will come back to you in a few hours
sounds good!
Seems like that did the trick
awsome!