postgresqldartbackendserverpod

Serverpod unable to authenticate with postgres


I have a completely new clean project created with the cli, I.E. serverpod create project_name. But when I run the startup commands for the server, it fails to connect to the database.

I run

$ docker compose up --build --detach
$ dart bin/main.dart

The server continues to spam this error message, over and over again.

Failed to connect to the database. Retrying in 10 seconds. PostgreSQLSeverity.fatal 28P01: password authentication failed for user "postgres"

I made sure I didn't run any docker containers from other projects, the postgres and redis containers comes from this new project but I still face this error.


Solution

  • Turns out I deleted and recreated the project manually but this left a docker volume pending with old data from the previous project.

    To solve this you can simply run the following command from the server project folder.

    docker compose down -v

    This will kill and remove all containers, the -v flag will also make sure to delete any volumes attached to the containers.

    The volume is recreated when you run docker compose up --build --detach with the correct data!


    You can also remove the volume manually if you want by running

    docker volume ls

    This should print all current volumes, there should be a volume with the name <project_name>_server_<project_name>_data where project_name is the name of your project.

    Then delete the volume by running

    docker volume rm <project_name>_server_<project_name>_data

    Make sure to kill the docker containers first or less you will get an error. I.E. docker ps and docker kill <container_id>