r/SQL • u/rathboma • Sep 13 '26
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.
0
Upvotes
13
u/08148694 Sep 13 '26
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/NastyPastyLucas Sep 13 '26
You make SQL software but require advice on how to use it safely?
10
u/juu073 Sep 13 '26
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.
5
u/workingtrot Sep 13 '26
how do you use the intern safely with the production database?
do you give the intern access to prod?
1
u/ToastieCPU Sep 13 '26
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/SearchAtlantis Sep 13 '26
3
u/az987654 Sep 13 '26
You don't, unless you're highly unprofessional
2
u/mwatwe01 Sep 13 '26
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/greendookie69 Sep 13 '26
I yell at it and tell it not to fuck anything up
1
u/Kazcandra Sep 13 '26
"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.