Failed to initialize database, got error failed to connect to host=xxxxx user=xxxxx database=postgres #9

Closed
opened 2026-02-16 00:19:00 -05:00 by yindo · 8 comments
Owner

Originally created by @ivannguyendev on GitHub (Feb 18, 2025).

When trying to connect to PostgreSQL cloud, encountering authentication error:

[error] failed to initialize database, got error failed to connect to 
`host=xxxxx user=xxxxx database=postgres`: server error 
(FATAL: no pg_hba.conf entry for host "xxxxxx", user "xxxxx", database "postgres", no encryption (SQLSTATE 28000))

Configuration

environment configuration in dify-plugin.yaml:

- name: DB_USERNAME
  valueFrom:
    secretKeyRef:
      name: postgres-credentials
      key: pg-username
- name: DB_PASSWORD
  valueFrom:
    secretKeyRef:
      name: postgres-credentials
      key: pg-password
- name: DB_HOST
  valueFrom:
    secretKeyRef:
      name: postgres-credentials
      key: pg-host
- name: DB_PORT
  valueFrom:
    secretKeyRef:
      name: postgres-credentials
      key: pg-port
- name: DB_DATABASE
  value: dify-plugin
- name: SQLALCHEMY_POOL_SIZE
  value: '20'
- name: DB_PLUGIN_DATABASE
  value: dify-plugin

i find a hardcoded 'postgres' database name here: https://github.com/langgenius/dify-plugin-daemon/blob/main/internal/db/init.go

Originally created by @ivannguyendev on GitHub (Feb 18, 2025). When trying to connect to PostgreSQL cloud, encountering authentication error: ``` [error] failed to initialize database, got error failed to connect to `host=xxxxx user=xxxxx database=postgres`: server error (FATAL: no pg_hba.conf entry for host "xxxxxx", user "xxxxx", database "postgres", no encryption (SQLSTATE 28000)) ``` ### Configuration environment configuration in dify-plugin.yaml: ```yaml - name: DB_USERNAME valueFrom: secretKeyRef: name: postgres-credentials key: pg-username - name: DB_PASSWORD valueFrom: secretKeyRef: name: postgres-credentials key: pg-password - name: DB_HOST valueFrom: secretKeyRef: name: postgres-credentials key: pg-host - name: DB_PORT valueFrom: secretKeyRef: name: postgres-credentials key: pg-port - name: DB_DATABASE value: dify-plugin - name: SQLALCHEMY_POOL_SIZE value: '20' - name: DB_PLUGIN_DATABASE value: dify-plugin ``` i find a hardcoded 'postgres' database name here: https://github.com/langgenius/dify-plugin-daemon/blob/main/internal/db/init.go
yindo added the question label 2026-02-16 00:19:00 -05:00
yindo closed this issue 2026-02-16 00:19:00 -05:00
Author
Owner

@Foglotus commented on GitHub (Feb 21, 2025):

When trying to connect to PostgreSQL cloud, encountering authentication error:

[error] failed to initialize database, got error failed to connect to 
`host=xxxxx user=xxxxx database=postgres`: server error 
(FATAL: no pg_hba.conf entry for host "xxxxxx", user "xxxxx", database "postgres", no encryption (SQLSTATE 28000))

Configuration

environment configuration in dify-plugin.yaml:

  • name: DB_USERNAME
    valueFrom:
    secretKeyRef:
    name: postgres-credentials
    key: pg-username
  • name: DB_PASSWORD
    valueFrom:
    secretKeyRef:
    name: postgres-credentials
    key: pg-password
  • name: DB_HOST
    valueFrom:
    secretKeyRef:
    name: postgres-credentials
    key: pg-host
  • name: DB_PORT
    valueFrom:
    secretKeyRef:
    name: postgres-credentials
    key: pg-port
  • name: DB_DATABASE
    value: dify-plugin
  • name: SQLALCHEMY_POOL_SIZE
    value: '20'
  • name: DB_PLUGIN_DATABASE
    value: dify-plugin
    i find a hardcoded 'postgres' database name here: https://github.com/langgenius/dify-plugin-daemon/blob/main/internal/db/init.go

这个问题可能是因为中间件启动顺序问题,在db还未成功启动的时候,这个服务启动了,临时解决方案是,你可以单独重新restart一下这个容器,这样就能在开始的时候连上db了

@Foglotus commented on GitHub (Feb 21, 2025): > When trying to connect to PostgreSQL cloud, encountering authentication error: > > ``` > [error] failed to initialize database, got error failed to connect to > `host=xxxxx user=xxxxx database=postgres`: server error > (FATAL: no pg_hba.conf entry for host "xxxxxx", user "xxxxx", database "postgres", no encryption (SQLSTATE 28000)) > ``` > > ### Configuration > environment configuration in dify-plugin.yaml: > > - name: DB_USERNAME > valueFrom: > secretKeyRef: > name: postgres-credentials > key: pg-username > - name: DB_PASSWORD > valueFrom: > secretKeyRef: > name: postgres-credentials > key: pg-password > - name: DB_HOST > valueFrom: > secretKeyRef: > name: postgres-credentials > key: pg-host > - name: DB_PORT > valueFrom: > secretKeyRef: > name: postgres-credentials > key: pg-port > - name: DB_DATABASE > value: dify-plugin > - name: SQLALCHEMY_POOL_SIZE > value: '20' > - name: DB_PLUGIN_DATABASE > value: dify-plugin > i find a hardcoded 'postgres' database name here: https://github.com/langgenius/dify-plugin-daemon/blob/main/internal/db/init.go 这个问题可能是因为中间件启动顺序问题,在db还未成功启动的时候,这个服务启动了,临时解决方案是,你可以单独重新restart一下这个容器,这样就能在开始的时候连上db了
Author
Owner

@Scenx commented on GitHub (Mar 3, 2025):

fuck me too im remote pg-rds

@Scenx commented on GitHub (Mar 3, 2025): fuck me too im remote pg-rds
Author
Owner

@leapin-devops commented on GitHub (Mar 3, 2025):

For scenario to use external postgresql, it will automatically try to create a new database with db name specified by "DB_DATABASE". So it will connect to "postgres" (hard-coded) db first, and then execute the create database sql.
Please refer
https://github.com/langgenius/dify-plugin-daemon/blob/main/internal/db/init.go#L14

Suggestion:

  1. add flag to control "create new database" or not.
  2. Add config option "DB_ADMIN_USERNAME", "DB_ADMIN_PASSWORD" since the db admin credential usually differs from application db credential.
@leapin-devops commented on GitHub (Mar 3, 2025): For scenario to use external postgresql, it will automatically try to create a new database with db name specified by "DB_DATABASE". So it will connect to "postgres" (hard-coded) db first, and then execute the create database sql. Please refer https://github.com/langgenius/dify-plugin-daemon/blob/main/internal/db/init.go#L14 Suggestion: 1. add flag to control "create new database" or not. 2. Add config option "DB_ADMIN_USERNAME", "DB_ADMIN_PASSWORD" since the db admin credential usually differs from application db credential.
Author
Owner

@erigo commented on GitHub (Mar 7, 2025):

It has been fixed #58

@erigo commented on GitHub (Mar 7, 2025): It has been fixed #58
Author
Owner

@ke-feng commented on GitHub (Mar 18, 2025):

This is due to PostgreSQL encryption connection enabled, but the daemon try to establish no ssl connection with DB.

@ke-feng commented on GitHub (Mar 18, 2025): This is due to PostgreSQL encryption connection enabled, but the daemon try to establish no ssl connection with DB.
Author
Owner

@mwakayama commented on GitHub (May 13, 2025):

I tried a setup with Azure Container Apps and several managed services (such as Azure Database for PostgreSQL Flexible Server and Redis), but encountered the same issue.

Are there currently any known solutions or workarounds?

@mwakayama commented on GitHub (May 13, 2025): I tried a setup with Azure Container Apps and several managed services (such as Azure Database for PostgreSQL Flexible Server and Redis), but encountered the same issue. Are there currently any known solutions or workarounds?
Author
Owner

@rgaoistheone commented on GitHub (Jun 9, 2025):

jump bump into this , does this fix already ? still got the errors like server error (FATAL: no pg_hba.conf entry for host "172.30.106.71", user "postgres", database "dify_plugin", no encryption (SQLSTATE 28000)

@rgaoistheone commented on GitHub (Jun 9, 2025): jump bump into this , does this fix already ? still got the errors like server error (FATAL: no pg_hba.conf entry for host "172.30.106.71", user "postgres", database "dify_plugin", no encryption (SQLSTATE 28000)
Author
Owner

@41tair commented on GitHub (Jun 11, 2025):

You can refer to this line in the .env.example file to update your environment variables. In most cases, when using a managed database service provided by a cloud provider, this parameter should be set to require.

If the issue persists even after setting it to require, please include the relevant logs and open new issue so we can help investigate further.

@41tair commented on GitHub (Jun 11, 2025): You can refer to [this line](https://github.com/langgenius/dify-plugin-daemon/blob/main/.env.example#L99C1-L99C2) in the .env.example file to update your environment variables. In most cases, when using a managed database service provided by a cloud provider, this parameter should be set to **require**. If the issue persists even after setting it to require, please include the relevant logs and open new issue so we can help investigate further.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-daemon#9