Postgres is very slow
Hello,
I have created a project with a very simple express js app that connects to a postgres server (located in the same project in Railway).
I connect to it and GET four simple posts (only ones in the database) and it takes a wopping 3 seconds to complete!
I therefore try to create the exact same database on Digitalocean with the same data and with the same express js app (hosted on Railway) and the same small query takes 200 ms (still very slow but much much better).
Why is Postgres so slow at Railway? This is unsuable unfortunately.
Project ID: 312b74d3-7061-448f-a297-539dd2bfbb7e
14 Replies
Project ID:
312b74d3-7061-448f-a297-539dd2bfbb7e
are both postgres and your app in the same region?
No, Express is in EU and Postgres in the US so that could absolutely be something. Moving the DB now!
and connect to the database through the private network
mm ok, will try that after
Redeploying now
Moving the DB to correct region made it go from 3 seconds to 96 ms, so my bad. I am sorry about that. Will moving to private network shave off more ms?
definitely could, here is a ping test to the same database through the private network and through the public network
So I just change the database URL?
yeah just change the reference
On it, changed. Redeploying!
That made it worse 🙂 I went from 96ms to 356ms
Changed back and is now 96ms again
what are you measuring exactly?
connection time + query time?
just query time?
??
Time from when I call the endpoint to when it responds (in Postman)
well using the internal network would be on average faster as I've shown, so i suspect there is something not quite right with your setup/code
Well not sure about that since its just a change of url to the database. Same code (that works). Do I need to change anything else in the code to make it work with internal communication or is it just a variable change?
it should just be a variable change, but that makes things worse for you and that's why I've come to the current conclusion of this being a code issue, unfortunately I have no idea how your code is setup or how the queries are ran, you could be making a connection to the database on every api request, no clue