Safety · Guide

How to Prevent Accidental DELETEs and DROPs in Production

Almost everyone who works with databases has run something on production they meant for staging. These are the habits and settings that make it hard to do twice.

Updated November 29, 2026By the QueryOS team7 min read

Quick answer

Use a read-only user by default, turn on MySQL’s sql_safe_updates, wrap manual changes in a transaction, colour-code production in your client, and use a client that shows the SQL before it runs and asks for confirmation (or Touch ID) on production.

Disclosure: QueryOS is our product and is shown here as one option. Every other step in this guide works with any database client.

How production gets broken

1. Use a read-only user by default

Most of the time you are reading. Connect with a user that can only SELECT, and keep a separate, rarely used login for changes. In PostgreSQL you can also make a role read-only by default:

ALTER ROLE analyst SET default_transaction_read_only = on;

2. Turn on MySQL safe updates

SET SESSION sql_safe_updates = 1;

MySQL then rejects UPDATE and DELETE statements that don’t filter on a key column or use a LIMIT.

3. Make changes inside a transaction

BEGIN;
UPDATE orders SET status = 'shipped' WHERE id = 1043;
-- check the row count, then
COMMIT;   -- or ROLLBACK;

If the affected row count isn’t what you expected, ROLLBACK and nothing happened.

4. Make production look different

Colour-code connections by environment in your client. In QueryOS, a connection tagged production turns the toolbar pill and the line beneath it red and shows a PROD tag; TablePlus and DBeaver offer connection colours too. It sounds trivial; it prevents the wrong-tab mistake better than anything else.

5. Let your client stop you

A good GUI gives you a moment to notice. QueryOS has four safe modes per connection: off, confirm every write, confirm writes with Touch ID, or read-only (also enforced in the database session). Grid edits are shown as the exact SQL before they run and commit in one transaction. It also asks before DROP, TRUNCATE, and UPDATE or DELETE without WHERE, and treats hidden writes (a DELETE inside a CTE, SELECT … INTO, EXPLAIN ANALYZE on a write) as writes.

6. Have a backup you have tested

Every guard can fail. Point-in-time recovery or regular dumps (pg_dump, mysqldump) are the last line, and only count if you have restored one recently.

Checklist

Try QueryOS on your Mac23 databases and a review step before every change, free. Premium adds the AI assistant and unlimited tabs for $15 once.

Download free

Frequently asked questions

How do I stop UPDATE or DELETE without WHERE in MySQL?

Run SET SESSION sql_safe_updates = 1; (or start the mysql client with --safe-updates). MySQL then refuses UPDATE and DELETE statements that don’t use a key in the WHERE clause or a LIMIT.

Can I undo a DELETE in PostgreSQL?

Only if it ran inside a transaction you haven’t committed: then run ROLLBACK. After a commit you need a backup or point-in-time recovery.

What does safe mode in a database GUI do?

It adds checks before statements run on a connection: from asking for confirmation, to requiring Touch ID, to blocking writes entirely. In QueryOS, read-only safe mode is also enforced in the database session, not just in the app.