R
Railway4mo 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
Percy4mo ago
Project ID: 3747f720-8c9c-4d81-9b13-1e420ceabd6c
Kurdiez
KurdiezOP4mo 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
Brody4mo 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
KurdiezOP4mo 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
Brody4mo ago
As mentioned before, please do not set the shm size to 30GB, that is not something we can allow.
Kurdiez
KurdiezOP4mo 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
Brody4mo ago
Please go ahead and do that
Kurdiez
KurdiezOP4mo 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
Brody4mo 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
KurdiezOP4mo 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
Brody4mo ago
Please check my first message, you need to be on the legacy runtime.
Kurdiez
KurdiezOP4mo 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
Brody4mo 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
KurdiezOP4mo 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
Brody4mo ago
It doesn't.
Kurdiez
KurdiezOP4mo ago
You just said that in order for the RAILWAY_SHM_SIZE_BYTES="536870912" to take an effect in genie-new-db service, I need to also set the same variable RAILWAY_SHM_SIZE_BYTES="536870912" to the genie-db service. That's how I understood.
Brody
Brody4mo ago
kindly finish reading the second half of this sentence
Kurdiez
KurdiezOP4mo ago
I am really confused now. Do you understand what I've done so far? Because that's exactly what I have already done for genie-new-db and I tested that that didn't solve the problem.
Brody
Brody4mo ago
Looks like you have yet to change it to legacy
No description
Kurdiez
KurdiezOP4mo ago
I had no idea when you said Runtime I was supposed to go to the Settings to change that. You never mentioned that that is a settings in Railway... I just understood as some runtime you have that automatically goes into Legacy mode. My bad. I will change that to Legacy now and redeploy. @Brody Ok that fixed the issue. Thank you. Everything is working now.
Brody
Brody4mo ago
awsome
Kurdiez
KurdiezOP4mo ago
Sorry, had no idea that settings even existed... we never really use Railway because we set it up long time ago and nothing broke until now.
Brody
Brody4mo ago
no worries at all
Kurdiez
KurdiezOP4mo ago
What is the new V2 way of specifying how much shared memory can be allocated? Should I be using that instead ?
Brody
Brody4mo ago
at this time the v2 runtime does not support setting a shm size
Kurdiez
KurdiezOP4mo ago
Ok, so we have no choice. Thanks.
Brody
Brody4mo ago
by the time the legacy runtime is deprecated the v2 runtime will have support for the shm size, so no worries there
Want results from more Discord servers?
Add your server