R
Railway2mo ago
Kurdiez

Urgent! Production DB is showing "could not resize shared memory segment" error

Project ID: 3747f720-8c9c-4d81-9b13-1e420ceabd6c We have a Postgres service with Max 32GB. I am getting the following error from postgreswhen querying data from our server.
QueryFailedError: could not resize shared memory segment "/PostgreSQL.2193811760" to 16777216 bytes: No space left on device
QueryFailedError: could not resize shared memory segment "/PostgreSQL.2193811760" to 16777216 bytes: No space left on device
I found a post from the Internet that said I need to add the following environment variable in Railway which is to give 30GB. This has worked in other services before.
RAILWAY_SHM_SIZE_BYTES="32212254720"
RAILWAY_SHM_SIZE_BYTES="32212254720"
As you can see I restarted the service and that's why you see the memory suddenly dropping. I performed the query again from the server and I still get the same error. It seems like there is not enough memory at the OS level still?
No description
Solution:
16777216 bytes is only 16MB. Attempting to set the SHM size to 30GB is not something we are okay with. 500MB for the SHM size would be more than enough....
Jump to solution
27 Replies
Percy
Percy2mo ago
Project ID: 3747f720-8c9c-4d81-9b13-1e420ceabd6c
Kurdiez
Kurdiez2mo ago
There are two Postgres DB services as you can see. The old one is just called genie-db and the new one I am migrating to is called genie-new-db. The old one genie-db has no problem allocating memory and works fine but as soon as I use the genie-new-db , I run into the memory allocation issue. - They both have RAILWAY_SHM_SIZE_BYTES environment variable set. - The old genie-db is version 15.5 with timescale and PostGIS extensions by default - The new genie-new-db is version 16.3 without timescale and PostGIS extensions
Solution
Brody
Brody2mo ago
16777216 bytes is only 16MB. Attempting to set the SHM size to 30GB is not something we are okay with. 500MB for the SHM size would be more than enough. 536870912 Only once you have changed all your shm size variables to 500MB you may switch back to the legacy runtime on your databases for the variable to take effect.
Kurdiez
Kurdiez2mo ago
@Brody I set the env variable according to what you told me
RAILWAY_SHM_SIZE_BYTES="536870912"
RAILWAY_SHM_SIZE_BYTES="536870912"
and then I Redeployed the service. It didn't fix the issue. Running into the exact same problem. As mentioned before, in the same project, I have a DB called genie-db which is the old one and this one ran into exactly the same problems I am having with the genie-new-db. For that one I set it to 30GB
RAILWAY_SHM_SIZE_BYTES="32212254720"
RAILWAY_SHM_SIZE_BYTES="32212254720"
and it fixed the problem and with exactly the same data and SQL query, it is serving up the results without running into a memory problem. As mentioned before, the only difference between the genie-db and genie-new-db on my side really is the Postgres template I used. Is the new Postgres 16.3 template using the RAILWAY_SHM_SIZE_BYTES properly?
No description
Brody
Brody2mo ago
As mentioned before, please do not set the shm size to 30GB, that is not something we can allow.
Kurdiez
Kurdiez2mo ago
Ok, I can also set RAILWAY_SHM_SIZE_BYTES="536870912" for the current DB genie-db service. But I really need the genie-new-db working. It is a blocker for us move forward in production.
Brody
Brody2mo ago
Please go ahead and do that
Kurdiez
Kurdiez2mo ago
On second thought I dont' want to do that to genie-db (the current PROD) because it's working well and serving live traffic right now. I dont' want to disturb the production. genie-new-db is the one that needs to work and that's the one that already has
RAILWAY_SHM_SIZE_BYTES="536870912"
RAILWAY_SHM_SIZE_BYTES="536870912"
as you instructed and as I mentioned here (https://discord.com/channels/713503345364697088/1274291514268188811/1274423235470954586) It's not working still
Brody
Brody2mo ago
A SHM size of 30gb is not something we can allow, it is far more than it needs to be set to please bump that down to 500MB
Kurdiez
Kurdiez2mo ago
I don't think you are understanding what I am saying. I said that whether you say it's not something you support or not, I made that change many months ago and that particular DB genie-db is our current production DB and its memory issue got solved with the 30GB I set and it works. I'm not gonna bump that down to 500MB when it's serving up live users right now in production. What I am saying is we are preparing another new DB to stop using genie-db. I need to get the new DB called genie-new-db working. And this is the one that ran into exact same memory issue and I set that one to
RAILWAY_SHM_SIZE_BYTES="536870912"
RAILWAY_SHM_SIZE_BYTES="536870912"
as you instructed and it's not working. This is the 3rd time I am mentioning this to you.
Brody
Brody2mo ago
Please check my first message, you need to be on the legacy runtime.
Kurdiez
Kurdiez2mo ago
Yes and that's why I set the RAILWAY_SHM_SIZE_BYTES to the service genie-new-db and it's not working. Are you saying both genie-new-db and genie-db services need to have the same RAILWAY_SHM_SIZE_BYTES="536870912" for this to take an effect?
Brody
Brody2mo ago
Only once you have changed all your shm size variables to 500MB you may switch back to the legacy runtime on your databases for the variable to take effect.
Kurdiez
Kurdiez2mo ago
Ah ok. My apologies. I never imagined that an environment variable from one service would affect the other. What an odd user experience that is...
Brody
Brody2mo ago
It doesn't.
Want results from more Discord servers?
Add your server