Thread: SQL Server's WITH (NOLOCK) equivalent in PostgreSQL?
Hi all,
I'm trying to understand how to replicate SQL Server's WITH (NOLOCK) behavior in PostgreSQL.
Since PostgreSQL uses MVCC, I'm wondering what the best practice is for non-blocking reads,
and whether there's an equivalent to dirty reads or READ UNCOMMITTED.
Would appreciate any insights or recommended approaches.
I'm trying to understand how to replicate SQL Server's WITH (NOLOCK) behavior in PostgreSQL.
Since PostgreSQL uses MVCC, I'm wondering what the best practice is for non-blocking reads,
and whether there's an equivalent to dirty reads or READ UNCOMMITTED.
Would appreciate any insights or recommended approaches.
> On Mar 30, 2025, at 21:44, 이현진 <jemie9812@gmail.com> wrote: > Since PostgreSQL uses MVCC, I'm wondering what the best practice is for non-blocking reads, > and whether there's an equivalent to dirty reads or READ UNCOMMITTED. There are two different questions here. 1. Reads are not blocked in PostgreSQL by writers, even if another transaction has updated the row but not yet committed. 2. There is no equivalent of a dirty read in PostgreSQL. You can only read committed data (short of bypassing the databaseand reading the disk directly).
On Sunday, March 30, 2025, 이현진 <jemie9812@gmail.com> wrote:
Since PostgreSQL uses MVCC, I'm wondering what the best practice is for non-blocking reads,
and whether there's an equivalent to dirty reads or READ UNCOMMITTED.
We are unable to implement read uncommitted because of our choice to implement MVCC. There is no equivalent because the fundamental operating decisions doesn’t allow for one.
If you don’t pre-suppose the solution of dirty reads and instead supply a use case and desired constraints maybe an alternative approach for that use case could be suggested.
David J.
On Sun, 2025-03-30 at 22:10 -0700, David G. Johnston wrote: > On Sunday, March 30, 2025, 이현진 <jemie9812@gmail.com> wrote: > > Since PostgreSQL uses MVCC, I'm wondering what the best practice is for non-blocking reads, > > and whether there's an equivalent to dirty reads or READ UNCOMMITTED. > > https://www.postgresql.org/docs/current/transaction-iso.html > > We are unable to implement read uncommitted because of our choice to implement MVCC. Perhaps it would be better to say "there is no need to implement a READ UNCOMMITTED isolation level that actually allows for dirty reads". On databases like SQL Server you don't use READ UNCOMMITTED because you desperately want to see dirty, inconsistent data. It is just something you have to accept in order to avoid read locks. Since PostgreSQL doesn't use read locks, there is no need for that. Yours, Laurenz Albe