Cloud SQL in Google Cloud

Cloud SQL in Google Cloud

A complete, plain-English guide to Google's managed relational database service: what it is, how it works inside, how to keep it fast, safe and always on, how to control its cost, and how real teams run MySQL, PostgreSQL and SQL Server without running database servers.

Almost every app you use has a memory. When you log in to a shopping site, it remembers your name. When you place an order, it remembers what you bought and where to send it. When you check your bank balance, it remembers every payment. That memory lives in something called a database, and most databases for business data are of one kind: relational.

Running a database well is a serious job. It must never lose data, must answer quickly, must stay up at night and on weekends, and must be updated and backed up without anyone noticing. Cloud SQL is Google Cloud’s service that does that job for you. You ask for a database, and Google gives you one that is already installed, patched, backed up and monitored.

In this guide you will learn what Cloud SQL is, why it exists, how a relational database thinks, how Cloud SQL is built, what happens inside when you save and read data, how to keep it fast and always available, how to protect it, and how to avoid the common mistakes. Every new word is explained the first time it appears, and almost every idea comes with an everyday example.

WWhat Cloud SQL Is and Why It Exists

Before the details, let us understand the problem that Cloud SQL solves, using a simple story.

The problem: a database needs a lot of care

Imagine you build a small online shop. You need a place to store customers, products and orders. You pick a well-known database program, install it on a server, and it works. Then the shop grows. Now you must worry about many things at once.

  • What if the server’s disk breaks and all orders are lost?
  • What if the server crashes at midnight during a sale?
  • What if a security flaw is found in the database program and you must update it without stopping the shop?
  • What if someone deletes a table by mistake and you need to go back to yesterday?
  • What if traffic doubles and the database becomes slow?

Each question needs knowledge, tools and time. Specialists called database administrators, or DBAs, are paid to handle them. Small teams often cannot afford one, and large teams would rather spend their skills on the product.

Analogy

Running your own database is like owning a restaurant and also growing every vegetable, fixing the oven and washing the pipes yourself. Using Cloud SQL is like renting a fully equipped kitchen with a maintenance crew. You still decide the menu and cook the food, but you do not repair the oven at two in the morning.

The Cloud SQL answer: a managed database

Cloud SQL is a managed service. That means Google handles the machines, the operating system, the database software installation, the security patches, the backups, the copies for failure protection and the monitoring. You get a database address, a user name and a password, and you start storing data.

Cloud SQL runs three very popular database engines: MySQL, PostgreSQL and SQL Server. An engine is the database program itself. Because Cloud SQL uses the real engines, your existing applications, tools and skills work with little or no change. This is a major reason people choose it.

A short history

Google offered a managed MySQL service in its early cloud years through App Engine. It was later rebuilt and grew into Cloud SQL as it is known today, with PostgreSQL added in the second half of the 2010s and SQL Server added soon after. Over time Google added regional high availability, read copies in other regions, stronger security options and a higher tier named Enterprise Plus aimed at the most demanding systems.

Where Cloud SQL sits among Google Cloud databases

Google Cloud offers many databases. Each is best at a different job.

ServiceKind of databaseBest for
Cloud SQLRelational: MySQL, PostgreSQL, SQL ServerStandard business applications, websites, services needing familiar engines
AlloyDBRelational, PostgreSQL-compatible, higher performanceHeavier PostgreSQL workloads and mixed transaction and analysis use
SpannerRelational, globally distributedHuge scale and worldwide consistency
FirestoreDocument databaseMobile and web apps with flexible data
BigtableWide-column, very high speedEnormous streams of simple data, such as sensor readings
BigQueryAnalytical data warehouseAsking big questions over huge amounts of data
i
Pro Tip

A simple rule: if your application already uses MySQL, PostgreSQL or SQL Server, or you want a classic relational database with a familiar tool set, start with Cloud SQL. Look at AlloyDB or Spanner only when your needs clearly pass what one Cloud SQL instance can do.

Production example: SaaS and web applications

Countless web applications and software-as-a-service products keep their users, accounts, billing records and settings in a managed relational database. Teams choose a managed service so their engineers spend time on features, while backups, failover and updates are handled behind the scenes.

RRelational Database Basics for Beginners

To use Cloud SQL well, you need a picture of how a relational database thinks. Here it is, with no jargon left unexplained.

Tables, rows and columns

A relational database stores data in tables. A table is like a spreadsheet with a fixed set of columns. Each column holds one kind of fact, such as a name or a price. Each row is one record, such as one customer or one order.

Analogy

Think of a school. One table lists students, with columns for student number, name and class. Another table lists courses. A third lists which student takes which course. Together they describe the school without repeating anyone’s name over and over.

Keys and relationships

Every row needs a way to be identified. A primary key is a column, such as a customer number, that is unique for each row. A foreign key is a column in one table that points to the primary key of another, such as an order that stores the customer number of the person who placed it. These links are the “relations” in relational. They let you keep each fact in one place and still join the facts together when you need them.

SQL: the language of databases

SQL, which stands for Structured Query Language, is the language used to talk to relational databases. You use it to ask questions, such as “show me all orders from last week”, and to change data, such as “add this new customer”. Almost every relational database speaks SQL, with small differences between engines.

Transactions and ACID

Many real actions need several changes that must succeed or fail together. When you pay for an order, the shop must record the payment, reduce the stock and create a delivery request. If the second step fails, the first must be undone. A transaction is a group of changes treated as one unit: all of it happens, or none of it does.

Relational databases promise four properties for transactions, known as ACID.

A

Atomicity

A transaction is all or nothing. A half-finished change never becomes visible.

C

Consistency

Rules, such as “every order must belong to a real customer”, are always kept.

I

Isolation

Transactions running at the same time do not confuse each other.

D

Durability

Once a change is confirmed, it survives crashes and power cuts.

Analogy

A bank transfer is the classic example. Taking money out of one account and putting it into another must happen together. If the power fails between the two steps, the database must either finish both or undo the first. That promise is atomicity, and it is why banks trust relational databases.

Indexes

Imagine finding one name in a phone book with no alphabetical order. You would read every page. An index is an extra, sorted lookup structure that lets the database jump straight to the right rows. Indexes make reads much faster, but they take space and make writes a little slower, because each change must also update the index.

Schema

A schema is the plan of your database: which tables exist, which columns they have, which keys and indexes apply. Changing the schema of a big live table needs care.

Relational versus other kinds of databases

Relational strengths

  • Strong guarantees for correct, consistent data
  • Powerful questions across many tables with SQL
  • Mature tools, skills and decades of experience
  • Well suited to money, orders, accounts and inventory

Relational limits

  • Fixed structure needs planning before use
  • One main server is harder to stretch to enormous scale
  • Very flexible or very huge data can fit other databases better
i
Remember

A database is not just a pile of files. It is a careful program that protects your data from crashes, mistakes and clashes between users. Cloud SQL keeps the care, and you supply the data model and the questions.

Production example: online retail

An online store keeps customers, products, prices, orders and payments in separate tables linked by keys. When a customer checks out, one transaction records the order, reduces stock and stores the payment together. If any step fails, the whole change is cancelled, and the customer is not charged for an order that was never created.

CCore Concepts You Must Know First

Cloud SQL has its own small vocabulary. Learn these words once, and the rest of the guide will feel familiar.

Instance

A Cloud SQL instance is one managed database server. It has a database engine and version, a size in processors and memory, storage, a network setting and a location. You cannot log in to the machine under it, but you connect to the database engine running on it.

Database

One instance can hold many databases, which are separate collections of tables. For example, one instance could hold a “shop” database and a “reports” database.

Users

A database user is an account inside the database engine, with a name and password. Users are different from Google Cloud accounts. Cloud SQL can also link database users to Google identities, which we cover in the security chapter.

Region and zone

A region is a geographic area, such as a part of a country. A zone is one isolated group of data center resources inside a region, with its own power and cooling. A normal instance lives in one zone. A high-availability instance uses two zones.

vCPU and memory

A vCPU is a virtual processor, the part that does the thinking. Memory is the fast working space. Databases love memory, because data already in memory is far quicker to read than data on disk.

Storage

Cloud SQL stores data on network-attached disks. You choose the type, solid-state or hard drive, and the size. Solid-state is faster and is the usual choice. Storage can grow automatically when space runs low, if you turn that option on.

Flags

Database engines have many settings. In Cloud SQL, the settings you may change are called database flags. Google allows a chosen list of flags, so you cannot change everything, but you can change the ones most teams need.

Backup and point-in-time recovery

A backup is a saved copy of your data. Point-in-time recovery, often shortened to PITR, lets you rewind a database to any chosen moment within a set period, by replaying a log of changes on top of a backup.

High availability, replica and failover

High availability, or HA, means a standby copy in another zone takes over automatically if the main one fails. A read replica is another copy used to serve read-only questions. Failover is the switch from a failed machine to its standby.

Server

Instance

The managed database server, with an engine, size and location.

Data

Database

A named collection of tables inside an instance.

Access

User

An account inside the database engine, with its own password or Google identity.

Power

vCPU and Memory

The thinking power and the quick working space of the server.

Safety

Backup and PITR

Saved copies plus a rewind button for mistakes.

Uptime

HA and Replica

A standby for failure and extra copies for reading.

!
Common Trap

Many beginners think “high availability” and “backup” are the same thing. They are not. HA protects you when a machine or zone fails. A backup protects you when data is deleted or damaged. Deleting a table is copied to the HA standby within moments. Only a backup or point-in-time recovery can bring it back.

AArchitecture and Main Components

Now let us zoom out and see how Cloud SQL connects to the applications that use it.

A typical setup has four groups of parts. First, the applications: web servers, containers or services that send SQL requests. Second, the network path: private addresses, firewall rules and secure connectors. Third, the Cloud SQL service itself: the primary instance, an optional standby and optional read replicas. Fourth, the supporting services: backups, logs, monitoring, identity and encryption keys.

flowchart TD
  subgraph APPS["Your Applications"]
    W1["Web Servers on Compute Engine"]
    K1["Containers on GKE"]
    R1["Cloud Run Services"]
  end
  PROXY["Cloud SQL Auth Proxy or Connectors"]
  W1 --> PROXY
  K1 --> PROXY
  R1 --> PROXY
  PROXY -->|"Encrypted private connection"| PRI
  subgraph CSQL["Cloud SQL Service Managed by Google"]
    subgraph ZA["Zone A"]
      PRI["Primary Instance"]
    end
    subgraph ZB["Zone B"]
      STB["Standby Instance for HA"]
    end
    PRI -->|"synchronous copy"| STB
    PRI -->|"asynchronous copy"| RR["Read Replica"]
    PRI --> DISK["Regional Storage"]
  end
  DISK --> BKP["Automated Backups and Logs"]
  KMS["Cloud KMS Encryption Keys"] -.-> CSQL
  IAM["IAM Permissions"] -.-> CSQL
  MON["Cloud Monitoring and Logging"] -.-> CSQL
Figure 1: A typical Cloud SQL layout. Applications reach the primary instance through a secure connection. A standby in another zone protects against failure, and a replica serves reads.

Walking through the picture

At the top are your applications, running on virtual machines, containers or serverless services. They need to send SQL requests. Instead of connecting directly with a bare password over an open path, they usually go through the Cloud SQL Auth Proxy or a language connector. These tools open an encrypted connection and check permissions with IAM, so you do not need to manage address allow lists or certificates by hand.

The requests arrive at the primary instance, which accepts all writes. In a high-availability setup, a standby instance in a different zone receives a synchronous copy of every change, which means the primary waits for the copy to be safe before confirming a write. An optional read replica receives changes asynchronously, which means slightly later, and answers read-only questions so the primary has less work.

Behind the scenes, data lives on Google’s disks, and backups and logs are stored separately. Around everything sit Cloud KMS for encryption keys, IAM for permissions, and monitoring and logging to watch the health of the instance.

Analogy

Think of a bank branch. The primary is the head teller who handles all deposits. The standby is a second teller in another building, who writes down every deposit at the same moment and can take over instantly if the first falls ill. The read replica is a clerk who answers balance enquiries from a copy of the books, so the head teller is not interrupted. The proxy is the security desk that checks each visitor’s identity.

Why this design works

Each part has one job. Applications only need the standard database language. The proxy handles safe connections. The primary handles writes and the truth of the data. The standby handles survival. The replicas handle extra reading. Google handles the machines. This split lets each part be improved or repaired without redesigning the whole.

Production example: mobile and web backends

Many app backends run their application servers on containers that start and stop all day, while a Cloud SQL instance holds the permanent records. Because the connection goes through the proxy and IAM, containers can come and go without anyone copying passwords or updating address lists.

IInternal Working: What Happens Under the Hood

This is the part many tutorials skip. Knowing it explains why Cloud SQL behaves the way it does.

The machine under the database

Each Cloud SQL instance runs on a virtual machine managed by Google. Inside that machine, the real database engine runs, together with small helper programs that handle backups, health checks, logging and communication with the Cloud SQL control system. You never log in to that machine, which is why you cannot install your own software on it or change the operating system. This is the price of being managed, and it is also the source of the service’s safety.

How a query is answered

When an application sends a question, the database engine follows a series of steps.

1

Parse

The engine reads the SQL text and checks that it is valid and that the tables and columns exist.

2

Plan

A part called the optimizer considers different ways of finding the answer, such as using an index or scanning the whole table, and picks the cheapest one using statistics about the data.

3

Execute

The engine follows the plan, fetching rows from memory when possible and from disk when needed.

4

Return

The result is sent back to the application.

Memory: the buffer pool

Disks are slow compared with memory. So databases keep recently used pieces of data in a large area of memory, often called the buffer pool or shared buffers. If a requested piece is already there, the answer is almost instant. If not, it must be read from disk first. A database with enough memory to hold its busiest data runs much faster than one that must keep going to disk.

Analogy

The buffer pool is the pile of books on a librarian’s desk. Books she has just used are within reach. Anything else needs a walk to the shelves in the back. A bigger desk means fewer walks.

How writes stay safe: the write-ahead log

Writing straight into the big data files on every change would be slow and risky. Instead, relational databases use a write-ahead log, often called the WAL in PostgreSQL, the redo log in MySQL’s InnoDB engine, and the transaction log in SQL Server. Before changing any data file, the engine first writes a short note of the change to the log, and forces that note safely to disk. Only then does it confirm the change. The data files are updated later in the background.

If the machine crashes, the engine reads the log on restart and replays any confirmed changes that had not yet reached the data files, and undoes any unfinished ones. This is how durability and atomicity are kept.

Analogy

The log is a ship captain’s journal. Before the crew rearranges the cargo, the captain writes down what is going to be moved. If a storm interrupts the work, the journal tells everyone exactly where things stood, so the job can be finished or undone safely.

The log also powers copies and rewind

The same stream of log notes is used for three other jobs. It is sent to the standby and to read replicas so they can repeat every change. It is stored for point-in-time recovery, so you can rewind to a chosen moment. And it supports tools that read changes for other systems. Understanding that the log is the heart of the engine makes replication, failover and recovery much easier to understand.

Locks and isolation

When many users change data together, the engine must keep them from stepping on each other. It uses locks, which are temporary “do not touch” marks on rows or tables, and a technique called multiversion concurrency control, or MVCC in some engines, which lets readers see a consistent older picture of data while writers change it. As a result, readers often do not block writers. But long-running transactions can still hold locks and cause others to wait, and even to fail with deadlocks, which happen when two transactions each wait for the other.

Storage under the engine

Cloud SQL stores data on Google’s network-attached block storage, similar to Persistent Disk. Because the disk is separate from the machine, it survives the loss of a machine, and its speed grows with its size and type. In a high-availability instance, the data is written in a way that is available to both zones, so a standby can take over using the same data.

The control plane

When you click “create instance”, “add a replica” or “restore backup”, you are talking to the Cloud SQL control plane, the management system that builds machines, installs engines, sets up networks and starts replication. The data plane is the running database and its traffic. These are separate, so a problem in the management system does not stop an already running database from answering queries.

i
Remember

Three ideas explain most Cloud SQL behavior: data lives in memory first and disk second, every change goes into a log first, and that log feeds the standby, the replicas and the rewind feature. When something puzzles you later, come back to these three.

Production example: surviving a crash

A busy shop’s database server restarts suddenly during a sale. Because every confirmed order was written to the log before it was confirmed, the engine replays the log on restart, and no confirmed order is lost. Customers may see a short pause, but not missing orders. This is the daily value of the write-ahead log.

EEngines and Editions: Choosing What to Run

Cloud SQL offers three engines and, for two of them, two editions. Picking well at the start saves pain later.

The three engines

Open source

MySQL

One of the world’s most widely used databases, loved for web applications. Simple to start, huge ecosystem, strong in read-heavy sites and content systems.

Open source

PostgreSQL

Known for rich features, strict correctness and extensions. A favorite for complex queries, geographic data, custom data types and modern applications.

Commercial

SQL Server

Microsoft’s database, common in companies that use Windows and .NET. Cloud SQL includes the license in the price, so you do not bring your own in the usual setup.

How to choose an engine

The best guide is what you already have. If your application was built for one engine, stay with it, because switching engines means rewriting queries and testing everything. If you are starting fresh, MySQL and PostgreSQL are both safe choices. PostgreSQL is often chosen for advanced features and extensions. MySQL is often chosen for simplicity and for many existing tools. Choose SQL Server mainly when your software depends on it.

Analogy

Choosing an engine is like choosing a language to write a book in. You can say nearly anything in any of them, but your team, your tools and your readers already speak one. Changing language mid-book means translating every page.

Versions

Each engine has major versions. Cloud SQL supports several recent ones and retires old ones after a notice period. Newer versions bring speed and security improvements, while old ones eventually stop receiving fixes. Pick a currently supported version for new work, and plan upgrades before your version reaches the end of its support.

Editions: Enterprise and Enterprise Plus

For MySQL and PostgreSQL, Cloud SQL offers two editions, which are bundles of features and performance at different prices. Google has adjusted details over time, so always confirm the current list in the documentation. In general:

QuestionEnterprise editionEnterprise Plus edition
Who is it for?Most standard applicationsDemanding, business-critical systems
PerformanceGood, general purposeHigher, with faster machine types and a data cache for read speed
Availability promiseA high uptime promise that usually excludes maintenance timeA higher promise that includes maintenance, with very short pauses for updates
Point-in-time recovery windowShorterLonger, up to about a month
PriceLowerHigher
i
Note

Edition names, features, limits and uptime promises are updated by Google over time. Treat this table as a general guide, and read the current service level agreement and edition comparison before you decide.

What you cannot do on a managed database

Being managed brings limits. You do not get operating system access to the machine. You cannot install arbitrary software or database add-ons that Google has not enabled. You do not get full “superuser” powers in the engine, but a special administrative role that covers nearly all normal tasks. Some low-level settings and file system paths are off limits. For most teams these limits are a feature, since they remove many ways to hurt yourself. If your application needs one of the blocked abilities, consider running the database yourself on Compute Engine, or use a different managed service.

Managed Cloud SQL: benefits

  • No patching, installing or machine repairs
  • Automatic backups, failover and monitoring
  • Real engines, so existing apps and skills transfer
  • Quick to create, resize and clone

Managed Cloud SQL: trade-offs

  • No operating system access
  • Only approved settings and extensions
  • Single primary for writes, so scale-up has limits
  • Costs more than a bare virtual machine

Production example: matching edition to risk

A company may run its internal tools on the standard edition to save money, while placing its customer-facing payments database on the higher edition, because even brief outages there cost real money. Matching the edition to what an hour of downtime costs is a sensible rule.

TThe Life of a Cloud SQL Instance: Data Flow and Lifecycle

From creation to deletion, every instance follows a story. Knowing each stage prevents surprises.

Creating an instance

You create an instance through the console, the command line, an API or an infrastructure tool such as Terraform. You choose the engine and version, the edition, the region and zone, the machine size, the storage type and size, the network settings, whether to enable high availability, the backup schedule and the maintenance window. You also set the password of the main administrative user.

1

Request and checks

Google checks your permissions, your quota and the validity of your settings.

2

Creating

The control plane builds the machine, attaches storage, installs the engine, joins the network and starts the database. This usually takes several minutes.

3

Runnable

The instance is ready. You create databases and users, load data and connect applications.

4

Operating

Backups run, logs flow, maintenance happens in your chosen window, and you resize or tune as needs change.

5

Stopped

You may stop an instance to save compute cost. Storage and backups still cost money while it is stopped.

6

Deleted

The instance and its data are removed. Final backups you took before deletion can remain, depending on your settings.

What happens when an application saves a row

sequenceDiagram
  participant A as Application
  participant P as Auth Proxy
  participant D as Primary Database Engine
  participant L as Write Ahead Log on Disk
  participant S as Standby in Zone B
  participant R as Read Replica
  A->>P: Send SQL INSERT or UPDATE
  P->>D: Forward over encrypted connection
  D->>L: Write change note to log
  D->>S: Send log record to standby
  S-->>D: Standby confirms log is safe
  L-->>D: Log safely on disk
  D-->>P: Transaction committed
  P-->>A: Success returned
  D-->>R: Send log record later
  R->>R: Replay change on replica
Figure 2: A write with high availability. The primary waits for its own log and for the standby, then confirms. The read replica receives the change slightly later.

What the picture shows

The application sends a change through the connection. The primary writes the change into its log. In a high-availability instance, the primary also sends the log record to the standby and waits for it to confirm that the record is safe. Only after both copies are safe does the primary tell the application “committed”. The read replica receives the same log record a little later, so replicas can briefly lag behind the primary.

What happens when an application reads data

For a read, the engine checks its memory first. If the needed data is there, it answers right away. If not, it reads from disk, places the data in memory for next time, and answers. Reads sent to a replica follow the same path on the replica’s own memory and disk, and may return data that is a moment old.

Data flow at runtime

While the instance runs, several streams of data move. Application queries flow in and results flow out. The log flows to the standby, to replicas and to storage for point-in-time recovery. Backups flow to protected storage. Metrics and logs flow to Cloud Monitoring and Cloud Logging. Administrative actions appear in audit logs.

!
Common Trap

Do not assume a read replica always has the latest data. Because copying is asynchronous, a replica may be a little behind. If a user saves a profile and immediately reloads it from a replica, they may briefly see the old version. Read data you just wrote from the primary.

Production example: separating busy writes from heavy reads

A news website records page views and comments on its primary database, while its reporting dashboards and search pages read from replicas. This keeps the editorial tools snappy even while thousands of readers browse at once.

MMachine Sizes, Storage and Sizing

Choosing the right size is like choosing the right vehicle: too small and you stall, too big and you waste money.

Machine types

Cloud SQL machines come in several styles. Shared-core machines are tiny and cheap, suitable for learning and light testing. Standard machines have a balanced amount of memory per processor. High-memory machines give much more memory per processor, which suits databases whose busy data is large. You can also create custom sizes within limits. Available shapes differ by engine and edition, so check the current list.

Tiny

Shared-core

For development, learning and very light use. Not meant for steady production loads.

Balanced

Standard

A good starting point for typical web applications and services.

Memory heavy

High-memory

For databases where keeping a large data set in memory is the key to speed.

Flexible

Custom

Pick the exact processors and memory you need within allowed limits.

Storage type and size

You choose between SSD storage, which is faster and is the standard choice, and HDD storage, which is cheaper and slower and is rarely right for busy databases. Storage size matters twice: it sets how much data you can keep, and in many cases it also sets how fast the disk can work, since larger disks are allowed more operations per second. If a database is slow because of disk limits, adding space may be the fix, even when you are not short of room.

Automatic storage increase

If you turn on automatic storage increase, Cloud SQL adds space when free space runs low, so the database does not fill up and stop. It is a safety net worth enabling. But note that storage can only be increased, not decreased, so a sudden temporary surge, such as a huge one-time import, can leave you paying for space you no longer need. To shrink, you must create a new instance with a smaller disk and move data over.

Analogy

Automatic storage increase is like a bathtub with an overflow valve that opens a larger tub when water nears the top. It prevents a flood, but the larger tub stays, even after the water level goes down.

The sizing rule of thumb

Because databases are fastest when their hot data fits in memory, the single most useful sizing question is: how big is the data that is used most often, and does it fit in memory with room to spare? If the answer is no, the database reads from disk often, and speed suffers. Add memory before adding processors, unless your charts show the processors are the limit.

Right-sizing step by step

  1. Start with an estimate based on a similar system, or with a modest standard size.
  2. Run a realistic test or a real workload and watch processor, memory, disk and connection charts for at least a week.
  3. If the processor is above seventy to eighty percent for long periods, add processors. If the database reads from disk heavily and memory is full, add memory.
  4. If the processor is always very low, consider a smaller size to save money.
  5. Repeat after major changes, such as a big launch or a new feature.

Resizing

You can change the machine size of an instance later. This is usually a restart event with a short interruption, so plan it for a quiet time. High-availability instances reduce the interruption, because a standby can take the load while the primary changes. Storage can be increased without a restart in most cases.

Connection limits depend on size

Each engine has a maximum number of simultaneous connections, and in Cloud SQL the default limit depends on the memory of the machine. Each connection uses memory. A common surprise is that a larger fleet of application servers, each opening many connections, exhausts the limit long before the database runs out of processing power. We return to this in the performance chapter.

!
Common Trap

Do not size by the processor count alone. A database with too little memory spends its time reading from disk, and no amount of extra processors will fix that. Look at memory pressure and disk reads first.

Production example: growth through right-sizing

A growing startup begins with a standard machine and watches its dashboards. As the customer table grows beyond memory, disk reads rise and pages slow down. The team moves to a high-memory size, and speed returns without any code changes. They keep checking each quarter so that the size follows the growth.

CConnectivity and Networking

A database is only useful when applications can reach it, and only safe when strangers cannot. This chapter explains how both are achieved.

Public IP and private IP

An IP address is the number that identifies a machine on a network. A Cloud SQL instance can have a public IP, which is reachable from the internet, a private IP, which is reachable only from inside your private network, or both. For production systems, private IP is the safer default, because the database is then not exposed to the internet.

Private IP: how it works

Cloud SQL runs in a network owned by Google, while your applications run in your own VPC, a Virtual Private Cloud, which is your private network in Google Cloud. To join the two, Cloud SQL uses private services access, which creates a private link called peering, and you reserve a block of private addresses for it. Newer options, such as Private Service Connect, expose the instance as a single private endpoint in your own network. The available methods and details may vary, so check the current documentation.

Analogy

A public IP is like a shop with a door on the main street: anyone can walk up and try the handle. A private IP is like an office inside a secure campus: only people who are already inside the gates can reach the door.

Authorized networks

If you use a public IP, you must tell Cloud SQL which addresses may connect. These are called authorized networks. Never add “everyone”, which is written as a range covering the whole internet. Even with a password, an open database invites constant attack attempts.

The Cloud SQL Auth Proxy and connectors

The Cloud SQL Auth Proxy is a small program that runs next to your application. It opens an encrypted connection to the instance, checks the caller’s IAM permissions, and handles certificates automatically. Your application connects to the proxy as if it were a local database. Google also offers language connectors for popular languages such as Java, Python and Go, which do the same job inside your code without a separate program. Using the proxy or a connector is the recommended way to connect, because it works with both public and private addresses and removes the need to manage address lists and certificates.

flowchart LR
  subgraph PROJ["Your Google Cloud Project"]
    subgraph VPC["Your VPC Network"]
      APP1["App on Compute Engine"]
      APP2["App on GKE"]
      SRV["Cloud Run with VPC connector"]
    end
  end
  subgraph ONP["Office or On-premises"]
    DEV["Developer or Legacy System"]
  end
  subgraph GOOG["Google Managed Network"]
    SQLI["Cloud SQL Instance with Private IP"]
  end
  APP1 -->|"Private connection"| SQLI
  APP2 -->|"Private connection"| SQLI
  SRV -->|"Private connection"| SQLI
  DEV -->|"Cloud VPN or Interconnect"| VPC
  DEV -.->|"through your VPC"| SQLI
  NET["Public Internet"] -. "blocked: no public IP" .-> SQLI
Figure 3: A private-only setup. Applications and approved offices reach the instance through private paths, and the public internet has no way in.

Firewall and routing

Even with private IP, network rules matter. Your VPC firewall rules must allow outgoing traffic from applications to the database’s address and port. Routes must exist from where your clients are to the database’s network. If you connect from an office, you need a Cloud VPN tunnel or a Cloud Interconnect line, and address ranges that do not overlap with the ranges used by Google’s side.

Encryption in transit

Data traveling between the application and the database can be encrypted using SSL or TLS, which are standard methods for scrambling data on the wire. The Auth Proxy and connectors always use encryption. For direct connections, you can require SSL on the instance, so any unencrypted connection is refused. For anything sensitive, turn this on.

Connecting serverless services

Serverless services, such as Cloud Run and Cloud Functions, can connect to Cloud SQL using built-in connection support, or through a VPC connector. Since serverless services can create many instances quickly, watch the total number of connections, and use connection pooling, which is explained in the next chapter.

Connection checklist

1

Choose private IP

Unless there is a clear reason, avoid a public IP on production databases.

2

Use the proxy or a connector

Encrypted, identity-checked connections without manual certificate work.

3

Require SSL for direct connections

Refuse unencrypted connections at the instance.

4

Limit who can reach the port

Narrow firewall rules and, if public, a small authorized network list.

5

Plan address ranges

Avoid overlaps between your networks and the reserved ranges.

i
Pro Tip

When a connection fails, work through the layers in order: Is the instance running? Does the application have a route and firewall path? Does the identity have permission to connect? Are the user name, password and database name right? Most connection problems are found in the first two questions.

Production example: private-only databases

Security-conscious companies commonly run their databases with no public IP at all. Their applications reach the database through the proxy over private paths, and administrators connect through approved tunnels. Even if a password leaked, an outsider on the internet could not reach the database port.

PPerformance and Tuning

Speed is where database knowledge pays off. Most slow databases are slow for a few common reasons, and most are fixable.

What “fast” means for a database

  • Latency is how long a single query takes. Users feel this directly.
  • Throughput is how many queries or transactions are handled per second.
  • Concurrency is how many users or connections are active at the same time.

A system can have fine throughput and awful latency for some users, so look at both, and look at the slowest few percent of queries, not just the average.

The usual suspects

Queries

Slow or wasteful queries

Queries that scan whole tables, fetch far more rows than needed, or repeat thousands of times for one page.

Indexes

Missing or unused indexes

No lookup structure on the columns used to find or sort data, or too many indexes slowing writes.

Memory

Too little memory

Hot data does not fit in memory, so the engine reads from disk again and again.

Connections

Too many connections

Hundreds of idle or busy connections wasting memory and causing contention.

Locks

Blocking and deadlocks

Long transactions holding locks while others wait.

Disk

Disk limits

Storage speed limits reached by heavy reads or writes.

Find slow queries first: Query Insights

Never tune by guessing. Cloud SQL provides Query Insights, a built-in tool that shows which queries use the most time, how often they run, and where time goes. You can also turn on the engine’s slow query log to record queries that take longer than a chosen time. Start with the few queries that use the most total time, because fixing one of them often helps the whole system.

Indexes: the biggest single lever

Adding the right index can turn a query from minutes to milliseconds. Create indexes on columns that are used often in filters, joins and sorting. Use the engine’s explain command, which shows the plan the optimizer will use, to check whether an index is being used. Remember the trade-off: every index makes writes slower and takes space, so do not index everything. Remove indexes that are never used.

Analogy

An index is the index at the back of a textbook. With it, you find a topic in seconds. Without it, you read every page. But a book where every single word is indexed would be as thick as the book itself, and the printer would be unhappy every time a page changed.

Write good queries

  • Ask only for the columns and rows you need, not “everything”.
  • Avoid running one query per item in a loop. Fetch many items in one query instead. This pattern, known as the N plus one problem, is a classic cause of slow pages.
  • Use pagination for long lists rather than loading thousands of rows.
  • Keep transactions short, and never keep one open while waiting for a person or a slow outside service.

Connection pooling

Opening a database connection is expensive, and each open connection uses memory. A connection pool keeps a small set of open connections and lends them to requests as needed, instead of opening a new one every time. Most application frameworks include pooling. For very large fleets, a separate pooling program, such as PgBouncer for PostgreSQL, or a managed pooling feature where Cloud SQL offers one, sits between the application and the database. Pooling lets thousands of application threads share a few dozen real connections.

Analogy

A pool is like a taxi rank. Instead of building a new taxi each time someone needs a ride, a fixed group of taxis waits and takes the next passenger. A few taxis can serve many people.

Caching in front of the database

The fastest query is the one never sent. A cache, such as Memorystore for Redis or Memcached, stores answers to common questions in memory so the database is asked less often. Cache data that is read often and changes rarely, such as product details. Set a time limit on cached values so they refresh. Some editions of Cloud SQL also include an internal data cache that uses fast local storage to speed up reads.

Tuning with flags

Database flags let you change engine settings, such as memory areas, timeouts and logging. Change them carefully, one at a time, and measure. Some flags need a restart. Many popular tuning guides assume you control the entire server, so check that a flag is allowed on Cloud SQL before you rely on advice.

Operations that hurt performance

  • Heavy reports run directly on the primary during business hours. Send them to a replica or a data warehouse instead.
  • Large one-time updates or deletes in one huge transaction. Break them into small batches.
  • Schema changes on big tables at busy times. Use online methods or off-peak windows.
  • Missing regular maintenance, such as updating table statistics, which the optimizer uses to choose plans.

A simple performance routine

1

Measure

Look at processor, memory, disk and connection charts, and at the top queries by total time.

2

Find the bottleneck

Decide whether the limit is queries, memory, disk, connections or locks.

3

Fix the biggest item

Add an index, rewrite a query, add pooling, or add memory, one change at a time.

4

Measure again

Confirm the change helped, and keep a note of what you did.

!
Common Trap

Do not respond to every slowdown by buying a bigger machine. A single missing index or an N plus one pattern can waste far more power than any upgrade can supply. Bigger hardware hides a bad query for a while, and the bill stays high long after.

Production example: the one-index fix

A commonly told story: an e-commerce page takes eight seconds to open because it searches orders by customer email with no index. The team adds one index, and the page opens in under a tenth of a second, with no change in hardware. Looking at the top slow queries first is what revealed it.

SScalability: Scaling Up, Reading Out

What do you do when one database is not enough? This chapter walks through the options, from the simplest to the most complex.

Why relational databases scale differently

A relational database keeps its data consistent through one main copy that accepts changes. That is why a single primary is simple and reliable. It is also why you cannot just add ten more servers and expect writes to be ten times faster. Scaling a relational database takes a few well-known steps.

Step 1: tune first

Before adding hardware, fix queries, add indexes, use pooling and add caching. This is cheapest and often removes the need for anything else.

Step 2: scale up (vertical scaling)

Scale up means moving to a bigger machine, with more processors and memory. It is simple and needs no change to the application. It has limits, since machines only get so big, and big machines get expensive, and resizing means a brief restart.

Step 3: scale out for reads with read replicas

Many applications read far more than they write. A read replica is a copy of the primary that receives changes through replication and serves read-only queries. By sending reports, search pages and browsing traffic to replicas, you take load off the primary. You can have several replicas, in the same region or in different regions. A replica in another region also brings data closer to far-away users and can serve as a disaster recovery copy.

flowchart TD
  APP["Application"] -->|"writes and fresh reads"| PRI["Primary Instance Region 1"]
  APP -->|"general reads"| RR1["Read Replica 1 Region 1"]
  APP -->|"general reads"| RR2["Read Replica 2 Region 1"]
  REP["Reporting Tools"] --> RR2
  PRI -->|"asynchronous replication"| RR1
  PRI -->|"asynchronous replication"| RR2
  PRI -->|"asynchronous replication"| XR["Cross-region Replica Region 2"]
  FAR["Users in another continent"] --> XR
  XR -.->|"promote in disaster"| NEWP["New Primary"]
Figure 4: Scaling reads. The primary takes writes, replicas share reading, and a cross-region replica serves distant users and can be promoted in a disaster.

Replica lag

Because replication is asynchronous, a replica can fall behind during heavy writing. The delay is called replica lag. Watch it in monitoring. For data that must be fresh, such as a customer’s own just-saved changes, read from the primary. For data that can be a little old, such as a public product list, a replica is fine.

Step 4: split the data (sharding and functional splitting)

When even a very large primary cannot keep up with writes or data size, teams split the data. Functional splitting moves different parts of the application to different databases, for example separating user accounts, orders and analytics. Sharding splits one huge table across several databases using a rule, such as customer number ranges. Sharding is powerful but adds real complexity to queries, transactions and operations, so it should come last. If you find yourself needing it, also look seriously at services built for scale, such as Spanner or AlloyDB.

Analogy

Scaling a database is like handling a busy library. First reorganize the shelves so books are easy to find (tuning). Then build a bigger library (scale up). Then open branches that hold copies of popular books for lending (read replicas). Finally, split the collection by subject across several buildings (sharding), which is the hardest of all because borrowers must now know which building to visit.

Comparing the steps

StepHelps withEffortMain catch
Tuning and cachingReads and writesLowNeeds measurement and care
Scale upEverything, within limitsLowCeiling and brief restart
Read replicasReads onlyMediumReplica lag and read routing in the app
Functional splitWrites and data sizeHighCross-database queries become hard
ShardingWrites and data size at huge scaleVery highComplex application and operations

Routing reads and writes

To use replicas, the application must know which connection is for writes and which is for reads. Many frameworks support a “read replica” setting. Some teams add a routing layer or a proxy that sends read-only statements to replicas automatically. Test the behavior carefully, especially for code that writes and then reads back immediately.

i
Pro Tip

Plan for read routing early, even if you have only one database today. If your code already distinguishes “write connection” from “read connection”, adding a replica later is a quiet configuration change instead of a risky rewrite.

Production example: reporting off the primary

Many companies place a read replica dedicated to business reports and dashboards. Analysts can run long queries all day without slowing customer-facing pages, and if a report is heavy enough to hurt the replica, customers on the primary never notice.

HHigh Availability and Automatic Failover

Machines break and buildings lose power. A highly available database is one that keeps going anyway, with little or no human help.

What availability means

Availability is the share of time a service works. It is often written in “nines”. Ninety-nine point nine percent allows under nine hours of downtime a year. Ninety-nine point ninety-five percent allows about four and a half hours. Ninety-nine point nine nine percent allows under an hour. Each added nine is harder and costlier to reach. Google publishes a written promise of uptime, called an SLA, for Cloud SQL, with different numbers for different editions and for instances with and without high availability. Read the current SLA for exact values and conditions.

A single-zone instance

Without high availability, an instance runs in one zone. Google protects the disk with copies inside its storage system, and if the machine fails, Cloud SQL restarts the instance, but this can take a while, and a zone-wide problem can stop it until the zone recovers. This is fine for development and for many low-risk systems, but not for important production work.

The high-availability configuration

When you enable high availability, Cloud SQL creates a regional instance. It keeps a primary in one zone and a standby in another zone of the same region. Both use a regional storage design, so a copy of the data is safely available to either one. Every change is written to both zones before it is confirmed, so the standby is always ready with all confirmed data. The standby does not serve queries. It only waits to take over.

flowchart TD
  APP["Applications"] --> IP["Single Instance Address"]
  IP --> PRI["Primary - Zone A"]
  PRI -->|"every write copied before confirm"| STB["Standby - Zone B"]
  PRI --> RD["Regional Disk across zones"]
  STB --> RD
  HM["Health Monitoring"] -.-> PRI
  HM -.->|"detects failure"| FO["Failover starts"]
  FO -->|"standby becomes primary"| STB
  FO -.->|"old primary rebuilt as new standby"| PRI
Figure 5: High availability. If the primary fails, the standby in the other zone becomes the new primary behind the same address, and the failed one is rebuilt as the new standby.

How failover works

1

Detect

Health checks notice that the primary is not responding, for example because its machine failed or its zone has a problem.

2

Decide

The control system confirms the failure, so that a brief hiccup does not cause a needless switch.

3

Switch

The standby becomes the primary. The instance address moves to it, so applications use the same address as before.

4

Recover the old primary

The failed machine is rebuilt and becomes the new standby, restoring protection.

During the switch, existing connections are dropped and applications must reconnect. A typical failover takes on the order of a minute or less, though this can vary. Applications that retry connections smoothly will recover without human help.

Analogy

It is like an airline with two pilots in the cockpit. The second pilot follows every action and can take the controls at once if the first falls ill. Passengers feel a small bump, but the plane keeps flying, and a replacement second pilot joins at the next stop.

Designing applications that survive failover

  • Retry connections with a short delay and a limit, instead of failing at the first error.
  • Use connection pools that detect broken connections and replace them.
  • Keep transactions short and safe to repeat, since a transaction that was in progress during failover is rolled back.
  • Test failover in a staging environment. Cloud SQL lets you start a manual failover so you can watch how your application behaves.

What high availability does not do

  • It does not protect against mistaken deletes or bad updates, since those are copied to the standby too.
  • It does not protect against the loss of an entire region. For that, you need a cross-region replica or backups stored elsewhere.
  • It does not make the standby serve reads. For read scaling, use read replicas.

Disaster recovery across regions

To survive the loss of a whole region, create a cross-region read replica. In a disaster, you promote the replica, which turns it into a standalone primary, and you point your applications at it. Promotion is a one-way step, so practice it first. A recovery point objective, the amount of recent data you could lose, depends on replica lag at the moment of the disaster, since replication to another region is asynchronous.

Two numbers to decide

RTO, the Recovery Time Objective, is how long you can afford to be down. RPO, the Recovery Point Objective, is how much recent data you can afford to lose. A shop that cannot lose any orders and can accept only a minute of downtime needs high availability within a region and a tested recovery plan for regional disasters. A small internal tool that can be down for an hour and lose a day of data can use just daily backups.

!
Common Trap

Do not switch on high availability and assume you are done. Teams often forget that their application cannot reconnect after a failover, because the code or the pool does not retry. An untested failover is a hope, not a plan. Rehearse it.

Production example: surviving a zone problem

A payments company runs its database with high availability. When one zone in the region suffers a power problem, the standby in another zone takes over within a minute. Its applications retry and reconnect, and customers see at most a short delay. The team reviews the incident afterwards, and nobody had to wake in the night to rebuild a server.

BBackups, Point-in-Time Recovery and Disaster Recovery

Data gets deleted by mistake, damaged by bugs and sometimes attacked. Backups are the way back.

Why high availability is not a backup

High availability copies every change instantly, including the bad ones. If someone runs a command that deletes a table, both zones lose it within moments. A backup is an older copy that is not changed when live data changes. HA protects against hardware failure. Backups protect against human error, bad code and attacks.

Analogy

High availability is a second copy of a document that updates in real time. If you scribble over one, you have scribbled over both. A backup is a photograph of the document taken last night. Only the photograph brings the old page back.

Automated backups

Cloud SQL can take a daily automated backup during a window you choose. It keeps a number of recent backups, with a default of about a week, and you can change how many to keep. Backups are incremental after the first one, which means they store only what changed. Google stores them separately from the instance’s disk. You can also take an on-demand backup at any time, for example before a risky change.

Point-in-time recovery

Point-in-time recovery, or PITR, lets you restore the database to any chosen second within a set period. It works by keeping the continuous log of changes, which you learned about earlier, and replaying it on top of a backup up to the moment you pick. For example, if someone deleted a table at 2:14 in the afternoon, you can recover the database to 2:13 and one second. The recovery period depends on how long logs are kept, and Enterprise Plus can keep them longer. Turning on PITR also uses extra storage for the logs.

Restoring: choices

Option 1

Restore to the same instance

Overwrites the current data with the backup. Quick, but destroys changes made after the backup, so use with care.

Option 2

Restore to a new instance

Creates a fresh instance from the backup, leaving the original untouched. Safer for investigations and partial recovery.

Option 3

Point-in-time clone

Creates a new instance as the database stood at a chosen moment, so you can pull out a lost table without disturbing production.

Exports and imports

Besides backups, you can export a database to a file in Cloud Storage, in SQL or CSV form, and import it elsewhere. Exports are useful for moving data between systems and for long-term archives, but they are logical copies and can take a long time on large databases. Backups and PITR are the main tools for fast recovery.

Protecting backups

Backups hold all your data, so treat them as seriously as the database. Restrict who can restore, since a restore creates a readable copy. Restrict who can delete, since deleting removes your safety net. Remember that deleting an instance may remove its automated backups, so keep a final on-demand backup or an export before you delete anything important.

A sensible protection plan

1

Automated daily backups

Keep enough days to cover how long a mistake might take to be noticed.

2

Point-in-time recovery on

Allows rewinding to the minute for human errors.

3

High availability for hardware failures

Standby in another zone for survival of machine and zone problems.

4

Cross-region replica or copies for disasters

For systems that must survive the loss of a region.

5

Regular restore tests

Every quarter, restore a backup into a test instance and check the data. An untested backup is only a hope.

Retention and rules

Some industries require you to keep data for years, or to delete it after a set time. Plan retention to match your rules. Long-term archives can be kept as exports in Cloud Storage with lifecycle rules, which is cheaper than keeping many backups inside the database service.

!
Common Trap

A backup you have never restored is an unproven backup. Many teams discover during a real emergency that the backup was missing a database, had expired, or took longer to restore than their business could wait. Practice restores so you know the real time it takes.

Production example: recovering from a bad deployment

A software release contains a bug that wrongly updates thousands of customer records. The team notices twenty minutes later. They create a point-in-time clone of the database from just before the release, extract the correct values, and repair the records. The main database never stops, and customers see little impact.

SSecurity for Cloud SQL

A database holds the most valuable things a company owns. Good security uses several layers, so one mistake does not open the door.

The shared responsibility model

Google secures the data centers, the hardware, the host machines, the operating system, the patching of the database engine and the storage system. You are responsible for who can reach the database, who can manage it, which users exist and what they can do inside, how data is protected in your application, and how passwords and keys are kept. Because Cloud SQL is managed, your share is smaller than with a database you run yourself, but it is never zero.

Analogy

Using Cloud SQL is like keeping valuables in a bank vault. The bank guards the building, the vault door and the cameras. You still decide who gets keys, what you put inside, and whether you leave the key lying on a table.

Layer 1: network

Use private IP, and avoid public IP for production. If you must use public IP, list a few specific authorized addresses, never the whole internet. Keep database instances in separate projects or networks from public-facing test systems. Use narrow firewall rules.

Layer 2: encrypted connections

Use the Cloud SQL Auth Proxy or connectors, which always encrypt. For direct connections, require SSL so unencrypted connections are refused. Consider requiring client certificates for the highest sensitivity.

Layer 3: IAM for management and connection

IAM controls who can create, change, back up, restore or delete instances, and who can connect through the proxy. Roles such as Cloud SQL Admin, Editor, Client and Viewer bundle permissions. Follow least privilege: give each person or program only what it needs. Keep the power to delete instances and backups limited to a few trusted people.

Layer 4: users inside the database

Inside the engine, create separate users for separate applications and for people, each with only the rights they need on only the databases they need. Never let applications use the main administrative user. If one application is compromised, the damage is limited to what that user could do.

Layer 5: IAM database authentication

Cloud SQL supports IAM database authentication for MySQL and PostgreSQL, where a user logs in with a short-lived Google access token instead of a stored password. This removes long-lived passwords from configuration files and makes access easier to audit and revoke. Where passwords are still used, keep them in Secret Manager, never in source code or images, and rotate them regularly.

Encryption at rest and customer-managed keys

Data on disk, backups and logs are encrypted by default using keys that Google manages. If your rules demand more control, you can use customer-managed encryption keys, or CMEK, through Cloud KMS, so you control the keys and can disable them to make data unreadable. Choose CMEK at creation time, since it generally cannot be added to an existing instance.

Auditing

Cloud Audit Logs record administrative actions, such as who created or deleted an instance. For PostgreSQL, the pgAudit extension and for MySQL and SQL Server, engine audit options can record what users do inside the database. Auditing is essential for rules about sensitive data and for investigating incidents. Keep logs long enough to meet your rules.

Organization policies and guardrails

A central team can use organization policies to enforce safe rules across many projects, such as forbidding public IP on database instances, or requiring customer-managed keys. Rules enforced by the platform are stronger than rules in a document that people may forget.

Data-level protection

Think about what is stored. Do not keep secrets or card numbers in plain form if you can avoid them. Mask or tokenize sensitive values. Use application-level encryption for the most sensitive fields. Limit test and development databases to fake or masked data, not copies of real customer information.

1

Isolate the network

Private IP, narrow rules, no open authorized networks.

2

Encrypt connections

Proxy or connectors, SSL required.

3

Control identities

Least-privilege IAM, separate database users, IAM database authentication where possible.

4

Protect secrets and keys

Secret Manager, rotation, CMEK where required.

5

Audit and alert

Audit logs, database auditing and alerts on unusual access.

!
Common Trap

The most common serious mistake is a public database open to the whole internet with a weak password. Attackers scan for these continuously. Remove public IP where you can, never authorize every address, and use strong, rotated secrets.

Production example: regulated data

Healthcare and finance organizations commonly run databases with private IP only, customer-managed encryption keys, IAM-based logins, detailed audit logs and separate projects for production, so they can show auditors who accessed which data and when.

MMaintenance, Updates and Upgrades

Even managed databases must be updated. This chapter explains how Google does it and how you can make it painless.

Why maintenance happens

Software has flaws that are found and fixed over time. Operating systems and database engines receive security fixes and improvements. Hardware is replaced and updated. Cloud SQL applies these updates for you, which is a large part of the value of a managed service. But applying many updates needs a restart of the database, so the timing matters.

Maintenance windows

You choose a maintenance window, a weekly time slot, such as late on a Sunday night, in which Cloud SQL may perform updates. You can also set an order of update to make test instances update before production ones, so you see problems early. Pick the quietest period of your traffic, in the time zone of your users.

Deny periods

A maintenance deny period blocks maintenance for a chosen range of days, up to a limit set by Google. Use it around critical dates, such as a holiday sale or a financial year end, so that no update interrupts the busiest time. Security-critical updates may still be applied in rare cases.

How long does maintenance take

For the standard edition, maintenance usually causes a short outage, often measured in minutes. High-availability instances reduce the downtime by updating the standby first, switching over, and then updating the old primary. In the Enterprise Plus edition, Google aims for near-zero downtime maintenance, with pauses measured in seconds. Details depend on the type of update, so check current documentation.

Self-service maintenance

You can sometimes ask for maintenance to happen sooner than the scheduled window, such as to receive a fix quickly. Some updates are optional and can be rescheduled, and others, particularly security updates, are required.

Major version upgrades

Engines release new major versions, such as a new number of PostgreSQL or MySQL. Cloud SQL supports in-place major version upgrades for some engines, and you can also upgrade by creating a new instance and migrating data. Major upgrades can change behavior, remove old features and change how queries are planned. Always test your application against the new version first. A good method is to clone the production instance, upgrade the clone, run your tests and compare speed. Only then upgrade production.

End of support

Old database versions eventually reach the end of their support period. After that, Google may charge extra for extended support, or require an upgrade. Keep a calendar of end-of-support dates, and plan upgrades months ahead, not in the final week.

Schema changes

Changing the structure of tables, such as adding a column or an index, can lock a large table and block users. Use methods designed for live systems, such as adding indexes in a way that does not block writes where the engine supports it, making changes in small steps, and testing on a clone. Avoid large schema changes at peak times.

Analogy

Maintenance windows are like the hours a shop closes for cleaning. A shop that cleans in the middle of a busy afternoon loses customers, but one that cleans at six on a Sunday morning loses nobody. Deny periods are like declaring “no cleaning on the week before Christmas”.

i
Pro Tip

Make your applications ready for short database pauses at any time, not only in the window. Retries, connection pools that heal themselves and short, repeatable transactions turn a surprise restart from an outage into a blip that nobody notices.

Production example: safe upgrade rehearsal

Before moving a large database to a new major version, a team clones production, upgrades the clone, replays a day of real traffic against it and compares the speed of the top queries. They find two queries whose plans changed for the worse, fix them with indexes, and only then upgrade production during a quiet window.

MMonitoring, Logging and Metrics

You cannot fix what you cannot see. Monitoring turns a mysterious slow database into a clear picture.

The three kinds of signals

Metrics are numbers over time, such as processor use. Logs are written messages about events, such as a slow query or a failed login. Alerts are messages sent when something needs attention. Together they answer: Is something wrong? What went wrong? Who must act?

Metrics Cloud SQL provides

Cloud SQL sends metrics to Cloud Monitoring automatically. Important ones include processor utilization, memory utilization, disk utilization and disk read and write activity, the number of connections, queries per second, network traffic, and for replicas, the replication lag. Names can change, so check the current list in the console.

What to watch

CPU

Processor use

Sustained use above seventy to eighty percent means queries are queueing or the machine is too small.

Memory

Memory use

Pressure here means the engine cannot keep hot data in memory, so disk reads rise.

Disk

Free space and activity

Alert before space runs out, and watch for reads and writes near the disk’s limits.

Connections

Connection count

Compare it with the maximum, to catch leaks and floods before they cause errors.

Replication

Replica lag

Rising lag means replicas serve old data and may be unfit for failover.

Health

Backups and failovers

Alert on failed backups and on any failover event.

Query Insights

Query Insights shows the top queries by total time, the frequency and the load they cause, and can connect a slow spike to the application code and the user that sent it. It is the first place to look when a database is slow. Use it regularly, not only in emergencies.

Logs

Cloud SQL writes engine logs, such as error logs and, if enabled, slow query logs and audit logs, to Cloud Logging. Admin actions are in Cloud Audit Logs. You can search them, chart them and send copies to storage or other tools. Turn on the slow query log with a sensible threshold, and keep an eye on log volume, since very verbose logging costs money and can slow the database.

Recommendations

Google Cloud provides automatic recommendations that spot patterns, such as an oversized instance, an instance with no backups, a database with open access or a table that would benefit from an index. Review them monthly as a free source of ideas.

Alerts that help, not annoy

Alert on symptoms that matter to users and that a person can act on, such as disk almost full, connections near the limit, high replica lag, failed backups, or long queries blocking others. Avoid alerts that fire constantly for small things. Attach a runbook, a short written list of steps, to each alert, so whoever is on duty knows what to do.

Golden signals for databases

  • Latency: how long queries take, especially the slowest few percent.
  • Traffic: queries or transactions per second.
  • Errors: failed queries, failed connections, deadlocks.
  • Saturation: how close processor, memory, disk and connections are to their limits.
Analogy

Monitoring is the dashboard of a car. The fuel gauge is free disk space, the speedometer is queries per second, the temperature light is processor use and the warning lamps are alerts. Driving a database without a dashboard means you learn about trouble only when the engine stops.

Production example: catching a leak

A team notices the connection count climbing steadily every day until the database refuses new users each Friday. Charts show one service that opens connections and never returns them. They fix the leak, add an alert at eighty percent of the limit and the weekly incident disappears.

PPricing and Cost Control

A managed database costs more than a bare machine, and the bill has several parts. Understanding them is how you avoid surprises.

Per hour
compute is billed for each hour an instance runs
Per GB
storage and backups are billed by size
About double
high availability roughly doubles compute and storage cost

What you pay for

  • Compute: processors and memory, billed for every hour the instance is running, at a rate that depends on the engine, the edition, the size and the region.
  • Storage: the provisioned disk, billed per gigabyte per month, with different prices for SSD and HDD.
  • Backups: the stored backup data beyond what is included, and the log storage for point-in-time recovery.
  • High availability: the standby adds compute and storage cost, so the instance costs roughly twice a single one.
  • Read replicas: each replica is billed as its own instance, with its own compute and storage.
  • Network: traffic leaving Google Cloud and some traffic between regions.
  • Licenses: for SQL Server, the license cost is part of the hourly price and can be a large share.

Prices change and differ by region and edition. Always read the current pricing pages and use the pricing calculator before you commit to a design.

Ways to save money

  1. Right-size. Use the monitoring charts and recommendations to match size to the real load.
  2. Use the right edition. Pay for the higher edition only where its benefits matter.
  3. Use high availability only where needed. Development and test instances rarely need it.
  4. Stop idle non-production instances. A stopped instance does not charge for compute, though storage still costs. Schedules can stop test databases at night and on weekends.
  5. Delete unused instances, replicas and old backups. Use labels and owners to find them.
  6. Use committed use discounts for steady production instances, where Google offers a lower price in return for a one- or three-year promise.
  7. Avoid over-large storage. Storage can grow but not shrink, so grow in steps, and archive old data to cheaper storage.
  8. Reduce unnecessary logging and long backup retention if your rules do not require them.
  9. Cache and tune. Cheaper than a bigger machine, as discussed earlier.
  10. Set budgets and alerts so someone is told before costs grow too far.

Compare the options on total cost

OptionDirect costHidden cost
Cloud SQLHigher than a bare VMLow, since Google handles patching, backups and failover
Database on a Compute Engine VMLower hourly priceYour team’s time for patching, backups, failover, monitoring and nights on call
AlloyDB or SpannerOften higherPays off at larger scale or special needs
Analogy

Cloud SQL is like paying a taxi fare instead of owning a car. The fare per kilometer is higher than the cost of petrol, but you skip the car loan, the insurance, the repairs and the parking. The right question is the total cost of the whole arrangement, including your own time.

i
Pro Tip

Put the cost of your own time into the comparison. A database on a virtual machine looks cheaper on paper, but patching, backup testing, failover design, monitoring and weekend emergencies all have a price. Many teams find the managed service cheaper in total.

Production example: scheduled development databases

Many organizations keep dozens of development and test databases. By labeling them, stopping them outside working hours and deleting those that nobody has used for a month, they cut their database bill significantly without touching production.

DDesign Patterns and Anti-patterns

A pattern is a proven way to solve a common problem. An anti-pattern looks reasonable but causes pain later.

Patterns that work

Pattern

Primary plus replicas

Writes and fresh reads go to the primary, while reports and browsing traffic go to read replicas.

Pattern

Connection pooling layer

Applications share a small set of database connections through a pool or pooler, so large fleets do not exhaust the limit.

Pattern

Cache in front

Common answers are served from a cache, which reduces queries and keeps the database for work only it can do.

Pattern

One database user per application

Each service has its own account with only the rights it needs, limiting damage if one is compromised.

Pattern

Offload analytics

Heavy reporting is sent to a replica or a data warehouse such as BigQuery, so customers are not slowed by analysts.

Pattern

Layered protection

High availability for failures, backups and point-in-time recovery for mistakes, and cross-region copies for disasters.

Pattern

Database per service

In microservice designs, each service owns its own database or schema, so services do not break each other’s data.

Pattern

Migrations as code

Schema changes are written as versioned scripts, reviewed, tested on a clone and applied in order.

Analogy

The cache-in-front pattern is like a shop assistant who remembers the answers to the ten most common customer questions, and only walks to the manager’s office for hard ones. The manager’s time is saved for what only the manager can decide.

Anti-patterns to avoid

ANTI-PATTERN 01Avoid
What it looks like

A production database with a public IP, an authorized network entry covering the whole internet, and a shared administrator password in the application code.

Why it hurts

Attackers scan constantly for open databases. One leaked password gives them everything, and nobody can tell which application did what.

What to do instead

Use private IP, the Auth Proxy, IAM database authentication or secrets stored in Secret Manager, and a separate limited user for each application.

ANTI-PATTERN 02Avoid
What it looks like

The team relies on high availability alone, with backups turned off, to save money.

Why it hurts

A mistaken delete or a faulty release is copied to the standby at once. With no backup or point-in-time recovery, the data is gone for good.

What to do instead

Keep automated backups and point-in-time recovery on, and test restores regularly.

ANTI-PATTERN 03Avoid
What it looks like

Every page load runs one query per item in a list, and each web request opens a new database connection.

Why it hurts

Hundreds of tiny queries add up in delay, and thousands of connections exhaust memory and hit the connection limit long before the machine is truly busy.

What to do instead

Fetch groups of items in single queries, use connection pooling, and look at Query Insights for the worst offenders.

ANTI-PATTERN 04Avoid
What it looks like

Heavy reports, large exports and big batch updates run directly on the primary during business hours.

Why it hurts

They use processor, memory and disk and hold locks, so customer-facing queries slow down or time out.

What to do instead

Run reports on a replica or warehouse, break batch changes into small batches and schedule heavy work off-peak.

ANTI-PATTERN 05Avoid
What it looks like

One huge shared database holds every application’s tables, and any team can change any table.

Why it hurts

A change or a heavy query from one team breaks others. Nobody owns the data, and a single problem becomes a company-wide outage.

What to do instead

Give services their own databases or schemas with clear owners, and control access with separate users.

ANTI-PATTERN 06Avoid
What it looks like

The team uses the database as a message queue, a file store and a cache, all at once.

Why it hurts

Constant polling, huge binary blobs and short-lived rows create load and bloat, which slow everything else and make backups large.

What to do instead

Use Pub/Sub for messages, Cloud Storage for files and Memorystore for caching, and keep the database for relational data.

BBest Practices and Common Mistakes

This chapter gathers the habits of teams that run databases well, and the mistakes of those who learned the hard way.

Best practices: planning

  • Choose the engine your application and team already know, and use a currently supported version.
  • Choose the edition and high-availability setting from the real cost of downtime, not just the monthly bill.
  • Place the database in the same region as most of its applications, to cut delay on every query.
  • Use separate projects and networks for development, testing and production.
  • Define instances, users, flags and backup settings as code with a tool such as Terraform, so every change is reviewed and repeatable.
  • Label every instance with owner, project, environment and cost center.

Best practices: reliability

  • Enable high availability for production, and test a manual failover.
  • Turn on automated backups and point-in-time recovery, and test restores each quarter.
  • Write applications to retry connections and to cope with short pauses.
  • Use read replicas for reporting, and a cross-region replica when the business must survive a regional disaster.
  • Set maintenance windows in quiet times and deny periods around critical dates.

Best practices: performance

  • Check Query Insights every week and fix the top queries first.
  • Index columns used in filters, joins and sorting, and remove unused indexes.
  • Use connection pooling, and keep transactions short.
  • Size memory so that hot data fits, and add storage if disk limits are reached.
  • Add caching for data that is read often and changes rarely.

Best practices: security

  • Use private IP, the Auth Proxy or connectors, and require SSL.
  • Use least-privilege IAM, separate database users per application and IAM database authentication where possible.
  • Keep secrets in Secret Manager and rotate them.
  • Use customer-managed keys when your rules demand control of keys, and enable audit logging.
  • Keep test and development data masked or fake.

Common mistakes

MistakeWhat goes wrongFix
Public IP open to everyoneConstant attack attempts, risk of data theftPrivate IP, Auth Proxy, narrow rules
Treating HA as a backupMistaken deletes are copied instantlyKeep backups and point-in-time recovery
Never testing restores or failoverSurprises during real emergenciesRehearse both regularly
Using the admin user in applicationsOne leak exposes everythingOne limited user per application
Ignoring connection limitsErrors when the fleet grows or serverless scalesPooling and connection alerts
Buying a bigger machine for every slowdownHigh cost, problem returnsFind slow queries and missing indexes first
Reading fresh data from lagging replicasUsers see stale informationRead just-written data from the primary
Letting storage fill upThe database stops accepting writesEnable automatic increase and alerts
Skipping upgrade rehearsalsPlan changes make queries slow after upgradeClone, upgrade and test before production
Forgetting old instances and backupsHourly charges that never stopLabels, owners and monthly review
i
Pro Tip

Before launching any important database, ask four questions. What happens if the primary dies right now? What happens if someone deletes a table by mistake? What will this cost at ten times the traffic? Who gets alerted when it runs short of space or connections, and what do they do? If you cannot answer all four, you are not ready.

A database is the one part of the system you can never afford to lose, so plan for failure before it happens.

MMigrating to Cloud SQL

Most teams do not start with an empty database. They have data that lives somewhere else and must be moved without stopping the business.

Migration styles

StyleHow it worksDowntimeBest for
Dump and loadExport the data to files, copy them, and import into Cloud SQLLonger, during the whole copySmall databases, test systems, acceptable maintenance windows
Continuous migrationCopy the data once, then keep it in sync with ongoing changes until cutoverVery short, at the final switchProduction systems that cannot be offline long
Replication from an external sourceMake Cloud SQL a replica of your existing server, then promote itShortTeams comfortable with their engine’s replication tools
Rebuild with a new engineConvert schema and code from one engine to anotherDepends on projectMoving away from commercial databases

Database Migration Service

Database Migration Service, or DMS, is Google’s managed tool for moving databases into Cloud SQL. For same-engine moves, such as MySQL to MySQL or PostgreSQL to PostgreSQL, it can do an initial copy and then continuous replication, so your old and new databases stay in step until you cut over. It handles many details and gives you a view of progress. Some paths use separate tools or offer conversion helpers for moves between different engines, so check the current support list.

A safe migration path

1

Assess

List databases, sizes, engines and versions, extensions, users, jobs and applications that depend on them. Check what Cloud SQL supports, such as versions, extensions and flags.

2

Design the target

Choose engine, edition, size, storage, high availability, network and security settings. Plan address ranges so they do not overlap.

3

Connect the networks

Build private connectivity, such as Cloud VPN or Interconnect, between your current site and your Google Cloud network.

4

Copy and sync

Run the initial copy and then keep the target in sync with ongoing changes, watching the delay.

5

Test

Point a copy of the application at the new database. Compare data, check performance and run your normal tests.

6

Cut over

Pause writes on the old database, let the last changes arrive, check the data, switch the applications to the new database and promote it.

7

Keep a fallback and then clean up

Keep the old database read-only for a safe period. When all is well, retire it.

Analogy

Continuous migration is like moving to a new office while the old one stays open. A team keeps carrying boxes and tracks every new document that arrives, so on moving day, only the last few papers need to be carried across, and clients hardly notice the change.

Things that surprise teams

  • Unsupported features. Cloud SQL does not allow every extension, flag or privilege. Check your list early.
  • Users and permissions. These may need to be recreated with the proper limited roles, since you do not get a full superuser.
  • Latency. If the application stays in the old site while the database moves to the cloud, every query crosses a long link and pages may feel slow. Move tightly connected parts together.
  • Large objects and special data types may need extra care during copy.
  • Sequences and identity counters must be set correctly after the move, or new rows may clash with old ones.
  • Time zones and character sets can differ, causing subtle data differences. Test carefully.
  • Cost shape. Cloud billing is ongoing and flexible, so a lifted-and-moved system may cost more than expected until right-sized.

After the move

Review the sizing against real load, set up alerts, test failover and restores, enable recommendations and schedule regular reviews. A migration is not finished at cutover. It is finished when the new system is measured, protected and understood by the people who run it.

i
Pro Tip

Do a full rehearsal migration on a copy of production before the real one. Time each step, note each problem, and write the cutover plan as a checklist. The real event then becomes a calm repeat of something you have already done.

Production example: moving off self-managed servers

Companies that ran MySQL or PostgreSQL on their own servers often move to a managed service to stop spending nights on patching and backups. They use continuous replication for production, rehearse the cutover and keep the old servers read-only for a few weeks. The final switch takes minutes instead of a weekend.

RReal-World and Industry Examples

Let us look at the kinds of work that managed relational databases carry every day. Companies seldom publish detailed designs, so these examples describe typical patterns in each industry.

E-commerce and retail

Online shops keep customers, products, prices, stock, orders and payments in a relational database, because orders need strong guarantees. Retailers prepare for sale days by testing load, raising instance sizes, adding read replicas for browsing, and putting caches in front of catalog pages, while the primary protects the integrity of orders.

Software as a service

Business software companies store accounts, settings, subscriptions, billing records and customer data in a database, often with one schema or database per customer group. They value managed backups and easy cloning, because cloning gives each developer or test run its own realistic copy of the data.

Financial technology

Payment, lending and banking applications need strict correctness and clear audit trails. They typically use high availability, point-in-time recovery, private-only networking, customer-managed keys and detailed audit logging, with cross-region replicas for disaster plans.

Healthcare and life sciences

Patient scheduling, records and study data live in relational databases with strong access controls and long retention rules. Teams apply least-privilege access, masked test data and audited logins, so they can show who saw each record.

Gaming and mobile apps

Games keep player accounts, purchases and inventories in a relational database, while fast-changing data, such as live positions, lives in other services. Mobile backends use pooling and caching, because many small stateless servers connect all at once.

Content management and publishing

Popular content systems, such as blogs and news sites built on MySQL-based platforms, move easily to Cloud SQL, since the engine is the same. Editors write to the primary, while reader traffic is served by caches and replicas.

Enterprise applications and lift-and-move

Many business applications, including ones that run on SQL Server, were built for traditional servers. Companies move them to Cloud SQL to avoid running database servers, often using continuous migration to keep downtime short.

What these stories have in common

Every example shares the same ideas. A relational database holds the data that must be correct. The application connects through a safe, encrypted path with limited users. High availability handles failures, backups and point-in-time recovery handle mistakes, and replicas handle extra reading. Caches and pooling protect the database from needless work. Costs follow size, availability level and housekeeping. The industries differ, but the design habits are the same.

i
Note

These examples describe common industry patterns rather than specific company designs. Your own design should always start from your own workload, your own data and your own tolerance for risk.

FFrequently Asked Questions

Short, direct answers to questions that beginners ask most often.

Q1What is Cloud SQL in one sentence?
Cloud SQL is Google Cloud’s managed service for relational databases, running MySQL, PostgreSQL and SQL Server, with Google handling machines, patching, backups and failover.
Q2Which engines does Cloud SQL support?
MySQL, PostgreSQL and SQL Server. Supported versions change over time, so check the current list before you start.
Q3How is Cloud SQL different from running a database on a virtual machine?
On a virtual machine you manage everything: installation, patching, backups, failover, monitoring and security of the operating system. In Cloud SQL, Google does most of this. You give up operating system access and some settings, and in return you save time and avoid many risks.
Q4How is Cloud SQL different from AlloyDB and Spanner?
Cloud SQL runs standard MySQL, PostgreSQL and SQL Server on a single primary. AlloyDB is a PostgreSQL-compatible service designed for higher performance and mixed workloads. Spanner is a globally distributed relational database built for enormous scale and strong consistency across regions. Start with Cloud SQL, and move up when your needs clearly exceed it.
Q5What is high availability in Cloud SQL?
It is a setup with a primary in one zone and a standby in another zone of the same region. Every change is copied to both before it is confirmed. If the primary fails, the standby takes over, usually within about a minute, using the same address.
Q6Does high availability replace backups?
No. High availability protects against machine and zone failures. Backups and point-in-time recovery protect against mistaken deletes, bad changes and attacks. You need both.
Q7What is point-in-time recovery?
It lets you restore a database to any chosen moment within a retention period, by replaying the log of changes on top of a backup. It is the best tool for undoing a mistake made at a known time.
Q8What is a read replica and when should I use one?
A read replica is a copy of the primary that receives changes and serves read-only queries. Use it to take reporting and browsing traffic off the primary, to serve users in other regions, or as a disaster recovery copy. Remember that replicas can lag slightly behind the primary.
Q9Can I connect to Cloud SQL without a public IP?
Yes. Use a private IP and connect from inside your VPC, or through a VPN or Interconnect from outside. The Cloud SQL Auth Proxy and language connectors work with private IP and are the recommended way to connect.
Q10What does the Cloud SQL Auth Proxy do?
It opens an encrypted connection from your application to the instance, checks IAM permissions and handles certificates for you, so you do not need to manage address allow lists or certificates manually.
Q11Can I shrink the storage of an instance?
No, storage can only be increased. To reduce it, create a new instance with a smaller disk and migrate the data. Because of this, grow storage in steps rather than far ahead of need.
Q12Why do I see “too many connections” errors?
Each engine has a maximum number of connections, which depends on the memory of the machine. Large fleets, serverless services or code that forgets to close connections can reach it. Use connection pooling, close connections properly and monitor the connection count.
Q13When does maintenance happen, and can I control it?
Maintenance happens in a weekly window you choose, and you can add deny periods around critical dates. Standard maintenance may cause a short restart, high-availability instances reduce the downtime, and Enterprise Plus aims for near-zero downtime.
Q14Is my data encrypted?
Yes. Data at rest, including backups, is encrypted by default with keys managed by Google, and you can choose customer-managed keys. Data in transit is encrypted when you use the Auth Proxy, connectors or required SSL.
Q15How do I keep costs down?
Right-size machines using charts and recommendations, use high availability and higher editions only where needed, stop or delete non-production instances, clean up old backups, use committed use discounts for steady systems, tune queries and add caching.
Q16How do I move an existing database to Cloud SQL?
Use Database Migration Service for continuous migration with little downtime, or export and import for small databases. Assess compatibility, rehearse the migration, test the application and keep the old database as a fallback for a while after cutover.
Q17How is Cloud SQL similar to Amazon RDS or Azure SQL Database?
All are managed relational database services. Cloud SQL and Amazon RDS both run familiar engines such as MySQL, PostgreSQL and SQL Server. The core ideas, such as backups, standby copies, read replicas and maintenance windows, carry across, though names, limits and prices differ.

SSummary and Key Takeaways

You have now seen Cloud SQL from the outside and from the inside. Here is the whole story in one place.

Cloud SQL gives you a real MySQL, PostgreSQL or SQL Server database that Google installs, patches, backs up and watches. Applications connect through a safe, encrypted path to a primary instance. Every change goes into a log first, and that log feeds the standby, the replicas and the rewind feature. You choose the size, the edition and the availability level, and you design the queries, indexes, users and recovery plan that make the database fast, safe and dependable.

Key Takeaways

  • Use it for relational data. Choose Cloud SQL for classic relational workloads on MySQL, PostgreSQL or SQL Server, and look to AlloyDB or Spanner only when you clearly outgrow one primary instance.
  • Understand the engine. Data lives in memory first and disk second, every change goes into a log first, and that log powers failover, replicas and point-in-time recovery.
  • Protect against both failures and mistakes. Use high availability for machine and zone failures, and backups with point-in-time recovery for human error. Practice restores and failover.
  • Tune before you buy. Check Query Insights, add the right indexes, use connection pooling and caching, and only then scale up or add read replicas.
  • Lock the doors. Use private IP, the Auth Proxy, required SSL, least-privilege IAM, separate database users, Secret Manager and audit logs.
  • Plan size, storage and cost. Right-size from real charts, remember that storage can only grow, run high availability where it matters, and clean up idle instances and old backups.
  • Treat operations as part of the design. Set maintenance windows and deny periods, rehearse upgrades on clones, monitor the golden signals and keep runbooks and infrastructure code up to date.