Repository navigation
thomasgauvin: update docs for cache status volatile, stable functions #28536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
9f19d13
b5cc02d
86539f4
588ca6e
3bbe77a
cec765c
4ed515e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| title: Queries using STABLE PostgreSQL functions are no longer cached | ||
| description: Hyperdrive marks queries containing STABLE PostgreSQL functions as uncacheable, preventing stale cached results. | ||
| products: | ||
| - hyperdrive | ||
| date: 2026-02-13 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note - needs new date - also for file name |
||
| --- | ||
|
|
||
| Hyperdrive treats queries containing PostgreSQL `STABLE` functions as uncacheable, in addition to `VOLATILE` functions. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add "now"? - Hyperdrive now treats |
||
|
|
||
| Previously, only functions that PostgreSQL categorizes as `VOLATILE` (for example, `RANDOM()`, `LASTVAL()`) were detected as uncacheable. `STABLE` functions (for example, `NOW()`, `CURRENT_TIMESTAMP`, `CURRENT_DATE`) were incorrectly allowed to be cached. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth linking to this? - https://www.postgresql.org/docs/current/xfunc-volatility.html Or something like it? |
||
|
|
||
| Because `STABLE` functions can return different results across different SQL statements within the same transaction, caching their results could serve stale or incorrect data. This change aligns Hyperdrive's caching behavior with PostgreSQL's function volatility semantics. | ||
|
|
||
| If your queries use `STABLE` functions and you were relying on them being cached, move the function call to your application code and pass the result as a query parameter. For example, instead of `WHERE created_at > NOW()`, compute the timestamp in your Worker and pass it as `WHERE created_at > $1`. | ||
|
|
||
| Hyperdrive uses text-based pattern matching to detect uncacheable functions. References to function names like `NOW()` in SQL comments also cause the query to be marked as uncacheable. | ||
|
|
||
| For more information, refer to [Query caching](/hyperdrive/concepts/query-caching/) and [Troubleshoot and debug](/hyperdrive/observability/troubleshooting/). | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,15 +15,15 @@ | |||||
|
|
||||||
| | Error Code | Details | Recommended fixes | | ||||||
| | ---------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||||||
| | `2008` | Bad hostname. | Hyperdrive could not resolve the database hostname. Confirm it exists in public DNS. | | ||||||
|
Check warning on line 18 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
| | `2009` | The hostname does not resolve to a public IP address, or the IP address is not a public address. | Hyperdrive can only connect to public IP addresses. Private IP addresses, like `10.1.5.0` or `192.168.2.1`, are not currently supported. | | ||||||
|
Check warning on line 19 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
| | `2010` | Cannot connect to the host:port. | Hyperdrive could not route to the hostname: ensure it has a public DNS record that resolves to a public IP address. Check that the hostname is not misspelled. | | ||||||
|
Check warning on line 20 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
| | `2011` | Connection refused. | A network firewall or access control list (ACL) is likely rejecting requests from Hyperdrive. Ensure you have allowed connections from the public Internet. | | ||||||
|
Check warning on line 21 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
| | `2012` | TLS (SSL) not supported by the database. | Hyperdrive requires TLS (SSL) to connect. Configure TLS on your database. | | ||||||
|
Check warning on line 22 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
| | `2013` | Invalid database credentials. | Ensure your username is correct (and exists), and the password is correct (case-sensitive). | | ||||||
|
Check warning on line 23 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
| | `2014` | The specified database name does not exist. | Check that the database (not table) name you provided exists on the database you are asking Hyperdrive to connect to. | | ||||||
|
Check warning on line 24 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
| | `2015` | Generic error. | Hyperdrive failed to connect and could not determine a reason. Open a support ticket so Cloudflare can investigate. | | ||||||
|
Check warning on line 25 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
| | `2016` | Test query failed. | Confirm that the user Hyperdrive is connecting as has permissions to issue read and write queries to the given database. | | ||||||
|
Check warning on line 26 in src/content/docs/hyperdrive/observability/troubleshooting.mdx
|
||||||
|
|
||||||
| ### Failure to connect | ||||||
|
|
||||||
|
|
@@ -60,9 +60,17 @@ | |||||
| | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | | ||||||
| | `Uncaught Error: No such module "node:<module>"` | Your Cloudflare Workers project or a library that it imports is trying to access a Node module that is not available. | Enable [Node.js compatibility](/workers/runtime-apis/nodejs/) for your Cloudflare Workers project to maximize compatibility. | | ||||||
|
|
||||||
| ### Driver errors | ||||||
| ### Uncached queries | ||||||
|
|
||||||
| If your queries are not being cached despite Hyperdrive having caching enabled, check the following: | ||||||
|
|
||||||
| **Stable or volatile PostgreSQL functions in your query**: Queries that contain PostgreSQL functions categorized as `STABLE` or `VOLATILE` are not cacheable. Common examples include `NOW()`, `CURRENT_TIMESTAMP`, `CURRENT_DATE`, `RANDOM()`, and `LASTVAL()`. To resolve this, move the function call to your application code and pass the result as a query parameter. For example, instead of `WHERE created_at > NOW()`, compute the timestamp in your Worker and pass it as a parameter: `WHERE created_at > $1`. Refer to [Query caching](/hyperdrive/concepts/query-caching/) for a full list of uncacheable functions. | ||||||
|
thomasgauvin marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| If your queries are not getting cached despite Hyperdrive having caching enabled, your driver may be configured such that your queries are not cacheable by Hyperdrive. This may happen if you are using the [Postgres.js](https://github.com/porsager/postgres) driver with [`prepare: false:`](https://github.com/porsager/postgres?tab=readme-ov-file#prepared-statements). To resolve this, enable prepared statements with `prepare: true`. | ||||||
| **Function names in SQL comments**: Hyperdrive uses text-based pattern matching to detect uncacheable functions. References to function names like `NOW()` in SQL comments cause the query to be treated as uncacheable, even if the function is not actually called. Remove any references to uncacheable function names from your query text, including comments. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| **Driver configuration**: Your driver may be configured such that your queries are not cacheable by Hyperdrive. This may happen if you are using the [Postgres.js](https://github.com/porsager/postgres) driver with [`prepare: false`](https://github.com/porsager/postgres?tab=readme-ov-file#prepared-statements). To resolve this, enable prepared statements with `prepare: true`. | ||||||
|
thomasgauvin marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| ### Driver errors | ||||||
|
|
||||||
| | Error Message | Details | Recommended fixes | | ||||||
| | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd name Hyperdrive in the title since the changelog is global