Rotating database credentials
You can change the connection information and credentials of your Hyperdrive configuration in one of two ways:
- Create a new Hyperdrive configuration with the new connection information, and update your Worker to use the new Hyperdrive configuration.
- Update the existing Hyperdrive configuration with the new connection information and credentials.
Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Hyperdrive configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration, and easily roll back to the previous configuration if needed.
To create a Hyperdrive configuration that connects to an existing PostgreSQL database, use the Wrangler CLI or the Cloudflare dashboard ↗.
# wrangler v3.11 and above requirednpx wrangler hyperdrive create my-updated-hyperdrive --connection-string="<YOUR_CONNECTION_STRING>"
The command above will output the ID of your Hyperdrive. Set this ID in the Wrangler configuration file for your Workers project:
{ "compatibility_flags": [ "nodejs_compat" ], "compatibility_date": "2024-09-23", "hyperdrive": [ { "binding": "HYPERDRIVE", "id": "<your-hyperdrive-id-here>" } ]}
# required for database drivers to functioncompatibility_flags = [ "nodejs_compat" ]compatibility_date = "2024-09-23"
[[hyperdrive]]binding = "HYPERDRIVE"id = "<your-hyperdrive-id-here>"
To update your Worker to use the new Hyperdrive configuration, redeploy your Worker or use gradual deployments.
You can update the configuration of an existing Hyperdrive configuration using the wrangler CLI.
# wrangler v3.11 and above requirednpx wrangler hyperdrive update <HYPERDRIVE_CONFIG_ID> --origin-host <YOUR_ORIGIN_HOST> --origin-password <YOUR_ORIGIN_PASSWORD> --origin-user <YOUR_ORIGIN_USERNAME> --database <YOUR_DATABASE> --origin-port <YOUR_ORIGIN_PORT>