Hyperdrive bindings exist in the Pages
Hyperdrive bindings exist in the Pages Projects API under
hyperdrive_bindings
. You won't be able to use the pg
driver, but you can use the Postgres.js driver which only requires the compat flag nodejs_compat
(not old node_compat
) and it works 🙂65 Replies
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
You won't be able to use
node_compat
and pg
, but you can use nodejs_compat
and https://github.com/porsager/postgresUnknown User•8mo ago
Message Not Public
Sign In & Join Server To View
won't build how so?
node_compat
is old and generally not recommended - it's a real shame that hyperdrive launched with drivers requiring it.Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
node_compat
is a build-time thing with wrangler. nodejs_compat
is a runtime compatibility flag
You can't use node_compat
with Pages. But you don't need that for the postgres.js
driver - it works fine with just nodejs_compat
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
I'm not familiar with nuxt and how it builds sadly, but
cloudflare:sockets
definitely works fine with Pages and manual Functions.
That sounds to me like Nuxt is doing something odd with the buildUnknown User•8mo ago
Message Not Public
Sign In & Join Server To View
lemme write up a quick rundown, one sec
For a quick rundown for Pages + Hyperdrive:
- Hyperdrive today recommends and works best with the
pg
driver. Sadly today, this driver requires the old and legacy node_compat
build option within wrangler, which limits a lot of functionality with the rest of the ecosystem
- Pages doesn't support node_compat
, so this driver will not work within Pages (without some serious hacks and building some stuff yourself)
- https://github.com/porsager/postgres is a postgres driver that doesn't need the legacy node_compat
mode and works just fine with the more modern nodejs_compat
compatibility runtime flag
- This driver doesn't work 100% with hyperdrive though, due to https://github.com/porsager/postgres/pull/736 and using prepared statements by default
- Pages doesn't yet have Hyperdrive config in the UI, but does support in the API and via wrangler.toml
This is all a bit confusing and definitely feels like it should still be "beta" to me 😅
cc @Matt @AJR ^ this is some good feedback and DX observationsUnknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Honestly my personal recommendation would be to probably avoid Hyperdrive with Pages for now - it's likely too much of a headache, and give them a bit of time to stabilise. Hopefully won't be too long.
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
This is good feedback, much appreciated.
Again, we're actively pursuing improvements with
postgres.js
which would simplify this case a bit it sounds like.
No worries, this is all good to hear.any updates on this? I'm having a ton of issues with both pg and postgres js and I'd really love to get this working
with postgres.js, I'm getting
with pg, I'm getting
might be making progres by downgrading via here https://github.com/kysely-org/kysely-postgres-js/issues/60#issuecomment-2177305424
GitHub
If the connection to PG fails during execution, it will cause the p...
Env: Win10 Node v20.14.0 kysely: 0.27.3 kysely-postgres-js: 2.0.0, postgres: 3.4.4 Reproduction steps: Start the PostgreSQL service. Start the application. Kill the PostgreSQL process. The error re...
progres, get it?
that made it work in
wrangler dev
but not production still
in production, every request is causing an infinite loop that eats my CPU time
(went from 18k ms to 100k in a couple hours)
yeah I'm really struggling here, my hyperdrive config ID is 5470ba839d3c47d7a9de80ebf5ee2bab
I assume there is some issue connecting to the databasepossibly related to this that I saw in dev
Can you confirm what version of Postgres.js you have installed? What does your
package-lock.json
say?3.4.4
Role “Postgres” does not exist implies you don’t have a user set up on your remote server called “Postgres”
Right, except this was in development and my connection string was
but creating the user fixed it in development
in production, it just... hangs
Can you open a GitHub issue with your code + command line invocations, as well as your Hyperdrive config ID?
to what repository?
This is the first report like this and easier to understand if we can reproduce
workers-sdk?
Yes
sounds great
GitHub
🐛 BUG: Obscure hangs while using hyperdrive and postgres.js · Issue...
Which Cloudflare product(s) does this pertain to? Pages, Other What version(s) of the tool(s) are you using? Wrangler 3.62.0, Postgres.js 3.4.4 What version of Node are you using? No response What ...
Ok I might have something, I tried connecting to the production database locally via miniflare instead of a local database, and it says "invalid url" despite the fact that psql accepts it, due to the special characters
I'm trying
1. to connect to the database via workers without hyperdrive
2. changing the password
ok so I've gotten it working without hyperdrive
lets swap in hyperdrive
and now look at it!
(I made sure to update the password for hyperdrive)
I'm not familiar with your editor, sorry if this is a dumb question. Is this attempting to connect through a worker? Hyperdrive is only accessible via a binding.
I'm reading through your GH issue now, one sec
You seeing any errors in your Hetzner log?
If you could add a slightly broader code snippet to your GH issue, that'd be helpful. It's not clear to me how you're populating
connectionString
in that example, and that is central to this effort.
As an aside, I recognize this is frustrating and I appreciate you spending the effort to document this and work through it.this is a cloudflare pages deployment, hyperdrive is bound to it inside the wrangler.toml
I will check hetzner for logs, I did that before and I saw a random chinese IP doing nonsense, and I thought "this probably isn't cloudflare", and that was it. I'll give it a look
Hyperdrive egresses through the untrusted Warp IP address space. It's a fluid pool, won't be "recognized" Cloudflare addresses
in any case, it was making 2 requests per second and it wasn't using SSL so
Then it's probably not us, yeah
nothing interesting
Connection string is being populated like
The reason for this is just so I could test swapping out the connection string to be a direct connection, I eventually did get to work. Env is being populated like , I know this looks "not cloudflaree", just working with what I got unfortunately, but I've managed to successfully log the connection string at one point
postgresql://xx:[email protected]:5432/xxxxxxxxx?sslmode=disable
Yeah, it'll be internal, and gibberish for your purposes.
Ok, that all looks right to me so far.
(right now I am trying to get the request to timeout again for Real-time Logs but its refusing... just going on and on)
yup
To be clear, you're trying to run local dev to a remote database here? I know that is a use case that we've fought with a bit. Just want to confirm as I dig
No, I've gotten that working correctly (though I've encountered a lot of issues getting to that point). Right now, the only thing that "isn't working" is the deployed worker, connecting to the database via hyperdrive
Looks like this config has an IP address registered as origin
yes it does
is that the cause?
Can you try making one using a hostname? There's enough moving parts here that I'm not 100% sure, but we definitely recommend using hostnames
sure, what is the recommended method? an
A
record?Going to vary based on your provider. I know I've seen Hetzner databases configured with hostnames, and they (mostly) all worked fine, but I'd need to look into their docs to see how they prefer you to do it.
(you're on Hetzner, right? I think I read that somewhere in here?)
Yes I am, A records are reccomended I believe. I've made one, I will update the config and redeploy the worker
I think that was it!!!!!!!!
Victory! I'll see to it that this is made more clear in our docs. Happy hunting.
Thank you so much!! Definitely a couple other notes:
1. At least miniflare doesn't support special characters as a password, it needs to be A-z0-9, maybe a couple others, despite the fact postgres supports it
2. I don't know how much control you have over postgres.js but this hang on a failed connection is really really really annoying
3. It would be helpful if hyperdrive logs could be exposed somehow to get better visibility into the cause of these failures
but for now I'm just happy to have it working
This is good feedback, thank you!
CC @thomasgauvin
Cheers!
yeah the docs currently say IPs are supported
Some providers play nicer on that front than others. I didn't know Hetzner in particular presented this challenge until today, just had a suspicion. Docs are going to need some tweaking here, for sure.
Out of curiosity, what is the root cause?
I still don't know for sure. We can egress to IP addresses across most of our stack. I'm more of a DB internals guy than a networking guy, so I hesitate to venture guesses.
Got it, well thank you regardless!