open-saas icon indicating copy to clipboard operation
open-saas copied to clipboard

error happened when run wasp db migrate-dev

Open feitian124 opened this issue 11 months ago • 4 comments

i am running postgre by WSL2 in ubuntu 24.04, and i am using docker desktop for windows.

when i run wasp start db, it report below error. but i do not on any process on wsl2 or windows for port 5432.

± |master ?:2 ✗| → wasp start db
✨ Starting a PostgreSQL dev database (based on your Wasp config) ✨

Additional info:
 ℹ Connection URL, in case you might want to connect with external tools:
     postgresql://postgresWaspDevUser:postgresWaspDevPass@localhost:5432/OpenSaaS-bba774dce6
 ℹ Database data is persisted in a docker volume with the following name (useful to know if you will want to delete it at some point):
     wasp-dev-db-OpenSaaS-bba774dce6

...
docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0: listen tcp 0.0.0.0:5432: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
wasp-bin: callCommand: docker run --name wasp-dev-db-OpenSaaS-bba774dce6 --rm --publish 5432:5432 -v wasp-dev-db-OpenSaaS-bba774dce6:/var/lib/postgresql/data --env POSTGRES_PASSWORD=postgresWaspDevPass --env POSTGRES_USER=postgresWaspDevUser --env POSTGRES_DB=OpenSaaS-bba774dce6 postgres (exit 125): failed

i try run bare docker command directly, it works this time.

 2024-12-22 03:03:37 ⌚  ming-r7000 in ~/github/feitian124/wearit/app
± |master ?:2 ✗| → sudo docker run --name wasp-dev-db-OpenSaaS-bba774dce6 --rm --publish 5432:5432 -v wasp-dev-db-OpenSaaS-bba774dce6:/var/lib/postgresql/data --env POSTGRES_PASSWORD=postgresWaspDevPass --env POSTGRES_USER=postgresWaspDevUser --env POSTGRES_DB=OpenSaaS-bba774dce6 postgres

PostgreSQL Database directory appears to contain a database; Skipping initialization

2024-12-21 19:03:43.907 UTC [1] LOG:  starting PostgreSQL 17.2 (Debian 17.2-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-12-21 19:03:43.911 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-12-21 19:03:43.922 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2024-12-21 19:03:43.932 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-12-21 19:03:43.943 UTC [29] LOG:  database system was shut down at 2024-12-21 18:24:50 UTC
2024-12-21 19:03:43.958 UTC [1] LOG:  database system is ready to accept connections

but later steps report error too:

± |master ?:2 ✗| → wasp db migrate-dev
🐝 --- Setting up database... -----------------------------------------------------


[   Db  !] Error: P1001
[   Db  !]
[   Db  !] Can't reach database server at `localhost:5432`
[   Db  !]
[   Db  !] Please make sure your database server is running at `localhost:5432`.
[   Db  !]
[   Db   ] Environment variables loaded from .env
[   Db   ] Prisma schema loaded from ../db/schema.prisma
[   Db   ]
[   Db   ] ✔ Generated Prisma Client (v5.19.1) to ./../../../node_modules/@prisma/client in 116ms
❌ --- [Error] Can not connect to database: ---------------------------------------

The database needs to be running in order to execute this command. You can easily start a managed dev database with `wasp start db`.

i run wasp db studio, i can see my database are runing and can see studio page, obviously my database is running on 5432, not sure why wasp db migrate-dev and wasp start not work.

does anyone met same problem? and also, does this repo support sqlite? thank you.

feitian124 avatar Dec 21 '24 19:12 feitian124

Maybe @martinovicdev, our resident WSL hacker, or @Martinsos know what to do here?

vincanger avatar Jan 07 '25 09:01 vincanger

This could have been caused by the incomplete Docker Desktop installation. Here is a step by step guide based on official Docker guide https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user:

  1. Run sudo groupadd docker If the group exists, continue with the following steps anyways.

  2. Now add your user to docker group by running sudo usermod -aG docker $USER where USER is your username. In my case, it would be sudo usermod -aG docker martinovicdev

  3. Now log out and log back in to the WSL2 shell. Run su -s $USER

  4. Now try out the wasp db start command and it should work.

martinovicdev avatar Jan 12 '25 15:01 martinovicdev

oh nice thanks for this @martinovicdev!

@feitian124 let us know if this solves your issue!

vincanger avatar Jan 13 '25 11:01 vincanger

sorry for delay, i tried today, it report the same error:

 2025-01-19 22:34:56 ⌚  ming-r7000 in ~/github/feitian124/open-saas-demo/app
○ →  wasp start db
✨ Starting a PostgreSQL dev database (based on your Wasp config) ✨

Additional info:
 ℹ Connection URL, in case you might want to connect with external tools:
     postgresql://postgresWaspDevUser:postgresWaspDevPass@localhost:5432/OpenSaaS-f3fba5c43c
 ℹ Database data is persisted in a docker volume with the following name (useful to know if you will want to delete it at some point):
     wasp-dev-db-OpenSaaS-f3fba5c43c

...
docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0: listen tcp 0.0.0.0:5432: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
wasp-bin: callCommand: docker run --name wasp-dev-db-OpenSaaS-f3fba5c43c --rm --publish 5432:5432 -v wasp-dev-db-OpenSaaS-f3fba5c43c:/var/lib/postgresql/data --env POSTGRES_PASSWORD=postgresWaspDevPass --env POSTGRES_USER=postgresWaspDevUser --env POSTGRES_DB=OpenSaaS-f3fba5c43c postgres (exit 125): failed

@martinovicdev what the step 3 purpose?

 2025-01-19 22:37:56 ⌚  ming-r7000 in ~/github/feitian124/open-saas-demo/app
○ → su -s $USER
Password:
su: failed to execute ming: No such file or directory

it also report error.

and thank you for help, you can close this issue since i know this is mainly a enviroment issue, not really close related to wasp, i will try use a real linux desktop instead of wsl2.

feitian124 avatar Jan 19 '25 14:01 feitian124