W
Wasp-lang2mo ago
linus

How do I connect to the postgres db deployed on fly?

I deployed my aspp using wasp deploy fly deploy and i want to see the data in the db, how can I do that?
4 Replies
kapa.ai
kapa.ai2mo ago
Hi @linus. 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 PostgreSQL database deployed on Fly, you can follow these steps: 1. Open a tunnel to your Fly production database using the fly proxy command. Replace <db-name> with the name of your database:
fly proxy 5432 -a <db-name>
fly proxy 5432 -a <db-name>
Keep this terminal tab running and open a new terminal tab for future commands. 2. Get your database name and password. You can get the database name by running:
fly postgres connect -a <db-name>
fly postgres connect -a <db-name>
and then typing:
\l
\l
You'll find your database name there. By convention, it should be server_name_with_underscores. To get the database password, run:
fly ssh console -a <db-name>
fly ssh console -a <db-name>
then
echo $OPERATOR_PASSWORD
echo $OPERATOR_PASSWORD
3. Set the database URL in your .env.server file to point to your production database. Replace <password> and <db_name> with your actual database password and name:
DATABASE_URL=postgres://postgres:<password>@localhost:5432/<db_name>
DATABASE_URL=postgres://postgres:<password>@localhost:5432/<db_name>
For example:
DATABASE_URL=postgres://postgres:myDatabasePassword@localhost:5432/seeding_test_server
DATABASE_URL=postgres://postgres:myDatabasePassword@localhost:5432/seeding_test_server
4. Now you should be connected to your production database. Be careful with the commands you execute since you're connected to the production database. You can test the connection by running wasp db studio. If it connects, the connection works. 5. After you're done, remember to remove the DATABASE_URL from the local .env.server and close the tunnel. For more details, you can refer to this Github issue (https://github.com/wasp-lang/wasp/issues/1464) which provides a detailed workflow on how to seed a production database on Fly. Please note that you should be careful when interacting with your production database to avoid accidentally modifying or deleting important data. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @linus, 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?
linus
linus2mo ago
I don't have a DATABASE_URL set up in the .env.server file, do i need one for production?
MEE6
MEE62mo ago
Wohooo @linus, you just became a Waspeteer level 1!
martinsos
martinsos2mo ago
GitHub
GitHub - wasp-lang/learning-materials: A place to collect some usef...
A place to collect some useful learning materials for Wasp - wasp-lang/learning-materials
Want results from more Discord servers?
Add your server