Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't not change postgress username and password #9888

Closed
5 tasks done
taowang1993 opened this issue Oct 26, 2024 · 12 comments
Closed
5 tasks done

Can't not change postgress username and password #9888

taowang1993 opened this issue Oct 26, 2024 · 12 comments
Labels
🐞 bug Something isn't working 🤔 cant-reproduce We can not reproduce it or the information is limited

Comments

@taowang1993
Copy link
Contributor

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.10.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

This is a fresh install.

I tried to change:
DB_USERNAME=postgres
DB_PASSWORD=difyai123456

But after I change them and deploy the app, the browser shows:
Internal Server Error

postgres container logs

2024-10-25 22:38:26 The files belonging to this database system will be owned by user "postgres".
2024-10-25 22:38:26 This user must also own the server process.
2024-10-25 22:38:26 
2024-10-25 22:38:26 The database cluster will be initialized with locale "en_US.utf8".
2024-10-25 22:38:26 The default database encoding has accordingly been set to "UTF8".
2024-10-25 22:38:26 The default text search configuration will be set to "english".
2024-10-25 22:38:26 
2024-10-25 22:38:26 Data page checksums are disabled.
2024-10-25 22:38:26 
2024-10-25 22:38:26 fixing permissions on existing directory /var/lib/postgresql/data/pgdata ... ok
2024-10-25 22:38:26 creating subdirectories ... ok
2024-10-25 22:38:26 selecting dynamic shared memory implementation ... posix
2024-10-25 22:38:26 selecting default max_connections ... 100
2024-10-25 22:38:27 selecting default shared_buffers ... 128MB
2024-10-25 22:38:27 selecting default time zone ... UTC
2024-10-25 22:38:27 creating configuration files ... ok
2024-10-25 22:38:30 running bootstrap script ... ok
2024-10-25 22:38:31 performing post-bootstrap initialization ... ok
2024-10-25 22:38:32 syncing data to disk ... ok
2024-10-25 22:38:32 
2024-10-25 22:38:30 sh: locale: not found
2024-10-25 22:38:30 2024-10-26 05:38:30.393 UTC [53] WARNING:  no usable system locales were found
2024-10-25 22:38:32 initdb: warning: enabling "trust" authentication for local connections
2024-10-25 22:38:32 initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
2024-10-25 22:38:32 
2024-10-25 22:38:32 Success. You can now start the database server using:
2024-10-25 22:38:32 
2024-10-25 22:38:32     pg_ctl -D /var/lib/postgresql/data/pgdata -l logfile start
2024-10-25 22:38:32 
2024-10-25 22:38:32 waiting for server to start....2024-10-26 05:38:32.485 UTC [70] LOG:  starting PostgreSQL 15.8 on aarch64-unknown-linux-musl, compiled by gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309, 64-bit
2024-10-25 22:38:32 2024-10-26 05:38:32.486 UTC [70] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-10-25 22:38:32 2024-10-26 05:38:32.505 UTC [73] LOG:  database system was shut down at 2024-10-26 05:38:31 UTC
2024-10-25 22:38:32 2024-10-26 05:38:32.513 UTC [70] LOG:  database system is ready to accept connections
2024-10-25 22:38:32  done
2024-10-25 22:38:32 server started
2024-10-25 22:38:33 2024-10-26 05:38:33.120 UTC [87] FATAL:  role "taowang" does not exist
2024-10-25 22:38:33 CREATE DATABASE
2024-10-25 22:38:33 
2024-10-25 22:38:33 
2024-10-25 22:38:33 /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2024-10-25 22:38:33 
2024-10-25 22:38:33 waiting for server to shut down...2024-10-26 05:38:33.310 UTC [70] LOG:  received fast shutdown request
2024-10-25 22:38:33 .2024-10-26 05:38:33.313 UTC [70] LOG:  aborting any active transactions
2024-10-25 22:38:33 2024-10-26 05:38:33.316 UTC [70] LOG:  background worker "logical replication launcher" (PID 76) exited with exit code 1
2024-10-25 22:38:33 2024-10-26 05:38:33.318 UTC [71] LOG:  shutting down
2024-10-25 22:38:33 2024-10-26 05:38:33.321 UTC [71] LOG:  checkpoint starting: shutdown immediate
2024-10-25 22:38:33 2024-10-26 05:38:33.512 UTC [71] LOG:  checkpoint complete: wrote 920 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.137 s, sync=0.050 s, total=0.194 s; sync files=301, longest=0.002 s, average=0.001 s; distance=4233 kB, estimate=4233 kB
2024-10-25 22:38:33 2024-10-26 05:38:33.540 UTC [70] LOG:  database system is shut down
2024-10-25 22:38:33  done
2024-10-25 22:38:33 server stopped
2024-10-25 22:38:33 
2024-10-25 22:38:33 PostgreSQL init process complete; ready for start up.
2024-10-25 22:38:33 
2024-10-25 22:38:33 2024-10-26 05:38:33.637 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
2024-10-25 22:38:33 2024-10-26 05:38:33.637 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-10-25 22:38:33 2024-10-26 05:38:33.637 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2024-10-25 22:38:33 2024-10-26 05:38:33.640 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-10-25 22:38:33 2024-10-26 05:38:33.656 UTC [92] LOG:  database system was shut down at 2024-10-26 05:38:33 UTC
2024-10-25 22:38:33 2024-10-26 05:38:33.668 UTC [1] LOG:  database system is ready to accept connections
2024-10-25 22:38:34 2024-10-26 05:38:34.234 UTC [102] FATAL:  role "taowang" does not exist
2024-10-25 22:38:35 2024-10-26 05:38:35.307 UTC [109] FATAL:  role "taowang" does not exist
2024-10-25 22:38:36 2024-10-26 05:38:36.373 UTC [116] FATAL:  role "taowang" does not exist
2024-10-25 22:38:37 2024-10-26 05:38:37.421 UTC [123] FATAL:  role "taowang" does not exist
2024-10-25 22:38:38 2024-10-26 05:38:38.475 UTC [130] FATAL:  role "taowang" does not exist
2024-10-25 22:38:39 2024-10-26 05:38:39.567 UTC [137] FATAL:  role "taowang" does not exist
2024-10-25 22:38:40 2024-10-26 05:38:40.648 UTC [144] FATAL:  role "taowang" does not exist
2024-10-25 22:38:41 2024-10-26 05:38:41.690 UTC [150] FATAL:  role "taowang" does not exist
2024-10-25 22:38:42 2024-10-26 05:38:42.725 UTC [157] FATAL:  role "taowang" does not exist
2024-10-25 22:38:43 2024-10-26 05:38:43.755 UTC [164] FATAL:  role "taowang" does not exist
2024-10-25 22:38:44 2024-10-26 05:38:44.839 UTC [171] FATAL:  role "taowang" does not exist
2024-10-25 22:38:45 2024-10-26 05:38:45.892 UTC [178] FATAL:  role "taowang" does not exist
2024-10-25 22:38:46 2024-10-26 05:38:46.973 UTC [184] FATAL:  role "taowang" does not exist
2024-10-25 22:38:48 2024-10-26 05:38:48.015 UTC [191] FATAL:  role "taowang" does not exist
2024-10-25 22:38:49 2024-10-26 05:38:49.079 UTC [198] FATAL:  role "taowang" does not exist
2024-10-25 22:38:50 2024-10-26 05:38:50.117 UTC [205] FATAL:  role "taowang" does not exist
2024-10-25 22:38:51 2024-10-26 05:38:51.273 UTC [212] FATAL:  role "taowang" does not exist
2024-10-25 22:38:52 2024-10-26 05:38:52.351 UTC [219] FATAL:  role "taowang" does not exist
2024-10-25 22:38:53 2024-10-26 05:38:53.416 UTC [226] FATAL:  role "taowang" does not exist
2024-10-25 22:38:54 2024-10-26 05:38:54.476 UTC [233] FATAL:  role "taowang" does not exist
2024-10-25 22:38:55 2024-10-26 05:38:55.579 UTC [240] FATAL:  role "taowang" does not exist
2024-10-25 22:38:56 2024-10-26 05:38:56.656 UTC [247] FATAL:  role "taowang" does not exist
2024-10-25 22:38:57 2024-10-26 05:38:57.730 UTC [254] FATAL:  role "taowang" does not exist
2024-10-25 22:38:58 2024-10-26 05:38:58.810 UTC [261] FATAL:  role "taowang" does not exist
2024-10-25 22:39:00 2024-10-26 05:39:00.042 UTC [269] FATAL:  role "taowang" does not exist
2024-10-25 22:39:01 2024-10-26 05:39:01.126 UTC [276] FATAL:  role "taowang" does not exist
2024-10-25 22:39:01 2024-10-26 05:39:01.523 UTC [277] FATAL:  password authentication failed for user "taowang"
2024-10-25 22:39:01 2024-10-26 05:39:01.523 UTC [277] DETAIL:  Role "taowang" does not exist.
2024-10-25 22:39:01     Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
2024-10-25 22:39:02 2024-10-26 05:39:02.224 UTC [284] FATAL:  role "taowang" does not exist
2024-10-25 22:39:03 2024-10-26 05:39:03.282 UTC [291] FATAL:  role "taowang" does not exist

Do I have to use "postgres" as the user name, and difyai123456 as the password?

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

Copy link

dosubot bot commented Oct 26, 2024

To change the PostgreSQL username and password in a self-hosted Dify setup, you need to update the relevant environment variables in the docker-compose.yaml file. Here are the steps you should follow:

  1. Update the DB_USERNAME and DB_PASSWORD under the application service environment variables:

    DB_USERNAME: <new_username>
    DB_PASSWORD: <new_password>
  2. Update the PGUSER and POSTGRES_PASSWORD under the db service environment variables:

    PGUSER: <new_username>
    POSTGRES_PASSWORD: <new_password>

Make sure to replace <new_username> and <new_password> with your desired new username and password. After making these changes, restart your Docker containers to apply the new configuration [1].

Additionally, ensure that the new role (username) you are using actually exists in the PostgreSQL database. If it doesn't, you will need to create it. You can do this by accessing the PostgreSQL container and using SQL commands to create the role. Here's a basic example of how you might do this:

CREATE ROLE <new_username> WITH LOGIN PASSWORD '<new_password>';

Replace <new_username> and <new_password> with your desired credentials. This should resolve the "role does not exist" error you're encountering.

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the 🐞 bug Something isn't working label Oct 26, 2024
@taowang1993
Copy link
Contributor Author

@StudyingLover
@dosu
Why can't i initialize dify with my desired user name and password?
Is there another config file that defines the value of DB_USERNAME and DB_PASSWORD?
Where is the file that initializes the app with postgress and difyai123456 as the user name and password?

Copy link

dosubot bot commented Oct 26, 2024

The initial configuration for the PostgreSQL username and password in Dify is set in the docker/docker-compose.yaml file. The relevant environment variables are:

DB_USERNAME: ${DB_USERNAME:-postgres}
DB_PASSWORD: ${DB_PASSWORD:-difyai123456}

Additionally, within the PostgreSQL service configuration:

db:
  environment:
    PGUSER: ${PGUSER:-postgres}
    POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-difyai123456}

These configurations set the default PostgreSQL username to postgres and the password to difyai123456 [1].

If you want to use your desired username and password, you need to update these environment variables in the docker-compose.yaml file and ensure that the new role exists in the PostgreSQL database. If the role does not exist, you can create it using SQL commands within the PostgreSQL container.

To continue talking to Dosu, mention @dosu.

@taowang1993
Copy link
Contributor Author

@dosu
No, the variables in the docker compose file is fallback, meaning if I did not provide user name and password in the .env file, docker is going to use the default value in the docker compose file.

Which file is setting the initial postgres user name and password besides the .env file?

On fresh install, I simply changed the default DB_USERNAME and DB_PASSWORD, but it does not work!

It is showing Internal Server Error!

Copy link

dosubot bot commented Oct 26, 2024

Besides the .env file, the initial PostgreSQL username and password in a fresh Dify installation are set in the docker-legacy/docker-compose.yaml file. The relevant section specifies:

db:
  image: postgres:15-alpine
  restart: always
  environment:
    PGUSER: postgres
    POSTGRES_PASSWORD: difyai123456
    POSTGRES_DB: dify

Additionally, the api/.env.example file also sets the initial PostgreSQL username and password:

# PostgreSQL database configuration
DB_USERNAME=postgres
DB_PASSWORD=difyai123456
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=dify

Changing the default DB_USERNAME and DB_PASSWORD can result in an Internal Server Error if these credentials are not updated consistently across all configurations and services that rely on them. Ensure that all dependent services and configurations are updated with the new credentials to avoid connection issues [1][2].

To continue talking to Dosu, mention @dosu.

@taowang1993
Copy link
Contributor Author

@dosu
That is not right. The legacy folder is already deprecated. The env.example file is not baked into the docker image when I built it, because user name and password related variables are not in the Dockerfile.

Copy link

dosubot bot commented Oct 26, 2024

The initial PostgreSQL username and password are set in the docker/docker-compose.yaml file during the Docker image build process. Specifically, they are set in the db service under the environment section:

db:
  image: postgres:15-alpine
  restart: always
  environment:
    PGUSER: ${PGUSER:-postgres}
    POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-difyai123456}
    POSTGRES_DB: ${POSTGRES_DB:-dify}
    PGDATA: ${PGDATA:-/var/lib/postgresql/data/pgdata}

The default username is postgres, and the default password is difyai123456 [1].

If you are encountering issues with changing these credentials, ensure that you update the environment variables in the docker-compose.yaml file and that the new role exists in the PostgreSQL database. If the role does not exist, you will need to create it using SQL commands within the PostgreSQL container.

To continue talking to Dosu, mention @dosu.

@crazywoola crazywoola added the 🤔 cant-reproduce We can not reproduce it or the information is limited label Oct 26, 2024
@crazywoola
Copy link
Member

A fresh install means you need to remove everything in docker/volumns and set the password and username in .env and start it again.

@taowang1993
Copy link
Contributor Author

A fresh install means you need to remove everything in docker/volumns and set the password and username in .env and start it again.

That's exactly what I did.

I am fully aware that the user name and password are stored in docker/volumes directory.

I removed docker/volumes, dowloaded it from dify repo, placed it back to where it was.

I even remove the docker volume by running: docker volume prune -f

Then, I restarted the containers with my user name and password.

But it still does not work.

@kurokobo
Copy link
Contributor

@crazywoola @taowang1993
This should be re-opened, simply we should use POSTGRES_USER instead of PGUSER to specify initial db username

POSTGRES_USER
This optional environment variable is used in conjunction with POSTGRES_PASSWORD to set a user and its password. This variable will create the specified user with superuser power and a database with the same name. If it is not specified, then the default user of postgres will be used.
https://hub.docker.com/_/postgres

@taowang1993
Copy link
Contributor Author

POSTGRES_USER

Thank you very much! I fixed the problem.

I simply changed PGUSER to POSTGRES_USER in both .env and docker-compose.yaml file.

Now, it works perfectly!

@taowang1993
Copy link
Contributor Author

The REDIS_USERNAME is not working either.

It should be REDIS_USER instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🤔 cant-reproduce We can not reproduce it or the information is limited
Projects
None yet
Development

No branches or pull requests

3 participants