# Set the cluster to read-only in yugabytedb

**URL:** <https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154>\
**Category:** General\
**Created:** [January 13, 2025, 4:22am UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154 "2025-01-13T04:22:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZhenNan2016](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/zhennan2016/32/623_2.png) [@ZhenNan2016](https://forum.yugabyte.com/u/ZhenNan2016)\
**Post date:** [January 13, 2025, 4:22am UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154/1 "2025-01-13T04:22:22Z")

</div>

Hi  
Is there a global switch that can set the entire cluster to read-only in yugabytedb ?  
That is to say, after setting the switch, all nodes in the cluster will accept user operations only as read-only, and write operations will be rejected.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [January 13, 2025, 7:27am UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154/2 "2025-01-13T07:27:53Z")

</div>

Hi @ZhenNan2016

There is no such mode. Maybe you can create a read-only user in YSQL?

---

<div class="post-metadata">

**Author:** ![Jim\_Knicely](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/jim_knicely/32/668_2.png) [@Jim\_Knicely](https://forum.yugabyte.com/u/Jim_Knicely)\
**Post date:** [January 13, 2025, 7:31pm UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154/3 "2025-01-13T19:31:09Z")

</div>

There is a parameter called **default\_transaction\_read\_only** that can be set to make all transactions read only.

**See** : [Make a Database Read Only](https://yugabytedb.tips/make-a-database-read-only/)  
**See:** [Ensure a Read Replica Cluster is Strictly Read-Only](https://yugabytedb.tips/ensure-a-read-replica-cluster-is-strictly-read-only/)

However, the setting can be overridden easily at the session level.

As Dorian suggested, a read only user is a good option.  
**See:** [Create a Read Only User](https://yugabytedb.tips/create-a-read-only-user/)

Note that PG15 support is coming to YB! So the pg\_read\_all\_data role will available real soon! 🙂

---

<div class="post-metadata">

**Author:** ![ZhenNan2016](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/zhennan2016/32/623_2.png) [@ZhenNan2016](https://forum.yugabyte.com/u/ZhenNan2016)\
**Post date:** [January 16, 2025, 3:14am UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154/4 "2025-01-16T03:14:36Z")

</div>

Hi, @Jim_Knicely.  
Thanks for the reply.  
Read-only switches based on session level may not fulfill the requirements. My requirement is that I want all sessions, all users, to have read-only access to the database, not write.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [January 16, 2025, 10:17am UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154/5 "2025-01-16T10:17:52Z")

</div>

Can you explain the requirement more? Why can’t you just create read-only users?

---

<div class="post-metadata">

**Author:** ![ZhenNan2016](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/zhennan2016/32/623_2.png) [@ZhenNan2016](https://forum.yugabyte.com/u/ZhenNan2016)\
**Post date:** [January 17, 2025, 3:36am UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154/6 "2025-01-17T03:36:15Z")

</div>

Hi.  
There is such a scenario, the user originally has read and write permissions, but will be triggered based on a certain condition, do not want the user to continue to write data, only read the old data.  
If the control is based on the user, there are two demand points:  
1, if the user has been created, with read and write access, it also needs to be changed to read-only, preventing the continuation of writing.  
2, if you re-create a user that can read and write operations, then also still have read and write permissions. This way, the user can’t be in read-only state after a certain condition is triggered.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![dorian\_yugabyte](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/dorian_yugabyte/32/206_2.png) [@dorian\_yugabyte](https://forum.yugabyte.com/u/dorian_yugabyte)\
**Post date:** [January 20, 2025, 7:07am UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154/7 "2025-01-20T07:07:27Z")

</div>

I didn’t understand why you can’t use per-role though. Why not alter role and only allow reads when your condition is triggered?

---

<div class="post-metadata">

**Author:** ![ZhenNan2016](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/zhennan2016/32/623_2.png) [@ZhenNan2016](https://forum.yugabyte.com/u/ZhenNan2016)\
**Post date:** [January 20, 2025, 9:05am UTC](https://forum.yugabyte.com/t/set-the-cluster-to-read-only-in-yugabytedb/4154/8 "2025-01-20T09:05:53Z")

</div>

Hi  
If the control user permissions are read-only, it is OK for old usernames. If you create another user, is it possible to read and write to the database again? To draw an analogy:  
Original test-a, set to read-only, no problem. However, if you re-create test-b, you can read and write again, which violates the “read-only” principle.  
The general principle is that you want the entire cluster, i.e. all nodes, to be read-only for all user operations.  
Thanks.
