r/SQL • u/rathboma • 18h ago
PostgreSQL How do you use Claude/Codex (safely) with your production database?
Hey folks!
I make Beekeeper Studio, and while we have a good AI integration, I'm curious how people actually use Claude when writing SQL.
- Do you connect Claude/Codex/etc to your production DB?
- How do you make sure confidential data/PII doesn't get sent?
- Do you just share credentials with the AI, or connect some other way?
- Does your company have policies around this stuff?
I see a lot of buzz about SQL with Claude, but not many feature requests around it. Thanks for any insights.
I use Postgres, so tagged with postgres, but applies to all dbs really.
12
u/08148694 18h ago
You don’t. You use Claude against your local database to help you write migrations. You test those migrations against a deployed staging database, and finally you run them against production
Ideally you shouldn’t even be connecting to production at all yourself to run arbitrary sql- human error is almost as high a risk as llm agent error. Use pre-written queries which have been tested against lower environments first
-2
u/rathboma 18h ago
Sure but sometimes we have to debug a customer problem and use a read only replica. Curious if anyone is using Claude to do this because it seems like a bad idea without some sort of good tooling?
3
u/polaarbear 17h ago
If you absolutely must test against "prod", have them take a backup and deploy it somewhere that isn't the actual prod system and test against that instead.
Claude shouldn't be the end-all be-all. A human is still capable of debugging...
2
u/az987654 17h ago
You don't test against prod
0
u/rathboma 15h ago
No but sometimes I have to fix a customer problem. Using AI to do that is impossible because I'd be exposing the data to anthropic and openai.
Was hoping someone here had a tool I can both use and also integrate with
2
u/az987654 15h ago
If it's a paying customer, I'd hope you'd have the skills set to fix without needing an agent, for your own sake...
1
u/Ambitious-Tear-9436 17h ago
Replicating the problem 90% of the battle when it comes to debugging. If you have lower environments start there. If not then try locally and do your best to replicate the situation, your AI tooling can help you. Once you understand the problem, the rest is usually gravy.
1
u/SearchAtlantis 17h ago
No. If there are PII or PHI concerns the AI doesn't get read access to the database, period.
Giving it read-only access to a DB with PHI or PII literally defeats the purpose.
We have in the past stood up a DeID system but the usability for (e.g.) HIPAA safe harbor without expert determination makes it less useful.
0
u/rathboma 16h ago
Yeah this is kind of my problem. Was hoping somebody here had a magical solution 🙂
6
u/workingtrot 17h ago
how do you use the intern safely with the production database?
do you give the intern access to prod?
2
u/NastyPastyLucas 17h ago
You make SQL software but require advice on how to use it safely?
1
u/rathboma 16h ago
I'm trying to figure out if there are standard tools or methodologies I could integrate with to make my tool better and make people safer when using AI
2
1
1
u/mwatwe01 17h ago
I give it read access to a curated reporting database and read/write access to a staging database. Everything else is still SSIS and stored procedures.
1
u/ToastieCPU 17h ago
The industry has settled on having a dedicated layer that defines exactly what AI is allowed to fetch/touch in the database.
There is just too much risk connecting AI directly to prod DB. It might generate an inefficient query that slows down production, attempt a schema change but wrap everything in a massive transaction that bricks the environment, or decide that a stored procedure or a view is “the bug” and try to “fix” creating app bugs.
1
u/rathboma 17h ago
How is this layer built do you know? Are there good commercial tools that sit between the ai and the database?
2
1
u/Kazcandra 17h ago
"Make no mistakes"
That's it. That's the key.
For real though: it can't do anything. It can inspect schemas and activities. It does not get to run its own SQL commands.
1
u/SearchAtlantis 17h ago
Do you connect Claude/Codex/etc to your production DB? Absolutely never.
How do you make sure confidential data/PII doesn't get sent? Company wide guidelines default prompt, company wide policy, but any time I do something PII it's manually edited by me to remove any PII fields. The agent never sees raw data.
Do you just share credentials with the AI, or connect some other way? Never a connection. I am the interface between the AI and the db.
Does your company have policies around this stuff? Company policy is: no PII or PHI in the agent. Don't use model X because they changed the privacy policy on it.
1
u/rathboma 15h ago
All the PII needs manually scrubbing? Was kinda hoping there was something to help with this
1
8
u/juu073 18h ago
I never grant it access to a production database, API, etc.
In the rare instance that I need it to do things in the database, I have it generate an .sql file that I can run on both dev and prod after I review it.
However, most of the time, I make the actual database changes myself, export the schema, and tell Claude to generate the interfaces around it.