question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres transaction isolation level

See original GitHub issue

Hi, Probably I’m missing something but I couldn’t find a way to specify transaction isolation level for Postgres (default to Read committed which is not sufficient for my use case - in which Repeatable read is needed).

Any way to workaround it (without changing postgres config or manually open transaction)?

Thanks a lot!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
duvifncommented, Jul 22, 2019

OK. Thanks again.

In case someone else will encounter this thread - another possible option (which i didn’t try) is to use raw SET TRANSACTION statement which should be ran before any other query in the transaction.

0reactions
coleifercommented, Jul 22, 2019
@contextmanager
def isolation(level):
    conn = db.connection()
    orig = conn.isolation_level
    conn.set_isolation_level(level)
    try:
        with db.atomic() as txn:
            yield txn
    finally:
        conn.set_isolation_level(orig)

Something like this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: 13.2. Transaction Isolation - PostgreSQL
The Serializable isolation level provides the strictest transaction isolation. This level emulates serial transaction execution for all committed transactions; ...
Read more >
Transaction Isolation Levels With PostgreSQL as an example
Transaction Isolation Levels With PostgreSQL as an example · Dirty Read. Dirty read means read uncommitted changes of other transactions. · Lost Update...
Read more >
Transaction Isolation in PostgreSQL - pgDash
Every transaction has it's isolation level set to one of these when it is created. The default level is “read committed”. Note that...
Read more >
PostgreSQL Concurrency: Isolation and Locking
The SQL standard defines four levels of transaction isolation. The most strict is Serializable, which is defined by the standard in a ...
Read more >
Transaction Isolation in Postgres | by Dhruv Arora - Medium
The four levels are Read uncommitted, read committed, repeatable read and serializable. Courtesy: Postgres official docs. The default isolation ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found