My strapi + postgres sql is always disconnect when idle a long time

I have monitor for a month. I see my service always down with these error LOG: could not receive data from client: Operation timed out It always happen when service idle around for 2 hours later
No description
No description
24 Replies
Percy
Percy8mo ago
Project ID: 04ff73c6-ae95-43b1-a420-8a274e65c9e2
NongBritee (ไบร์ท)
04ff73c6-ae95-43b1-a420-8a274e65c9e2 Hi brody
NongBritee (ไบร์ท)
for currently I have set to 2 let try and I will update you later. Thank bro
No description
Brody
Brody8mo ago
sounds good! needs to be zero when in a docker environment
NongBritee (ไบร์ท)
Hi bro It still have an issue
NongBritee (ไบร์ท)
Railway
Log Explorer
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
Brody
Brody8mo ago
no need for the ping please #🛂|readme #5 show me how you set pool.min to zero
NongBritee (ไบร์ท)
here is my database.js
const path = require('path');

module.exports = ({ env }) => {
const client = env('DATABASE_CLIENT', 'postgres');

const connections = {
postgres: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool(
'DATABASE_SSL_REJECT_UNAUTHORIZED',
true
),
},
schema: env('DATABASE_SCHEMA', 'public'),
},
pool: {
min: env.int('DATABASE_POOL_MIN', 0),
max: env.int('DATABASE_POOL_MAX', 10),
idleTimeoutMillis: env.int('DATABASE_POOL_IDLE_TIMEOUT', Number.MAX_SAFE_INTEGER),
},
},
};

return {
connection: {
client,
...connections[client],
acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 60000),
},
};
};
const path = require('path');

module.exports = ({ env }) => {
const client = env('DATABASE_CLIENT', 'postgres');

const connections = {
postgres: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool(
'DATABASE_SSL_REJECT_UNAUTHORIZED',
true
),
},
schema: env('DATABASE_SCHEMA', 'public'),
},
pool: {
min: env.int('DATABASE_POOL_MIN', 0),
max: env.int('DATABASE_POOL_MAX', 10),
idleTimeoutMillis: env.int('DATABASE_POOL_IDLE_TIMEOUT', Number.MAX_SAFE_INTEGER),
},
},
};

return {
connection: {
client,
...connections[client],
acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 60000),
},
};
};
Brody
Brody8mo ago
can you use this database.js instead? you would need to add the missing service variables to your service first
NongBritee (ไบร์ท)
const path = require('path');

module.exports = ({ env }) => {
const client = env('DATABASE_CLIENT', 'postgres');

const connections = {
postgres: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool(
'DATABASE_SSL_REJECT_UNAUTHORIZED',
true
),
},
schema: env('DATABASE_SCHEMA', 'public'),
},
pool: {
min: 0,
max: 10,
idleTimeoutMillis: Number.MAX_SAFE_INTEGER,
},
},
};

return {
connection: {
client,
...connections[client],
acquireConnectionTimeout: 60000,
},
};
};
const path = require('path');

module.exports = ({ env }) => {
const client = env('DATABASE_CLIENT', 'postgres');

const connections = {
postgres: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool(
'DATABASE_SSL_REJECT_UNAUTHORIZED',
true
),
},
schema: env('DATABASE_SCHEMA', 'public'),
},
pool: {
min: 0,
max: 10,
idleTimeoutMillis: Number.MAX_SAFE_INTEGER,
},
},
};

return {
connection: {
client,
...connections[client],
acquireConnectionTimeout: 60000,
},
};
};
I have updated, let see tomorrow, thank bro Ah i see, sorry for misunderstanding Wow It's really good template, I think it should work let see tomorrow
Brody
Brody8mo ago
sounds good
NongBritee (ไบร์ท)
In railway can I seperate billing on each project depends on my clients I mean I have client A -> for A billing, then client B in my same email account -> then B billing
Brody
Brody8mo ago
railway doesn't offer a way to do that, you'd have to write up your own invoices for your clients manually with invoicing software of your choosing
NongBritee (ไบร์ท)
ok thanks, but any plan in future ?
Brody
Brody8mo ago
there has been talks about it, but it's relatively low priority I will say, if you have clients, you shouldn't be on the hobby plan, you should be on the pro plan
NongBritee (ไบร์ท)
ok I got it, for now It not reach max capacity yet
Brody
Brody8mo ago
if you're still getting settled the hobby plan is fine for now, but running a project with clients is not a hobby use case just letting you know before railway themselves lets you know
NongBritee (ไบร์ท)
Ok, I will be plan for it
No description
Brody
Brody8mo ago
yeah those numbers don't look like what you'd expect from a hobby project tbh either way, let me know if you continue to see errors