Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sr57's avatar
Level 39

Sail - postgresql - password authentication failed

I use sail for the fist time without knowing docker.

My first test* with mysql works fine but I don't succeed with postgresl.

*test done with a pre-existing app ( https://laravel.com/docs/8.x/sail#installing-sail-into-existing-applications )

My docker.compose.yml

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
#            - mysql
            - pgsql
            - redis
            # - selenium
    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:
            - 'sailpostgresql:/var/lib/postgresql/data'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}"]
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "redis-cli", "ping"]
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - '${FORWARD_MAILHOG_PORT:-1025}:1025'
            - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
#    sailmysql:
#        driver: local
    sailpostgresql:
        driver: local
    sailredis:
        driver: local

For my .env, I tested different user / passwd but did not find any doc ?

...
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432
DB_DATABASE=db1
DB_USERNAME=    ????????????
DB_PASSWORD=   ????????????
...

Thanks in advance.

0 likes
7 replies
martinbean's avatar
Level 80

@sr57 You use whatever username and password you set in those environment variables.

sr57's avatar
Level 39

Hi @martinbean

Thanks for your reply.

That's what I thought but none of my tests worked, so I have to go deeper.

I tested with a fresh install with Sail, it works, have to understand why it does not work with a pre-existing app.

mh71's avatar

What about something like:

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=[the database you created]
DB_USERNAME=postgres
DB_PASSWORD=[the password]
sr57's avatar
Level 39

I did a first test with a different user/login. When I did this 2nd test I forgot that my db was persistent and it was this first user that was active!

Danyil Kolosov's avatar

My configs

DB_CONNECTION=pgsql DB_PASSWORD=1234 DB_DATABASE=db DB_USERNAME=root DB_HOST=pgsql FORWARD_DB_PORT=5432

Other usernames and passwords don't work. I don't know why.

zoidq's avatar

Have you restarted / rebuilt your docker container after changing the authentication details in the .env file?

Please or to participate in this conversation.