What Is The Best Way to Handle Restart Errors in YSQL?

Distributed SQL Tips and Tricks Series
Marko Rajcevic

First and foremost, you need to be using at least version 2.12 or 2.13 of YugabyteDB along with yb_enable_read_committed_isolation=true to use the READ COMMITTED isolation that YSQL supports.

Please note that this isolation is the default in PostgreSQL, and YSQL has the same semantics (barring minor limitations that likely will not affect you).

More specifically, it ensures clients won’t see a Restart read required error, which is not seen in single-node PostgreSQL. However, it can occur in YugabyteDB due to the clock skew that might be present between nodes.

As per our transaction isolation documentation:

“…this isolation level internally handles read restart and conflict errors. In other words, the client doesn’t see read restart and conflict errors (barring an exception). Details on YugabyteDB’s implementation are on the Read Committed isolation level page.”

This isolation level will likely alleviate all the errors you are running into. Furthermore, READ COMMITTED already has pessimistic locking built-in, which means a transaction might wait for another transaction to complete, which is seen in PostgreSQL. We are working on a more sophisticated implementation of pessimistic locking that will improve the performance of READ COMMITTED in a workload with contention and also help avoid the requirement of adding a statement timeout to avoid deadlocks. Additionally, orthogonal to the work on performance-optimized pessimistic locking implementation, current limitations are set to be improved.

If you cannot upgrade your cluster, incorporate retries at the application level when these errors surface to help alleviate the issue.

For more details and examples, check out our documentation page on Read Committed Isolation Levels.

Discover More Tips and Tricks

Explore our library of distributed SQL tips and tricks and general “how to” information on the YugabyteDB blog and on our DEV Community Blogs.

Events and Training

Check out the upcoming YugabyteDB events, including all training sessions, conferences, in-person and virtual events, and YugabyteDB Friday Tech Talks (designed for engineers by engineers).

In addition, there is some extremely popular “how to” content on the YugabyteDB YouTube channel.

If You Have Questions About Distributed SQL

If you have questions, ask them on the YugabyteDB Slack channel, Forum, GitHub, or Stack Overflow.

Next Steps

Ready to start exploring YugabyteDB features? You have some great options to get started. Run the database locally on your laptop (Quick Start), deploy it to your favorite cloud provider (Multi-node Cluster Deployment), sign up for a free YugabyteDB Managed cluster, or request a full-featured trial. It’s easy! Get started today!

Marko Rajcevic

Related Posts

Explore Distributed SQL and YugabyteDB in Depth

Discover the future of data management.
Learn at Yugabyte University
Get Started
Browse Yugabyte Docs
Explore docs
PostgreSQL For Cloud Native World
Read for Free