Port 5432 is already in use
Is it yet possible to assign a different postgres port for Wasp? Mine's currently in use by a different project, and I don't want to kill it so as to run Wasp.
What's the best way to accomplish this?
6 Replies
Hi @Kynetix. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Currently, Wasp does not have a built-in feature to easily change the default PostgreSQL port (5432) for its managed development database. However, there are a few workarounds and potential solutions being discussed:
1. Use an existing database:
Instead of using Wasp's managed dev database, you can connect to your own PostgreSQL instance by setting the
DATABASE_URL
environment variable. This allows you to use any port you want.
Wasp Docs: Connecting to a Database explains:
"If you want to spin up your own dev database (or connect to an external one), you can tell Wasp about it using the DATABASE_URL
environment variable. Wasp will use the value of DATABASE_URL
as a connection string."
You can set this in your .env.server
file or inline when running Wasp commands:
2. Future improvements:
There are ongoing discussions about improving port selection for Wasp's managed database:
- Github Issue: Allow automatic and/or manual choosing of another port than 5432 discusses potential solutions, including allowing users to specify a custom port or having Wasp automatically find an available port.
- Github Issue: wasp start db
should allow switching port also addresses this issue and suggests defaulting to a non-standard port to avoid conflicts with local PostgreSQL installations.
For now, the best way to accomplish this is to use your own PostgreSQL instance on a different port and connect to it using the DATABASE_URL
environment variable. This gives you the flexibility to choose any port you want while still using Wasp for your project.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Kynetix, 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?I've added the DATABASE_URL to the .env.server, but when I run wasp start db, I get the error "Wasp has detected that you have defined DATABASE_URL env var in your .env.server file.
To have Wasp run the dev database for you, make sure you remove that env var first."
Should I run a different command instead?
could you try run
wasp db migrate-dev
/ wasp start
now?When you set
DATABASE_URL
, that tells Wasp you're using an unmanaged (external) database, so you shouldn't run wasp start db
as long as that variable is set. Just run wasp start
and it'll connect to the database you've configured.Thanks, I figured it out. I didn't know about the DATABASE_URL option before 🙂
Thanks
Thanks for the help @genyus and glad you got it working @Kynetix