DATABASE_URL Splitter
Convert a DATABASE_URL connection string into discrete DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME environment variables — or go the other way and reconstruct a connection URL from those variables. Useful for converting between Heroku / Railway / Render style DATABASE_URL and the multi-variable format expected by some frameworks and infrastructure tools.
How to use the DATABASE_URL Splitter
URL to env vars: paste a DATABASE_URL (e.g. postgresql://user:pass@host:5432/db?sslmode=require) into the top field. The output box fills immediately with one KEY=value line per component: DB_SCHEME, DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME. Query parameters like sslmode become additional DB_SSLMODE vars. Copy the block and paste into your .env file or CI environment.
Env vars to URL: switch mode and paste your individual database variables. The tool reads DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME, and DB_SCHEME (or DB_DRIVER) and assembles the canonical scheme://user:pass@host:port/db URL. Extra DB_* variables not in the core set are appended as query parameters. The output is the DATABASE_URL ready to paste into a platform environment or config file.
Use the Example button to load a sample Postgres URL with credentials and a query param so you can see both directions in action.
DATABASE_URL vs discrete env vars
Twelve-factor app methodology popularised the DATABASE_URL single-string pattern: one environment variable encodes the full connection information. Platforms like Heroku, Render, and Railway provision databases this way — you copy the URL from the dashboard and paste it as a single secret. This makes it trivial to swap databases by changing one variable.
However, many tools and frameworks expect discrete variables: DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME. Kubernetes secrets are often managed as individual key-value pairs. Ansible and Terraform modules expect separate variables. Legacy application configs with separate host/port/user fields cannot consume a URL directly. Splitting is also useful for security: you can log DB_HOST and DB_PORT freely in debug output without risking credential exposure, whereas a full DATABASE_URL must be scrubbed.
Going the other direction — assembling a URL from discrete vars — is common in deployment scripts and Dockerfile entrypoints that construct the connection string at runtime from injected environment variables. This tool handles both directions with correct percent-encoding of special characters in usernames and passwords.
Common use cases
- Heroku/Railway → Kubernetes migration — split a platform-provided DATABASE_URL into individual Kubernetes Secret keys.
- Legacy app config — convert a modern URL into the separate host/port/user/password fields expected by an older configuration format.
- CI/CD secret management — store credentials as separate secrets in GitHub Actions or GitLab CI and reconstruct the URL in a build step.
- Debugging credential encoding — verify that special characters in passwords are correctly percent-encoded by comparing the URL and split values side-by-side.
- Documentation — generate the env-var block for a runbook or onboarding guide from a team database URL without manually parsing it.
Frequently asked questions
Does the round-trip preserve the original URL exactly?
%20 is preserved but uppercase/lowercase hex may differ).How are special characters in passwords handled?
%40 becomes @. When rebuilding env → URL, special characters in the password value are re-encoded: @ becomes %40. This ensures the reconstructed URL is safe to use with URL parsers.What if my URL has no port?
DB_PORT. When rebuilding, if DB_PORT is present it is always included in the URL.Does it work with MySQL and other databases?
mysql://, postgresql://, redis://, etc.) in the DB_SCHEME variable and restores it when rebuilding.Can I use DB_USERNAME instead of DB_USER?
DB_USER and DB_USERNAME, and both DB_PASSWORD and DB_PASS, to cover common naming conventions.