GitHub user dosubot[bot] added a comment to the discussion: How to 
automatically register a database in superset when deploying via Helm?

<!-- Greeting -->
Hi @victor98dl! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the 
superset team.

<!-- Answer -->
You can automate database registration in Superset Helm deployments by using 
the `extraConfigs` section in your `values.yaml`. This lets you provide an 
`import_datasources.yaml` file that defines your database(s), which the init 
job will import automatically on startup—no GUI needed. Here’s how to set it up:

1. **Disable the internal PostgreSQL** by setting `postgresql.enabled: false` 
if you’re using an external database.
2. **Configure your external database connection** under 
`supersetNode.connections` (set `db_host`, `db_port`, `db_user`, `db_name`, and 
reference the password securely via a Kubernetes Secret).
3. **Add an `import_datasources.yaml` under `extraConfigs`**. For example:
   ```yaml
   extraConfigs:
     import_datasources.yaml: |
       databases:
         - database_name: my-external-db
           sqlalchemy_uri: 
postgresql+psycopg2://username:password@host:5432/dbname
           allow_file_upload: true
           allow_ctas: true
           allow_cvas: true
           extra: "{}"
           tables: []
   ```
   You can use environment variables in the URI and inject them securely with 
`extraSecretEnv` or `envFromSecrets` if you don’t want to hardcode credentials.

4. **On deployment or upgrade**, the init job will detect this file and run 
`superset import_datasources`, registering the database automatically 
[[source]](https://github.com/apache/superset/blob/master/docs/docs/installation/kubernetes.mdx).

**Tips:**  
- Make sure your YAML is valid and the `sqlalchemy_uri` is correct.
- If you use secrets for credentials, reference them in the URI as environment 
variables (e.g., `postgresql+psycopg2://{{ .Values.db_user 
}}:${DB_PASS}@host:5432/dbname`).
- The database user must have the necessary permissions.
- If you’re using SSL, append `?sslmode=require` to your URI.

This approach ensures your database is registered every time you deploy or 
redeploy Superset, with no manual steps required 
[[source]](https://github.com/apache/superset/blob/master/helm/superset/values.yaml#L62-L776).

For more details and examples, see the [Superset Helm chart 
documentation](https://github.com/apache/superset/blob/master/docs/docs/installation/kubernetes.mdx).


<!-- 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/68a0a1f9-dd6d-408f-9932-521d089d60bb?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/68a0a1f9-dd6d-408f-9932-521d089d60bb?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/68a0a1f9-dd6d-408f-9932-521d089d60bb?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/68a0a1f9-dd6d-408f-9932-521d089d60bb?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/68a0a1f9-dd6d-408f-9932-521d089d60bb?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/68a0a1f9-dd6d-408f-9932-521d089d60bb?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/68a0a1f9-dd6d-408f-9932-521d089d60bb?feedback_type=other)</sup>

[![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=You%20can%20automate%20database%20registration%20in%20Superset%20Helm%20deployments%20by%20using%20the%20%60extraConfigs%60%20section%20in%20your%20%60values.yaml%60.%20This%20lets%20you%20provide%20an%20%60import_datasources.yaml%60%20file%20that%20defines%20your%20database%28s%29%2C%20which%20the%20init%20job%20will%20import%20automatically%20on%20startup%E2%80%94no%20GUI%20needed.%20Here%E2%80%99s%20how%20to%20set%20it%20up%3A%0A%0A1.%20%2A%2ADisable%20the%20internal%20PostgreSQL%2A%2A%20by%20setting%20%60postgresql.enabled%3A%20false%60%20if%20you%E2%80%99re%20using%20an%20external%20database.%0A2.%20%2A%2AConfigure%20your%20external%20database%20connection%2A%2A%20under%20%60supersetNode.connections%60%20%28set%20%60db_host%60%2C%20%60db_port%60%
 
2C%20%60db_user%60%2C%20%60db_name%60%2C%20and%20reference%20the%20password%20securely%20via%20a%20Kubernetes%20Secret%29.%0A3.%20%2A%2AAdd%20an%20%60import_datasources.yaml%60%20under%20%60extraConfigs%60%2A%2A.%20For%20example%3A%0A%20%20%20%60%60%60yaml%0A%20%20%20extraConfigs%3A%0A%20%20%20%20%20import_datasources.yaml%3A%20%7C%0A%20%20%20%20%20%20%20databases%3A%0A%20%20%20%20%20%20%20%20%20-%20database_name%3A%20my-external-db%0A%20%20%20%20%20%20%20%20%20%20%20sqlalchemy_uri%3A%20postgresql%2Bpsycopg2%3A//username%3Apassword%40host%3A5432/dbname%0A%20%20%20%20%20%20%20%20%20%20%20allow_file_upload%3A%20true%0A%20%20%20%20%20%20%20%20%20%20%20allow_ctas%3A%20true%0A%20%20%20%20%20%20%20%20%20%20%20allow_cvas%3A%20true%0A%20%20%20%20%20%20%20%20%20%20%20extra%3A%20%22%7B%7D%22%0A%20%20%20%20%20%20%20%20%20%20%20tables%3A%20%5B%5D%0A%20%20%20%60%60%60%0A%20%20%20You%20can%20use%20environment%20variables%20in%20the%20URI%20and%20inject%20them%20securely%20with%20%60extraSecretEnv
 
%60%20or%20%60envFromSecrets%60%20if%20you%20don%E2%80%99t%20want%20to%20hardcode%20credentials.%0A%0A4.%20%2A%2AOn%20deployment%20or%20upgrade%2A%2A%2C%20the%20init%20job%20will%20detect%20this%20file%20and%20run%20%60superset%20import_datasources%60%2C%20registering%20the%20database%20automatically%20%5B%5Bsource%5D%5D%28https%3A//github.com/apache/superset/blob/master/docs/docs/installation/kubernetes.mdx%29.%0A%0A%2A%2ATips%3A%2A%2A%20%20%0A-%20Make%20sure%20your%20YAML%20is%20valid%20and%20the%20%60sqlalchemy_uri%60%20is%20correct.%0A-%20If%20you%20use%20secrets%20for%20credentials%2C%20reference%20them%20in%20the%20URI%20as%20environment%20variables%20%28e.g.%2C%20%60postgresql%2Bpsycopg2%3A//%7B%7B%20.Values.db_user%20%7D%7D%3A%24%7BDB_PASS%7D%40host%3A5432/dbname%60%29.%0A-%20The%20database%20user%20must%20have%20the%20necessary%20permissions.%0A-%20If%20you%E2%80%99re%20using%20SSL%2C%20append%20%60%3Fsslmode%3Drequire%60%20to%20your%20URI.%0A%0AThis%20approach%20ensures%20
 
your%20database%20is%20registered%20every%20time%20you%20deploy%20or%20redeploy%20Superset%2C%20with%20no%20manual%20steps%20required%20%5B%5Bsource%5D%5D%28https%3A//github.com/apache/superset/blob/master/helm/superset/values.yaml%23L62-L776%29.%0A%0AFor%20more%20details%20and%20examples%2C%20see%20the%20%5BSuperset%20Helm%20chart%20documentation%5D%28https%3A//github.com/apache/superset/blob/master/docs/docs/installation/kubernetes.mdx%29.)&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/apache/superset/discussions/36443)

GitHub link: 
https://github.com/apache/superset/discussions/36443#discussioncomment-15175873

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to