database "postgres" does not exist #5480

Closed
opened 2026-02-21 18:11:10 -05:00 by yindo · 2 comments
Owner

Originally created by @djoylove on GitHub (Sep 9, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.73

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

i do this step on my macbook M1

cd docker
cp .env.example .env
docker compose up -d

than i get error

docker-db-1 |
docker-db-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
docker-db-1 |
docker-db-1 |

docker-db-1 | 2024-09-09 08:39:54.594 UTC [1] LOG: starting PostgreSQL 15.8 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309, 64-bit
docker-db-1 | 2024-09-09 08:39:54.595 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
docker-db-1 | 2024-09-09 08:39:54.595 UTC [1] LOG: listening on IPv6 address "::", port 5432
docker-db-1 | 2024-09-09 08:39:54.606 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
docker-db-1 | 2024-09-09 08:39:54.721 UTC [37] LOG: database system was shut down at 2024-09-09 08:29:08 UTC
docker-db-1 | 2024-09-09 08:39:54.794 UTC [1] LOG: database system is ready to accept connections
docker-web-1 | pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)

docker-db-1 | 2024-09-09 08:39:55.421 UTC [47] FATAL: database "postgres" does not exist
docker-db-1 | 2024-09-09 08:40:07.395 UTC [126] FATAL: no pg_hba.conf entry for host "172.18.0.6", user "postgres", database "dify", no encryption
docker-worker-1 | ERROR [root] Database migration failed, error: (psycopg2.OperationalError) connection to server at "db" (172.18.0.5), port 5432 failed: FATAL: no pg_hba.conf entry for host "172.18.0.6", user "postgres", database "dify", no encryption

✔️ Expected Behavior

i can do http://localhost/install to setup

Actual Behavior

error instead

Originally created by @djoylove on GitHub (Sep 9, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.73 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce i do this step on my macbook M1 **cd docker cp .env.example .env docker compose up -d** than i get error docker-db-1 | docker-db-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization docker-db-1 | docker-db-1 | docker-db-1 | 2024-09-09 08:39:54.594 UTC [1] LOG: starting PostgreSQL 15.8 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309, 64-bit docker-db-1 | 2024-09-09 08:39:54.595 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 docker-db-1 | 2024-09-09 08:39:54.595 UTC [1] LOG: listening on IPv6 address "::", port 5432 docker-db-1 | 2024-09-09 08:39:54.606 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" docker-db-1 | 2024-09-09 08:39:54.721 UTC [37] LOG: database system was shut down at 2024-09-09 08:29:08 UTC docker-db-1 | 2024-09-09 08:39:54.794 UTC [1] LOG: database system is ready to accept connections docker-web-1 | pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages) docker-db-1 | 2024-09-09 08:39:55.421 UTC [47] FATAL: database "postgres" does not exist docker-db-1 | 2024-09-09 08:40:07.395 UTC [126] FATAL: no pg_hba.conf entry for host "172.18.0.6", user "postgres", database "dify", no encryption docker-worker-1 | ERROR [root] Database migration failed, error: (psycopg2.OperationalError) connection to server at "db" (172.18.0.5), port 5432 failed: FATAL: no pg_hba.conf entry for host "172.18.0.6", user "postgres", database "dify", no encryption ### ✔️ Expected Behavior i can do http://localhost/install to setup ### ❌ Actual Behavior error instead
yindo added the 🐞 bug🤔 cant-reproduce labels 2026-02-21 18:11:10 -05:00
yindo closed this issue 2026-02-21 18:11:10 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 9, 2024):

Hey there, @djoylove! I'm here to assist you with any bugs, questions, or contributions you have. Let's get to the bottom of this together.

I found some similar issues and discussions that might help you resolve the error "database 'postgres' does not exist":

  1. Unable to connect the postgres database (open) [1]
  2. Permission denied in docker compose up (open) [2]
  3. Fail to start db-1 (postgres:15-alpine) in docker, and fail to finish install (closed) - The suggested solution involves creating a Docker volume and updating the docker-compose.yaml file [3].

To resolve the error "database 'postgres' does not exist" when setting up Dify version 0.73 on a self-hosted Docker environment, ensure that the POSTGRES_DB environment variable is set correctly in your docker-compose.yaml file. By default, it should be set to dify.

Here is the relevant section of the docker-compose.yaml file:

services:
  pgvector:
    image: pgvector/pgvector:pg16
    restart: always
    environment:
      PGUSER: postgres
      POSTGRES_PASSWORD: difyai123456
      POSTGRES_DB: dify
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - ./volumes/pgvector/data:/var/lib/postgresql/data
    ports:
      - "5433:5432"
    healthcheck:
      test: [ "CMD", "pg_isready" ]
      interval: 1s
      timeout: 3s
      retries: 30

Ensure that the POSTGRES_DB environment variable is set to dify or the name of the database you intend to use. If you need to use a different database name, update the POSTGRES_DB variable accordingly and make sure that the database exists.

Additionally, you need to address the pg_hba.conf entry issue. Ensure that your pg_hba.conf file allows connections from the Docker network. You can add the following entry to your pg_hba.conf file:

host    all             all             172.18.0.0/16            md5

This entry allows all hosts in the 172.18.0.0/16 subnet to connect using MD5 authentication.

After making these changes, restart your Docker containers:

  1. Navigate to the Docker directory in the Dify source code:

    cd dify/docker
    
  2. Copy the environment configuration file:

    cp .env.example .env
    
  3. Start the Docker containers:

    • If you have Docker Compose V2, use the following command:

      docker compose up -d
      
    • If you have Docker Compose V1, use the following command:

      docker-compose up -d
      

After executing the command, check if all containers are running successfully:

docker compose ps

This should help you resolve the error and successfully set up Dify [4][5].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 9, 2024): <!-- Greeting --> Hey there, @djoylove! I'm here to assist you with any bugs, questions, or contributions you have. Let's get to the bottom of this together. <!-- Answer --> I found some similar issues and discussions that might help you resolve the error "database 'postgres' does not exist": 1. [Unable to connect the postgres database](https://github.com/langgenius/dify/discussions/7435) (open) <sup>[[1]](https://github.com/langgenius/dify/discussions/7435)</sup> 2. [Permission denied in docker compose up](https://github.com/langgenius/dify/discussions/4822) (open) <sup>[[2]](https://github.com/langgenius/dify/discussions/4822)</sup> 3. [Fail to start db-1 (postgres:15-alpine) in docker, and fail to finish install](https://github.com/langgenius/dify/issues/4126) (closed) - The suggested solution involves creating a Docker volume and updating the `docker-compose.yaml` file <sup>[[3]](https://github.com/langgenius/dify/issues/4126)</sup>. To resolve the error "database 'postgres' does not exist" when setting up Dify version 0.73 on a self-hosted Docker environment, ensure that the `POSTGRES_DB` environment variable is set correctly in your `docker-compose.yaml` file. By default, it should be set to `dify`. Here is the relevant section of the `docker-compose.yaml` file: ```yaml services: pgvector: image: pgvector/pgvector:pg16 restart: always environment: PGUSER: postgres POSTGRES_PASSWORD: difyai123456 POSTGRES_DB: dify PGDATA: /var/lib/postgresql/data/pgdata volumes: - ./volumes/pgvector/data:/var/lib/postgresql/data ports: - "5433:5432" healthcheck: test: [ "CMD", "pg_isready" ] interval: 1s timeout: 3s retries: 30 ``` Ensure that the `POSTGRES_DB` environment variable is set to `dify` or the name of the database you intend to use. If you need to use a different database name, update the `POSTGRES_DB` variable accordingly and make sure that the database exists. Additionally, you need to address the `pg_hba.conf` entry issue. Ensure that your `pg_hba.conf` file allows connections from the Docker network. You can add the following entry to your `pg_hba.conf` file: ``` host all all 172.18.0.0/16 md5 ``` This entry allows all hosts in the `172.18.0.0/16` subnet to connect using MD5 authentication. After making these changes, restart your Docker containers: 1. Navigate to the Docker directory in the Dify source code: ```bash cd dify/docker ``` 2. Copy the environment configuration file: ```bash cp .env.example .env ``` 3. Start the Docker containers: - If you have Docker Compose V2, use the following command: ```bash docker compose up -d ``` - If you have Docker Compose V1, use the following command: ```bash docker-compose up -d ``` After executing the command, check if all containers are running successfully: ```bash docker compose ps ``` This should help you resolve the error and successfully set up Dify <sup>[[4]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml)</sup><sup>[[5]](https://github.com/langgenius/dify-docs/blob/main/en/getting-started/install-self-hosted/docker-compose.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@djoylove commented on GitHub (Sep 9, 2024):

您好,您的邮件我已收到,我会尽快回复你的!

@djoylove commented on GitHub (Sep 9, 2024): 您好,您的邮件我已收到,我会尽快回复你的!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5480