Connect to fly.io database
Hello friends, does anybody know how to find the information to connect to the database hosted on fly? I would like to view my production database, even better if i can do this with prisma studio 🙂
2 Replies
Hi @Ertan Köse. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To connect to your Fly.io-hosted database and view your production database (including with Prisma Studio), follow these steps:
1. Get Database Credentials:
- You need your database name and password. You can retrieve these by connecting to your Fly Postgres instance:
- Run:
- Once connected, list databases with:
Your database name will typically be your server app name with underscores (e.g.,
After you’re done, remove the production
my_app_server).
- To get the password, SSH into your database:
Then run:
- Now you have the DB name and password you need to construct your connection string.
2. Open a Tunnel to Your Database:
- On your local machine, run:
This will forward your production database to localhost:5432 on your machine.
3. Set the DATABASE_URL Locally:
- In your .env.server file (or as an environment variable), set:
Replace <password> and <db_name> with the values you obtained above.
4. Open Prisma Studio:
- With the tunnel running and DATABASE_URL set, you can now run:
This will open Prisma Studio connected to your production database.
Important:After you’re done, remove the production
DATABASE_URL from your .env.server to avoid accidentally running commands against your production database in the future.
For more details and a step-by-step example, see the discussion and workflow here: Update the database docs on seeding the production DB on Fly and Discord support thread.
Let me know if you need help with any of the steps!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Ertan Köse, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Hi @Ertan Köse, I believe the bot is correct.
There are two ways to connect to a Fly db:
1. Connect to the database console using
fly pg connect -a app-name
2. Connect to the database using a connection string (you can then use the studio on the production db, or psql, or anything you usually use to interact with databases)
For the second option, the bot is just repeating the stuff it read here:
- https://github.com/wasp-lang/learning-materials?tab=readme-ov-file#running-wasp-db-studio-on-production-db
So just do the steps there and run wasp studio (in your app directory). That should work well