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

[Bug]: zitadel init does not use ZITADEL_DATABASE_POSTGRES_DATABASE #7903

Open
1 of 2 tasks
Yberion opened this issue May 3, 2024 · 3 comments
Open
1 of 2 tasks

[Bug]: zitadel init does not use ZITADEL_DATABASE_POSTGRES_DATABASE #7903

Yberion opened this issue May 3, 2024 · 3 comments
Labels
bug Something isn't working devops storage

Comments

@Yberion
Copy link

Yberion commented May 3, 2024

Preflight Checklist

  • I could not find a solution in the documentation, the existing issues or discussions
  • I have joined the ZITADEL chat

Environment

Self-hosted

Version

v2.51.2

Database

PostgreSQL

Database Version

AWS RDS PostgreSQL 16.2

Describe the problem caused by this bug

Hello,

I'm using an AWS RDS PostgreSQL database and wanted to execute the following command:

ZITADEL_DATABASE_POSTGRES_HOST=aws_rds_endpoint ZITADEL_DATABASE_POSTGRES_PORT=5432 ZITADEL_DATABASE_POSTGRES_DATABASE=zitadel ZITADEL_DATABASE_POSTGRES_USER_USERNAME=zitadeluser ZITADEL_DATABASE_POSTGRES_USER_PASSWORD=zitadeluser ZITADEL_DATABASE_POSTGRES_USER_SSL_MODE=disable ZITADEL_DATABASE_POSTGRES_ADMIN_USERNAME=admin_username ZITADEL_DATABASE_POSTGRES_ADMIN_PASSWORD=admin_password ZITADEL_DATABASE_POSTGRES_ADMIN_SSL_MODE=disable ZITADEL_EXTERNALSECURE=false zitadel init

I'm getting the following error:

INFO[0000] initialization started                        caller="/home/runner/work/zitadel/zitadel/cmd/initialise/init.go:73"
FATA[0000] unable to initialize the database             caller="/home/runner/work/zitadel/zitadel/cmd/initialise/init.go:66" error="ID=DATAB-0pIWD Message=Errors.Database.Connection.Failed Parent=(failed to connect to `host=aws_rds_endpoint user=admin_username database=postgres`: server error (FATAL: database \"postgres\" does not exist (SQLSTATE 3D000)))"

It seems that it uses postgres as database even if I set ZITADEL_DATABASE_POSTGRES_DATABASE=zitadel.

Something to note, I removed the postgres database as I won't use it, maybe I shouldn't?

Edit: I added back the postgre database, but I'm getting the same error, hm, adding back the postgres database and it works (correctly create things in the zitadel database)

To reproduce

  • Create a PostgreSQL database
  • Remove postgres database
  • Try to connect with the previous command (with proper credentials)

Screenshots

No response

Expected behavior

No error, I'm not using the postgres database.

Operating System

Debian 12 ARM64 (both database & zitadel server).

Relevant Configuration

No response

Additional Context

No response

@Yberion Yberion added the bug Something isn't working label May 3, 2024
@icebob
Copy link

icebob commented May 21, 2024

Same issue here.
I'm using Timescale Cloud DB where postgres database is not exist.
Checking #5346 PR, the postgres database name is hard-coded in admin mode.

Would be better a ZITADEL_DATABASE_POSTGRES_ADMIN_DATABASE config where I can overwrite this DB name.

@Camel
Copy link

Camel commented May 23, 2024

Hacky workaround, but for those blocked, just create a DB w/ the name postgres and ensure the admin user can connect to it. All the admin user needs to do is make its connection to that db, so the postgres DB can effectively be a dummy / no-op.

@etinquis
Copy link

etinquis commented May 26, 2024

In addition, the docs at https://zitadel.com/docs/self-hosting/manage/database#postgres say

The admin user is only needed for the installation step but can also be avoided by preparing the necessary requirements:

the zitadel user
the zitadel database
granting required permissions to the zitadel user

CREATE ROLE zitadel LOGIN;
CREATE DATABASE zitadel;
GRANT CONNECT, CREATE ON DATABASE zitadel TO zitadel;

but that doesn't appear to be true, as it tries to connect as the admin user to the 'postgres' db regardless of the ZITADEL_DATABASE_POSTGRES_USER_USERNAME user being preconfigured.

EDIT: I may have missed necessary steps in the phases doc https://zitadel.com/docs/self-hosting/manage/updating_scaling#separating-init-and-setup-from-the-runtime.

EDIT2: Yup, start-from-setup instead of start-from-init bypasses the admin requirement. Disregard the above.

EDITN: Migrations in the setup phase didn't work without manually setting up the schemas and tables in https://github.com/zitadel/zitadel/tree/main/cmd/initialise/sql/postgres as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working devops storage
Projects
Status: 🧐 Investigating
Development

No branches or pull requests

5 participants