PostgreSQL reports an error when running dify from source code following dify docs #15549

Closed
opened 2026-02-21 19:22:15 -05:00 by yindo · 6 comments
Owner

Originally created by @J2M3L2 on GitHub (Jul 21, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

f70ff72a5

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

cd docker
cp middleware.env.example middleware.env
docker compose -f docker-compose.middleware.yaml up -d
docker compose logs -f

✔️ Expected Behavior

without error log

Image

Actual Behavior

with error log

Image
Originally created by @J2M3L2 on GitHub (Jul 21, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [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, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version f70ff72a5 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce ```bash cd docker cp middleware.env.example middleware.env docker compose -f docker-compose.middleware.yaml up -d docker compose logs -f ``` ### ✔️ Expected Behavior without error log <img width="1025" height="373" alt="Image" src="https://github.com/user-attachments/assets/f7c75574-7855-4eca-8ed1-e88eec3478d0" /> ### ❌ Actual Behavior with error log <img width="996" height="731" alt="Image" src="https://github.com/user-attachments/assets/9c767420-41cb-4765-92c0-2f7febb56f03" />
yindo added the 🐞 buggood first issue labels 2026-02-21 19:22:15 -05:00
yindo closed this issue 2026-02-21 19:22:15 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 21, 2025):

Hi @J2M3L2! I'm Dosu and I’m helping the dify team.

The error "role 'root' does not exist" means something is trying to connect to PostgreSQL as the user root, but Dify's default configuration always uses the user postgres, not root. All official config files and Docker Compose templates set POSTGRES_USER and DB_USERNAME to postgres, and there are no references to root in the code or templates (middleware.env.example, docker-compose.middleware.yaml, database config).

This usually happens if an environment variable (like DB_USERNAME or POSTGRES_USER) is set to root somewhere outside the official files—possibly in your shell, CI/CD, or a custom override. Here’s how to fix it:

  1. Check your middleware.env and .env files for any reference to root and make sure POSTGRES_USER and DB_USERNAME are set to postgres.
  2. Run env | grep -i postgres and env | grep -i db_ in your shell to see if anything is exported as root.
  3. If you made changes, remove all containers and volumes with docker compose down -v, then start fresh with the correct env files.
  4. If the problem persists, run docker compose config to see the fully rendered environment for the db service and verify the user is postgres.

The correct values should be:

POSTGRES_USER=postgres
POSTGRES_PASSWORD=difyai123456
POSTGRES_DB=dify

and in your .env:

DB_USERNAME=postgres
DB_PASSWORD=difyai123456
DB_DATABASE=dify

If you follow these steps, the error should disappear. If not, double-check for any local or system-wide overrides.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 21, 2025): <!-- Greeting --> Hi @J2M3L2! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> The error "role 'root' does not exist" means something is trying to connect to PostgreSQL as the user root, but Dify's default configuration always uses the user postgres, not root. All official config files and Docker Compose templates set POSTGRES_USER and DB_USERNAME to postgres, and there are no references to root in the code or templates ([middleware.env.example](https://github.com/langgenius/dify/blob/f70ff72a5856e1648e8f5c3ed031ca123f9a406d/docker/middleware.env.example), [docker-compose.middleware.yaml](https://github.com/langgenius/dify/blob/f70ff72a5856e1648e8f5c3ed031ca123f9a406d/docker/docker-compose.middleware.yaml), [database config](https://github.com/langgenius/dify/blob/f70ff72a5856e1648e8f5c3ed031ca123f9a406d/api/configs/middleware/__init__.py)). This usually happens if an environment variable (like DB_USERNAME or POSTGRES_USER) is set to root somewhere outside the official files—possibly in your shell, CI/CD, or a custom override. Here’s how to fix it: 1. Check your middleware.env and .env files for any reference to root and make sure POSTGRES_USER and DB_USERNAME are set to postgres. 2. Run env | grep -i postgres and env | grep -i db_ in your shell to see if anything is exported as root. 3. If you made changes, remove all containers and volumes with docker compose down -v, then start fresh with the correct env files. 4. If the problem persists, run docker compose config to see the fully rendered environment for the db service and verify the user is postgres. The correct values should be: ``` POSTGRES_USER=postgres POSTGRES_PASSWORD=difyai123456 POSTGRES_DB=dify ``` and in your .env: ``` DB_USERNAME=postgres DB_PASSWORD=difyai123456 DB_DATABASE=dify ``` If you follow these steps, the error should disappear. If not, double-check for any local or system-wide overrides. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/ad5302ae-fb30-41c2-afe7-59835cde3924?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/ad5302ae-fb30-41c2-afe7-59835cde3924?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/ad5302ae-fb30-41c2-afe7-59835cde3924?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/ad5302ae-fb30-41c2-afe7-59835cde3924?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/ad5302ae-fb30-41c2-afe7-59835cde3924?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/ad5302ae-fb30-41c2-afe7-59835cde3924?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/ad5302ae-fb30-41c2-afe7-59835cde3924?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/22749)
Author
Owner

@J2M3L2 commented on GitHub (Jul 21, 2025):

This is because the health check command didn’t specify a user. Just add the appropriate user, for example:

pg_isready -U postgres

Fix it here

@J2M3L2 commented on GitHub (Jul 21, 2025): This is because the health check command didn’t specify a user. Just add the appropriate user, for example: ```bash pg_isready -U postgres ``` Fix it [here](https://github.com/langgenius/dify/blob/f70ff72a5856e1648e8f5c3ed031ca123f9a406d/docker/docker-compose.middleware.yaml#L23)
Author
Owner

@J2M3L2 commented on GitHub (Jul 24, 2025):

Hi @Nov1c444 The issue has not been resolved yet. Why was the issue closed?

Please update the docker-compose.middleware.yaml file to ensure that the PostgreSQL healthcheck command is correct.

You can refer to this file docker-compose.yaml.

@J2M3L2 commented on GitHub (Jul 24, 2025): Hi @Nov1c444 The issue has not been resolved yet. Why was the issue closed? Please update the[ docker-compose.middleware.yaml](https://github.com/langgenius/dify/blob/aca8b836696167fc47b71c5507876897f8f6dd0b/docker/docker-compose.middleware.yaml#L23) file to ensure that the PostgreSQL healthcheck command is correct. You can refer to this file [docker-compose.yaml](https://github.com/langgenius/dify/blob/061d4c8ea0dc082d7dce467bcea3af36c5d5dd94/docker/docker-compose-template.yaml#L120).
Author
Owner

@Nov1c444 commented on GitHub (Jul 24, 2025):

Sorry, I misunderstood what you meant. Are you interested in contributing a PR for this issue?

@Nov1c444 commented on GitHub (Jul 24, 2025): Sorry, I misunderstood what you meant. Are you interested in contributing a PR for this issue?
Author
Owner

@J2M3L2 commented on GitHub (Jul 24, 2025):

Sorry, I misunderstood what you meant. Are you interested in contributing a PR for this issue?

OK

@J2M3L2 commented on GitHub (Jul 24, 2025): > Sorry, I misunderstood what you meant. Are you interested in contributing a PR for this issue? OK
Author
Owner

@J2M3L2 commented on GitHub (Jul 24, 2025):

Sorry, I misunderstood what you meant. Are you interested in contributing a PR for this issue?

Hi @Nov1c444 MR is ready, please take a look.

@J2M3L2 commented on GitHub (Jul 24, 2025): > Sorry, I misunderstood what you meant. Are you interested in contributing a PR for this issue? Hi @Nov1c444 MR is ready, please take a look.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#15549