select 1 queries in production
Hey all, I'm trying to track down an inconsistency between dev and prod environments -
I'm using Neon postgres, and I'm finding that in my production environment, Prisma is running a
SELECT 1
query about every 5 seconds, but it doesn't seem to happen at all in development. I haven't been able to find any options about enabling/disabling this behavior, and I'm having trouble even figuring out what's triggering it it one environment and not the other.
This looks like some kind of connection health check, but it's causing the connection from my application to Neon to never go fully idle, which means I'm winding up paying for uptime usage when it should be spinning down to zero when inactive.
I've verified it's coming from the PrismaPg adapter by patching the pool query to trace the source, but that hasn't gotten me very far. In prod, it's showing the pool acquire/release every 5 seconds, with the trace coming from @prisma/client/runtime/library.js:6:6846
showing the SELECT 1
query.

6 Replies
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the
#ask-ai
channel awaits if you're curious!Logs that repeat every 5 seconds in production, but never occur in development:
This is with Prisma 6.14.0, but I was having similar issues with 6.8.0 prior to upgrading to try and pass the pool instance directly to help troubleshoot.
I've found this - https://github.com/prisma/prisma/discussions/5604, which suggests it's related to connection health testing, but it's from several years ago, and I'm not finding much else recently suggesting this is still done. Also tried searching the prisma repo for this query, but didn't come across anything.
GitHub
Why does Prisma run the query 'SELECT 1' in some queries? · prisma...
I've noticed Prisma runs SELECT 1 sometimes and sometimes it doesn't, it would be nice to know what "triggers" this to be ran and what it does, isn't a SELECT 1 query by itsel...
I'm assuming this is something I won't be able to modify without potentially affecting the connection stability, but I'd at least like to understand what's causing the difference between development and production environments.
I haven't seen other Neon users run into this issue. I am assuming that you have the exact same setup in Dev environment as you have in Prod.
It would be interesting to see if you get the same
SELECT 1
queries if you don't use driverAdapaters to connect.Bizarre, I swapped out the adapter for the default setup, and I'm still seeing the same behavior difference between dev and prod.
I even pulled all environment configs to my local instance to make sure I was connecting to the same database the same way, and built the same Docker image that's being used in production on render.com. Running it locally with exactly the same production environment configs still never caused a
SELECT 1
to trigger, and it's still happening every 5 seconds in production after swapping back to the default prisma-client-js
client without the adapter.
Closing this out in case someone searches for something similar later -
It wound up being an issue with the API health checks. The Render service monitor was hitting my /healthz
endpoint every 5 seconds, which I wasn't logging, and was submitting the SELECT 1
through prisma to verify the connection to the database was still healthy, but was causing it to never drop below at least 1 connection in the database pool.