> ## Documentation Index
> Fetch the complete documentation index at: https://planetscale.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Read-only mode

> PlanetScale may automatically enable read-only mode on a cluster to maintain stability and availability when certain conditions are detected.

Read-only mode preserves cluster functionality while preventing operations that could lead to instability, allowing you to remediate issues before they become critical.

When read-only mode is enabled, attempts to write to the cluster will see the following error:

```sql theme={null}
invalid statement because cluster is read-only
```

We will also *pause* all logical replication subscriptions writing data into the cluster.
Once your cluster is out of read-only mode you can unpause the subscribers by running

```
ALTER SUBSCRIPTION sub_name ENABLE;
```

on each subscription.

There's no way for a PlanetScale customer to enter or exit read-only mode, except by remediating the conditions that caused the cluster to enter that mode.

Here are the reasons we'll put the cluster into read-only mode:

## Insufficient space

To protect your cluster from crashing, if a cluster has very little space left (typically 5% or less), we will automatically move it into read-only mode. The specific scenarios are:

| Storage Type | Scenario | Remediation |
| - | - | - |
| **Network-attached storage** | Clusters with [Autoscaling](https://planetscale.com/docs/postgres/cluster-configuration/cluster-storage.md#enable-autoscaling) disabled or where your current [disk size](https://planetscale.com/docs/postgres/cluster-configuration/cluster-storage.md#minimum-disk-size-configuration) is approaching your configured [Autoscaling maximum](https://planetscale.com/docs/postgres/cluster-configuration/cluster-storage.md#storage-limit) | Increase the [cluster disk size](https://planetscale.com/docs/postgres/cluster-configuration/cluster-storage.md#minimum-disk-size-configuration) manually or increase the [storage limit on disk autoscaling](https://planetscale.com/docs/postgres/cluster-configuration/cluster-storage.md#storage-limit) |
| **PlanetScale Metal** | When your data is approaching the storage size of your cluster | Increase the [cluster size](https://planetscale.com/docs/metal.md) |

Once you have remediated the issue, your cluster will automatically exit read-only mode.

> [!NOTE]
>
> PlanetScale will send notifications via email and webhook (if enabled) when your storage exceeds 60, 75, 85, 90, and 95 percent, respectively. You can also track disk utilization via [Metrics](https://planetscale.com/docs/postgres/monitoring/metrics.md). Emails are sent to all Organization and Database administrators. It is critical that these email addresses are monitored regularly.

If the issue was temporary, say due to errant data being written by mistake, you could remove the data, perform a vacuum, and then reverse the remediation action. See [Cluster storage configuration](https://planetscale.com/docs/postgres/cluster-configuration/cluster-storage.md) for more on reducing storage usage.

## Single Node Archiver lag

Single node Postgres clusters offer decreased durability compared to HA offerings. In HA, we use Postgres synchronous replication to guarantee every committed transaction reaches the primary and at least one replica.
As part of our usual (we do this on HA too) durability posture, we archive postgres Write-Ahead Logs (WAL) to durable object storage (S3, GCP Cloud Storage). For single-node, we will enter read-only mode if this archiving process falls too far behind writes on your cluster.

If you see this happening frequently, we recommend sizing your cluster up, or moving to an HA cluster.

## Read-only transactions vs cluster read-only mode

Cluster read-only mode and read-only transactions are different failure modes with different error messages.

| | Cluster read-only mode | Read-only transaction |
| - | - | - |
| Error | `invalid statement because cluster is read-only` | `cannot execute <command> in a read-only transaction` (SQLSTATE `25006`) |
| Cause | PlanetScale protects the cluster when storage is low or archiver lag is high | The current transaction is read only |
| Branch state | Branch enters read-only mode | Branch stays writable |

A transaction becomes read only through `BEGIN READ ONLY`, `SET TRANSACTION READ ONLY`, session characteristics, role defaults, `default_transaction_read_only`, and similar settings in application code, an ORM, or a database driver.

If only some writes fail while others succeed on the same branch, the branch is likely not in read-only mode.

[PgBouncer](https://planetscale.com/docs/postgres/connecting/pgbouncer.md) runs in transaction pooling mode and reuses server connections across clients. When session parameters such as `default_transaction_read_only` are not tracked, read-only state from a prior client can persist on a server connection and affect the next client. A plain `SET` can leak across transactions (including `BEGIN; SET ...; COMMIT`); only `SET LOCAL` is limited to the current transaction. See [limitations of transaction pooling](https://planetscale.com/docs/postgres/connecting/pgbouncer.md#limitations-of-transaction-pooling) and [PgBouncer error messages](https://planetscale.com/docs/postgres/connecting/pgbouncer.md#pgbouncer-error-messages) for more on pooled connection behavior.

To resolve read-only transaction errors:

1. Search application code, ORM configuration, and driver options for read-only transaction modes, session characteristics, or replica routing that sets read-only sessions on a write connection.
2. Remove the setting if writes should use the same connection, use `SET LOCAL` when a per-transaction setting is required, or route read-only traffic through a separate [role](https://planetscale.com/docs/postgres/connecting/roles.md) and connection (for example, a [replica PgBouncer](https://planetscale.com/docs/postgres/connecting/pgbouncer.md#dedicated-replica-pgbouncers)) instead of toggling read-only on a shared pooled connection.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.