Requirements and tips for configuring replication

This page provides information about working with read replicas.

For information about how to configure a read replica, see Creating read replicas.

Read replicas

Read replicas are Cloud SQL instances that replicate from a Cloud SQL primary instance. Read replicas are read-only. You cannot write to them. You can use a replica to offload read requests and analytics traffic from the primary instance.

For information about how to configure a read replica, see Creating Read Replicas.

Quick reference for Cloud SQL read replica topics

Topic Discussion
High availability Read replicas neither provide high availability nor offer it.
Failover A primary instance cannot failover to a read replica, and read replicas are unable to failover in any way during an outage.
Maintenance windows Maintenance windows cannot be set on read replicas and they do not share maintenance windows with the primary instance. Maintenance can occur at any time on the read replica. Maintenance occurs on read replicas at a different time than on the primary instance.
Disruptive upgrades Read replicas can experience a disruptive upgrade at any time.
Performance When you create a read replica, it does not impact the performance or availability of the primary instance.
Multiple read replicas You can create multiple read replicas for a single primary instance.
Load balancing Cloud SQL does not provide load balancing between replicas.
Settings The settings of the primary instance are propagated to the replica, including the password for the postgres user and changes to the user table.
Machine types Read replicas can be a different machine type (or tier) than the primary instance. Read replicas can have more CPUs and memory than the primary instance, but they cannot have less.
User tables You cannot make changes to the user table on the replica. All user changes must be done on the primary instance.
Backups You cannot configure backups on the replica.
Restoring the primary instance You cannot restore the primary of a replica while the replica exists. Before restoring an instance from a backup, you must promote or delete all of its replicas.
Deleting the primary instance Before you can delete a primary instance, you must promote all of its read replicas to stand-alone instances or delete the read replicas.
Creating a replica of a replica You cannot create a replica of a replica.
Stopping a replica You cannot stop a replica. You can restart, delete, or disable replication on it, but you cannot stop it as you can a primary instance.

Billing

  • A read replica is charged at the same rate as a standard Cloud SQL instance. There is no charge for the data replication.

Troubleshooting

Click the links in the table for details:

For this problem... The issue might be... Try this...
Read replica did not start replicating on creation. At least one backup must have been created after binary logging was enabled. Wait until at least one backup has been created after enabling binary logs.
Unable to create read replica - unknown error. There could be many root causes. Check the logs to find more information.
Disk is full. The primary instance disk size can become full during replica creation. Upgrade the primary instance to a larger disk size.
Replica instance is using too much memory. Replicas can cache often-requested read operations. Restart the replica instance to reclaim the temporary memory space.
Replication stopped. Max storage space was reached and automatic storage increase is not enabled. Enable automatic storage increase.
Replication lag is consistently high. There can be many different root causes. Increase the instance size of the replica or reduce the load on the database.

Read replica did not start replicating on creation

Read replica did not start replicating on creation.

The issue might be

The primary instance must have at least a week's worth of binlogs or else replicas cannot start replicating.

Things to try

Wait until there are enough binlogs.


Unable to create read replica - unknown error

Unable to create read replica - unknown error.

The issue might be

There is probably a more specific error in the log files.

Things to try

Inspect the logs in Cloud Logging to find the actual error. If the error is: set Service Networking service account as servicenetworking.serviceAgent role on consumer project, then disable and re-enable the Service Networking API. This action creates the service account necessary to continue with the process.


Disk is full

error: disk is full

The issue might be

The primary instance disk size can become full during replica creation.

Things to try

Edit the primary instance to upgrade it to a larger disk size.


Replica instance is using too much memory

The replica instance is using too much memory.

The issue might be

The replica uses temporary memory to cache often-requested read operations, which can lead it to use more memory than the primary instance.

Things to try

Restart the replica instance to reclaim the temporary memory space.


Replication stopped

Replication stopped.

The issue might be

The maximum storage limit was reached and >automatic storage increase is disabled.

Things to try

Edit the instance to enable automatic storage increase.


Replication lag is consistently high

Replication lag is consistently high.

The issue might be

The write load is too high for the replica to handle. Replication lag takes place when the SQL thread on a replica is unable to keep up with the IO thread. Some kinds of queries or workloads can cause temporary or permanent high replication lag for a given schema. Some of the typical causes of replication lag are:

  • Slow queries on the slave. These are discoverable by enabling log_slow_slave_statements and fixing them.
  • All tables should have unique/primary key. Every update on such a table without a unique/primary key causes full table scans on th replica.
  • Queries like DELETE ... WHERE field < 50000000 cause replication lag with row-based replication since a huge number of updates are piled up on the replica.

Things to try

Edit the instance to increase the size of the replica, or reduce the load on the database.

What's next