logo

How to read uncommitted data in your database tool while debugging a test

Only one line of SQL needed

Joel Clermont
Joel Clermont
2025-10-28

I recommend using the RefreshDatabase trait in your tests to ensure a clean state for each test.

One side effect of this, though, is that every test is wrapped in a database transaction.

What if you want to step debug a test and run database queries manually in your database client (like TablePlus) to inspect the data? You won't see the "in progress" data, because it isn't committed yet.

A clean solution to this is to have those manual queries read in an "uncommitted" state. This lets you peek at the data without the transaction being committed.

Add this line to the beginning of your query in your database client:

set @transaction_isolation = 'READ-UNCOMMITTED';

-- your query here

This changes the isolation level for only the very next query, not for the whole session or the whole server.

I don't need this a lot, but it's handy to know it's available when trying to debug a tricky test issue.

Here to help,

Joel

P.S. Would you like some help pairing on your Laravel application? Check out our Get Unstuck calls.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.