Crashed after migration to new DB
I have a project with a Postgres DB and 2 services: one for frontend and one for backend. I migrated to the new DB as Railway requested, and now the backend repository is crashing.
The project is: https://railway.app/project/c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
Railway
Railway
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
Solution:Jump to solution
seems like you hardcoded your database variables somewhere, please use reference variables https://docs.railway.app/guides/variables#referencing-another-services-variable
68 Replies
Project ID:
c28866fd-5fa3-41e6-8ebd-1ab29b18f9c9
did the migration finish without errors?
logs of the crashed service please https://bookmarklets.up.railway.app/log-downloader/
Yes, I actually I checked and it was working well, so I deleted the legacy postgress and then it crashed
Solution
seems like you hardcoded your database variables somewhere, please use reference variables https://docs.railway.app/guides/variables#referencing-another-services-variable
I just used variables in my .env file. Should I changed there or do you mean in Railway service?
use service variables, make sure you are using references.
never use a .env file when on railway, if its in your repo, delete it and add it to your .gitignore please
Yes, I have it in my gitignore, that why I think it doesnt care what I do there. So, where should I use the reference variables?
I think I understand the problem. I have to go to the backend service and paste the new DATABASE_URL that I have in the new Postgres service
Now it is not crashing, but in the app I cant see the products: https://grooveticket.up.railway.app/
GROOVE TICKET
GROOVE TICKET
This seems like a code issue. Your app is starting, maybe it’s having issues pulling from the db?
do you log if the db was connected to successfully?
It just chrashed again
please read the docs i have linked, you should not need to be pasting anything from your postgres service
please use reference variables
I dont understand how to use reference variables
that is what the docs are for, please read the docs i have linked, there is an example
Should I do this
${{ VARIABLENAME }} in the backend serivce or what should I do
please look at the example the docs gives
do not skim read, read the entire section for
Referencing another service's variable
Yes, I already did that, but it keep crushing.
And I also did it for DATABASE_URL
In the backend service there is a variable that there is not in the DB: DB_DEPLOY, so I cant use it as reference and I dont know what should I do
what variable do you use in code to connect to the database?
I have this code:
then you need to name that variable (the left value)
DB_DEPLOY
while keeping the value on the right the sameHi, I am back. I added in the Postgres service the variable DB_DEPLOY with the same value I have in the backend service. But the backend keep crashing.
I was trying to find out why it is not connecting. In the backend service I added variables PGHOST and PGPORT. And I changed the value of NODE_ENV from TEST to PRODUCTION. But it is still failing and crashing.
have you made this change I said? if so, please show me a screenshot
definitely don't show me the rendered value
deleting that because that's your database credentials
show me the raw reference syntax please
what does it mean? Where is it?
do you mean the raw editor?
the edit button, show me the raw value for that variable
If I touch the edit button, you will see the same:
please use variable references like the docs page I linked above showed
please look at the example in the docs page I linked
it has a very clear example
Man, obviously I dont understand. Can you explain me?
you use
DB_DEPLOY
in your code, therefore that is the only variable you need to focus on, I don't know how I could explain it better than the docs do, the example goes pretty in depth in my opinion
have you expanded the example section so it shows you what variable references look like?The docs doesnt explain nothing actually, . I am asking you to help me. According what I understand What I did is the same that there is in the example I saw in the doc
Yes, this:
can you explain the difference because probably I am not seeing it
you have not expanded the example section
please look at the examples under this section
https://docs.railway.app/guides/variables#referencing-another-services-variable
Instead of ${{Postgres.DATABASE_PRIVATE_URL}} should I write:
${{Postgres.DATABASE_PRIVATE_URL}}
or is the same?yes that is the value you want. but are those two options you just asked not the exact same??
yes, looks the same but I wrote the second with `` as in the example
please, please make an effort an try to explain me what I need to do instead of asking me to read a doc that I dont understand
ignore the backticks, those are purely for style formatting
I see this example, but I dont know what I have to in my case.
I have already explained exactly what you needed to do.
you are looking at the wrong example, why?
In postres service I have something similar, but is not the proble:
No man, because I already added the DB_DEPLOY and added a value and is not working, so it is not what I need to do
you did not use references, you hardcoded the actual value
once you are using reference variables we can move on to debugging further, but for now that's what needs to be done
come, please help me. In backend service I am using reference, or I understand I use reference because I have this:
Why it is not a reference variable?
it is a reference variable, but the Postgres service you are referencing does not have a
DB_DEPLOY
variable to reference, so it is an invalid reference.
please look at the example for the correct reference syntax that you need to use
you had the correct value here, use that valueIn the postgres service I have this:
Can you tell me what should I write there if it is not correct?
please remove it, you should not have needed to touch the variables on the postgres service itself
but if I remove that variable in the postgres service, I will not have a riable to refer from backend? So how I will conect?
you need to reference the database url variable
which is?
DATABASE_URL
or DATABASE_PRIVATE_URL
might be easier to choose the first variable.
the example shows you how to use these variables in the reference syntaxcome on!!!! please, help me!!!
I am begging you the answer, dont send me to the example!!!
I dont understand it!!!
you had it right here, just the variable name was wrong (the name on the left)
you where already 90% of the way there
let's focus on this service first, you can see it's name in the top left
Yes, and you same the variable name is wrong. What should be the name_?
your name of the variable should be the same as you use in your code
So I change DATABASE_PRIVATE_URL and put DB_DEPLOY
if you are only talking about the variable name on the left input field, then yes
ok, and then I also change the name in the postgres service and use the variable reference
please do not touch any variables on the postgres service
Finally! It is working
Thanks
no problem!
look your dm
please do not DM people here without asking first
ok sorry