diff --git a/src/content/docs/hyperdrive/configuration/connect-to-postgres.mdx b/src/content/docs/hyperdrive/configuration/connect-to-postgres.mdx index 33d68e9adee0dce..a7ad69e85e924d8 100644 --- a/src/content/docs/hyperdrive/configuration/connect-to-postgres.mdx +++ b/src/content/docs/hyperdrive/configuration/connect-to-postgres.mdx @@ -161,4 +161,4 @@ To identify active connections to your Postgres database server from Hyperdrive: - Refer to the list of [supported database integrations](/workers/databases/connecting-to-databases/) to understand other ways to connect to existing databases. - Learn more about how to use the [Socket API](/workers/runtime-apis/tcp-sockets) in a Worker. -- Understand the [protocols supported by Workers](/workers/reference/protocols/). +- Understand the [protocols supported by Workers](/workers/reference/protocols/). \ No newline at end of file diff --git a/src/content/docs/hyperdrive/get-started.mdx b/src/content/docs/hyperdrive/get-started.mdx index 1a2287e1e9ee728..67e115acd617242 100644 --- a/src/content/docs/hyperdrive/get-started.mdx +++ b/src/content/docs/hyperdrive/get-started.mdx @@ -195,7 +195,19 @@ export default { // Hyperdrive generates a unique connection string you can pass to // supported drivers, including node-postgres, Postgres.js, and the many // ORMs and query builders that use these drivers. - const sql = postgres(env.HYPERDRIVE.connectionString); + const sql = postgres( + env.HYPERDRIVE.connectionString, + { + // Workers limit the number of concurrent external connections, so be sure to limit + // the size of the local connection pool that postgres.js may establish. + max: 5, + + // If you are using array types in your Postgres schema, it is necessary to fetch + // type information to correctly de/serialize them. However, if you are not using + // those, disabling this will save you an extra round-trip every time you connect. + fetch_types: false, + }, + ); try { // Test query @@ -245,4 +257,4 @@ By finishing this tutorial, you have created a Hyperdrive configuration, a Worke - How to [configure query caching](/hyperdrive/configuration/query-caching/). - [Troubleshooting common issues](/hyperdrive/observability/troubleshooting/) when connecting a database to Hyperdrive. -If you have any feature requests or notice any bugs, share your feedback directly with the Cloudflare team by joining the [Cloudflare Developers community on Discord](https://discord.cloudflare.com). +If you have any feature requests or notice any bugs, share your feedback directly with the Cloudflare team by joining the [Cloudflare Developers community on Discord](https://discord.cloudflare.com). \ No newline at end of file diff --git a/src/content/docs/hyperdrive/observability/troubleshooting.mdx b/src/content/docs/hyperdrive/observability/troubleshooting.mdx index fb12ad92baa7aad..964a3bab234f4c9 100644 --- a/src/content/docs/hyperdrive/observability/troubleshooting.mdx +++ b/src/content/docs/hyperdrive/observability/troubleshooting.mdx @@ -38,7 +38,7 @@ Hyperdrive may also encounter `ErrorResponse` wire protocol messages sent by you | Error Message | Details | Recommended fixes | | ------------------------------------------------------ | ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `Internal error.` | Something is broken on our side. | Check for an ongoing incident affecting Hyperdrive, and contact Cloudflare Support. | +| `Internal error.` | Something is broken on our side. | Check for an ongoing incident affecting Hyperdrive, and contact Cloudflare Support. Retrying the query is appropriate, if it makes sense for your usage pattern. | | `Failed to acquire a connection from the pool.` | Hyperdrive timed out while waiting for a connection to your database, or cannot connect at all. | If you are seeing this error intermittently, your Hyperdrive pool is being exhausted because too many connections are being held open for too long by your worker. This can be caused by a myriad of different issues, but long-running queries/transactions are a common offender. | | `Server connection attempt failed: connection_refused` | Hyperdrive is unable to create new connections to your origin database. | A network firewall or access control list (ACL) is likely rejecting requests from Hyperdrive. Ensure you have allowed connections from the public Internet. Sometimes, this can be caused by your database host provider refusing incoming connections when you go over your connection limit. | @@ -50,4 +50,4 @@ Hyperdrive may also encounter `ErrorResponse` wire protocol messages sent by you ### Improve performance -Having query traffic written as transactions can limit performance. This is because in the case of a transaction, the connection must be held for the duration of the transaction, which limits connection multiplexing. If there are multiple queries per transaction, this can be particularly impactful on connection multiplexing. Where possible, we recommend not wrapping queries in transactions to allow the connections to be shared more aggressively. +Having query traffic written as transactions can limit performance. This is because in the case of a transaction, the connection must be held for the duration of the transaction, which limits connection multiplexing. If there are multiple queries per transaction, this can be particularly impactful on connection multiplexing. Where possible, we recommend not wrapping queries in transactions to allow the connections to be shared more aggressively. \ No newline at end of file diff --git a/src/content/docs/pages/functions/bindings.mdx b/src/content/docs/pages/functions/bindings.mdx index 976cc4dcc29fe51..263a74fdca0fcec 100644 --- a/src/content/docs/pages/functions/bindings.mdx +++ b/src/content/docs/pages/functions/bindings.mdx @@ -834,4 +834,4 @@ When developing locally, add secrets by creating a `.dev.vars` file in the root ``` SECRET_NAME= -``` +``` \ No newline at end of file diff --git a/src/content/docs/workers/tutorials/postgres/index.mdx b/src/content/docs/workers/tutorials/postgres/index.mdx index e1ec2e65f713948..7767f034ea721a1 100644 --- a/src/content/docs/workers/tutorials/postgres/index.mdx +++ b/src/content/docs/workers/tutorials/postgres/index.mdx @@ -195,7 +195,19 @@ import postgres from "postgres"; export default { async fetch(request, env, ctx): Promise { - const sql = postgres(env.DB_URL); + const sql = postgres( + env.DB_URL, + { + // Workers limit the number of concurrent external connections, so be sure to limit + // the size of the local connection pool that postgres.js may establish. + max: 5, + + // If you are using array types in your Postgres schema, it is necessary to fetch + // type information to correctly de/serialize them. However, if you are not using + // those, disabling this will save you an extra round-trip every time you connect. + fetch_types: false, + }, + ); // Query the products table const result = await sql`SELECT * FROM products;`; @@ -368,4 +380,4 @@ Your Worker application is now live and accessible at `.; -``` +``` \ No newline at end of file