MedusaJS + Postgres Deployment

Hi everyone!

I’m running into some problems trying to deploy MedusaJS with a Postgres database on Fly.io.

I’m comfortable using Fly.io for deploying simple Docker images, but I’m not sure how to get two servers to communicate with each other.

I already have a working Dockerfile and a fly.toml file with (what I think are) the correct settings, and I’ve also deployed a Postgres database on Fly.io. However, I’m unsure how to connect these two services so they can communicate properly.

Does anyone have a step-by-step guide or process for setting up this specific stack?

Hi,

Do you mean you need your app (Medusa) machine to communicate with your Postgres machine? If so and you have deployed those separately but within the same organisation, they are within the same private network. Therefore the app can connect to the database using the private hostname the CLI/dash should have shown when you created the database. The hostname may be like app-name.internal.

Yes, that’s exactly what I mean. I’ve deployed a PostgreSQL database on Fly.io, created a user account, and set up a Fly app for my Medusa application. I also posted all the necessary environment variables, but it’s still not working.

In my case, the hostname is app.flycast rather than an internal one, but I’m having trouble with the step-by-step process. Until now, I’ve only worked with volumes for my apps and haven’t set up PostgreSQL on Fly.io before.

Ok. I’d take it step by step, so first confirm the database is actually running and so can be connected to. Check its status and logs to check all is well.

If so, see if you can connect to it.

If so, then yes the issue must be between the app and postgres. I’d check the app machine’s logs to see where it’s failing. Look for any recent “connection failed”-type message? Or a hostname not resolved? I’d assume Medusa would throw some kind of exception (you may need to enable logs within it - no idea). There should be an error.

I see various other mentions of database issues, but unfortunately no consistent solution e.g

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.