1

I created a laravel sail project with PostgreSQL then I tried to connect with the server on 3rd party software (TablePlus & Navicat) I got this error message

FATAL:  password authentication failed for user "sail"

This is my docker-compose.yml

    pgsql:
        image: 'postgres:13'
        ports:
            - '${FORWARD_DB_PORT:-5432}:5432'
        environment:
            PGPASSWORD: '${DB_PASSWORD:-secret}'
            POSTGRES_DB: '${DB_DATABASE}'
            POSTGRES_USER: '${DB_USERNAME}'
            POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
        volumes:
            - 'sailpgsql:/var/lib/postgresql/data'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}"]
          retries: 3
          timeout: 5s

And this is my env

DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432
DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=password

This is a fresh install I changed nothing. It's working with MySQL, am I missing something? thank you..

2 Answers2

5

I also ran into this issue after cloning my Laravel Sail project from source control. I found the reason for the error was that I downloaded Sail and started the containers before adding the DB_PASSWORD to my new .env file. Even though this is marked as solved I though I would post this in case this it the reason other people are having this issue.

To fix the error:

  1. Make sure your env variables are set correctly
  2. Recreate the Docker volume containing the database
sail down
docker volume ls
docker volume rm example-app_sailmysql
sail up -d

^ replace "example-app_sailmysql" with the name of your Docker volume

After figuring out all my issues when cloning a Laravel Sail project I made a Gist with the steps to follow. It also contains a script to easily install Composer dependencies to regain access to the Sail binary.

https://gist.github.com/LaurenceRawlings/3b4f801cafb2e683f45a3b573dad868d

2

Turns out port 5432 is already used by another pgsql service on my windows so I just change FORWARD_DB_PORT in my env. silly me