R
Railway15mo ago
Agus

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:
Straight up pool.min: 0 as you said In my config/database.ts ```typescript // My other imports...
Jump to solution
19 Replies
Percy
Percy15mo ago
Project ID: 54c2ba8f-05f3-48a7-8347-7fe20afe05a8
Agus
Agus15mo ago
54c2ba8f-05f3-48a7-8347-7fe20afe05a8
Ray
Ray15mo ago
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?
Agus
Agus15mo ago
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?
{"level":40,"time":1692989569205,"pid":20,"hostname":"railway","name":"axer-backend","msg":"Connection Error: Connection ended unexpectedly"}
{"level":40,"time":1692989569205,"pid":20,"hostname":"railway","name":"axer-backend","msg":"Connection Error: Connection ended unexpectedly"}
I'm just digging into this problem so I'm not discarding the posibility of the framework being at fault
Ray
Ray15mo ago
👍 could also try increasing conn timeout and see if that helps
Agus
Agus15mo ago
Will try that, with the info that the db doesn't drop the connection narrows my problem Thanks!
Brody
Brody15mo ago
would you be using knex or something that uses knex?
Agus
Agus15mo ago
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
Agus
Agus15mo ago
Aaand it has knex declared as a dependency
Brody
Brody15mo ago
read 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 out
Agus
Agus15mo ago
I totally agree on this one, awesome thank you!
Brody
Brody15mo ago
hey where you able to find a way to set pool.min to 0?
Agus
Agus15mo ago
Yeah, its on the basic pool config
Solution
Agus
Agus15mo ago
Straight up pool.min: 0 as you said In my config/database.ts
// My other imports

const databaseConfig: DatabaseConfig = {
connections: {
pg: {
/// Rest of my config
pool: {
min: 0,
}
}
};
// My other imports

const databaseConfig: DatabaseConfig = {
connections: {
pg: {
/// Rest of my config
pool: {
min: 0,
}
}
};
Brody
Brody15mo ago
awsome, and you havent had any issues since?
Agus
Agus15mo ago
We just deployed it so I will come back to you in a few hours
Brody
Brody15mo ago
sounds good!
Agus
Agus15mo ago
Seems like that did the trick
Brody
Brody15mo ago
awsome!
Want results from more Discord servers?
Add your server