ClickHouse Managed Postgres
import { PackageManagers, Render, Steps } from "~/components";
This example connects Hyperdrive to a ClickHouse Managed Postgres database in ClickHouse Cloud. ClickHouse Managed Postgres is a managed PostgreSQL service with local NVMe storage and built-in ClickHouse integration for analytics.
:::note ClickHouse documents the platform availability and current product status of ClickHouse Managed Postgres. For details, refer to the ClickHouse Managed Postgres documentation. :::
Prerequisites
Before you begin, you need:
- An existing ClickHouse Managed Postgres instance.
- A Workers project. Refer to Get started to create one.
- Wrangler version
4.9.0or later, authenticated with your Cloudflare account.
1. Get your connection details
- In the ClickHouse Cloud console, select your Postgres instance and open the Connect menu.
- Select Directly to use the direct PostgreSQL endpoint. Hyperdrive provides connection pooling.
- Copy the hostname, port, database name, username, and password. Use a database role with the permissions your application needs.
- In Settings, download the certificate authority (CA) certificate for this instance. Save it locally as
postgres-ca.pem.
For more information, refer to ClickHouse Managed Postgres connection details.
Your database must accept connections from Hyperdrive. If you restrict inbound connections by IP address, allow the Cloudflare IP address ranges.
2. Create a database configuration
Use the instance CA to verify the database server with Transport Layer Security (TLS). The CA certificate is specific to your Postgres instance.
-
Upload the CA certificate to your Cloudflare account:
-
Copy the certificate ID from the command output. Create a Hyperdrive configuration using that ID and your database connection details:
Replace each placeholder with your values. Use the direct endpoint port, which defaults to
5432. Keep the password and command output private. -
Copy the Hyperdrive configuration ID from the output. Use this ID for the Worker binding in the next section.
The verify-full mode validates the certificate and database hostname. Hyperdrive checks the connection when you create the configuration. For certificate configuration details, refer to SSL/TLS certificates.
This example turns off query caching so reads reach Postgres. Connection pooling still applies. For workloads that can tolerate cached results, refer to Query caching.
3. Use Hyperdrive from your Worker
To test the connection through Hyperdrive, deploy your Worker and request its URL. A successful response contains success: true and the query results.
Next steps
- Configure local development.
- Review supported PostgreSQL features.
- Diagnose connection errors with Troubleshoot and debug.
谢谢你的反馈!