A PostgreSQL-compatible connection string can make a migration look trivial while hiding a breaking change in transaction semantics, supported SQL, recovery procedures, or primary-key design.

TL;DR

  • Problem: Treating Cloud SQL, AlloyDB, and Spanner’s PostgreSQL interface as small, medium, and large tiers of the same database leads to blocked migrations, broken ORMs, or over-engineered distributed schemas.
  • Answer: Select the service by matching your workload’s hard constraints—PostgreSQL dialect fidelity, storage ceiling, read-pool scale, SLA tier, and PITR window—before writing migration code.
  • Watch out: Spanner’s PGAdapter translates wire traffic, not PostgreSQL internals; DDL transactions, SERIAL keys, and most pg_catalog views fail or behave differently.

Requirements determine the shortlist

Situation

Platform engineering teams standardizing PostgreSQL workloads on Google Cloud face three distinct managed database offerings: Cloud SQL for PostgreSQL, AlloyDB for PostgreSQL, and Spanner with its PostgreSQL interface. On paper, all three accept PostgreSQL drivers and SQL syntax. In practice, they represent three different storage engines, availability models, and operational contracts.

Engineers coming from AWS often reach for familiar analogies: Cloud SQL resembles Amazon RDS, and AlloyDB’s disaggregated compute-and-storage architecture resembles Amazon Aurora. Those comparisons help frame initial architecture questions about replication, read scaling, and storage elasticity, but they do not transfer exact failover timings, pricing models, or extension support. Spanner has no direct RDS equivalent; it is a globally distributed database built on Paxos consensus and TrueTime that exposes a PostgreSQL-dialect surface rather than running a PostgreSQL server process.

When a platform catalog groups all three under a single “managed PostgreSQL” label, application teams assume they can start on Cloud SQL and later swap the connection string to AlloyDB or Spanner without changing schema design, ORM migrations, or operational runbooks.

The Problem

Portability assumptions break down along four hard technical boundaries: compatibility, capacity ceilings, availability guarantees, and recovery windows.

Constraint 1: Storage, compute, and read-scaling ceilings. Cloud SQL for PostgreSQL supports up to 64 TB of storage on dedicated-core instances (3 TB on shared-core), with a hard PostgreSQL table limit of 32 TB. Compute scales up to 96 vCPUs and 624 GiB RAM on Enterprise Edition, or 128 vCPUs and 864 GiB RAM on Enterprise Plus Edition. AlloyDB for PostgreSQL raises the cluster storage ceiling to 128 TiB, scales individual compute nodes up to 288 vCPUs and 2,232 GiB RAM, and supports up to 20 read-pool nodes per cluster across all read pools. Exceeding 64 TB total storage or needing independent, fast-scaling read-pool nodes beyond standard Cloud SQL replicas forces an architectural move to AlloyDB, while exceeding a single-cluster write primary forces horizontal sharding or Spanner.

Constraint 2: Availability SLAs and failover mechanics. Cloud SQL Enterprise Edition with Regional High Availability (HA) carries a 99.95% availability SLA, rising to 99.99% on Enterprise Plus with HA (or a read pool of 2 or more nodes), with typical HA failover times of 60 to 120 seconds. AlloyDB with HA enabled carries a 99.99% availability SLA across standard regions (99.95% in Stockholm) and targets under-60-second failover using a warm standby VM over shared storage. Spanner offers a 99.99% SLA for regional instances in standard regions and a 99.999% SLA for dual-region and multi-region instances. Any workload with a contractual requirement for 99.999% availability or active multi-region writes cannot be satisfied by Cloud SQL or AlloyDB alone.

Constraint 3: Point-in-time recovery (PITR) retention windows. Cloud SQL Enterprise retains PITR write-ahead logs for 1 to 7 days, whereas Enterprise Plus extends PITR retention up to 35 days. AlloyDB enables continuous backups by default with a 14-day PITR window, configurable from 1 to 35 days. Spanner controls PITR through version_retention_period, which defaults to just 1 hour and caps at 7 days maximum. Moving a workload with a 30-day compliance PITR requirement onto Spanner breaks that retention contract unless supplemented by scheduled exports.

Constraint 4: Dialect and wire-protocol fidelity. Spanner’s PostgreSQL interface relies on PGAdapter to translate PostgreSQL wire-protocol traffic into Spanner gRPC calls. PGAdapter does not support SSL/TLS between the client and the proxy itself (requiring local or sidecar deployment in a trusted network), does not support DDL statements inside explicit BEGIN ... COMMIT transactions, does not support SERIAL or IDENTITY auto-incrementing keys, and omits many pg_catalog tables expected by ORMs and administrative tools like pgAdmin.

Hard service ceilings separate Cloud SQL, AlloyDB, and Spanner

Which database contract does the workload actually require, and what measurable constraint justifies taking on a different operational or SQL boundary?

Options Considered

Platform teams typically evaluate four deployment paths when standardizing PostgreSQL workloads on Google Cloud.

OptionPostgreSQL FidelityMax Storage & ScaleAvailability & PITRPrimary Rejection or Selection Reason
Self-managed on GCE100% upstream PostgreSQLBound by PD limits and manual shardingSelf-managed HA; custom WAL retentionRejected as baseline due to patching, failover, and backup toil
Cloud SQL for PostgreSQLFull managed PostgreSQL + curated extensions64 TB storage, 128 vCPU (Ent Plus), single primary99.95% (Ent) / 99.99% (Ent Plus); 7d / 35d PITRDefault choice when single-primary PostgreSQL fits load
AlloyDB for PostgreSQLHigh PostgreSQL compatibility + columnar engine128 TiB storage, 288 vCPU/node, 20 read-pool nodes99.99% HA (<60s failover); 1-35d PITR (14d default)Chosen for >64 TB, read-heavy pools, or faster HA failover
Spanner (PG Interface)PostgreSQL dialect subset via PGAdapterHorizontal multi-region writes and storage99.99% regional / 99.999% multi-region; 7d max PITRChosen only when distributed writes or 99.999% SLA justify schema changes

Self-managed PostgreSQL on Compute Engine (GCE) preserves 100% control over operating system packages, custom C extensions, and kernel tuning. However, it shifts synchronous replication, fencing, WAL archiving, minor-version patching, and restore drills onto the platform team. Unless a workload depends on an unapproved extension or custom kernel behavior, GCE self-management adds operational risk without improving application outcomes.

Cloud SQL for PostgreSQL is the lowest-friction managed option. It preserves standard PostgreSQL operational mental models and supports both Enterprise and Enterprise Plus tiers. It is rejected only when storage exceeds 64 TB, a single table approaches 32 TB, read-replica lag or count becomes unmanageable, or failover latency under 60 seconds is mandatory.

AlloyDB for PostgreSQL decouples compute VMs from a shared, WAL-backed storage layer. It is the right upgrade path when a workload outgrows Cloud SQL’s storage or read-scaling model while still requiring full PostgreSQL semantics, extensions, and up to 35-day PITR. It is rejected when the application requires active multi-region writes or a 99.999% availability SLA.

Spanner with the PostgreSQL interface solves horizontal write scaling and multi-region consensus. It is rejected as a general-purpose PostgreSQL target because its dialect subset, key-distribution requirements, 7-day PITR cap, and PGAdapter operational model require application-level adaptation.

Each service trades PostgreSQL fidelity for distributed scale

Start with Behavior, Then Choose the Service

A database selection framework must map application behavior to the underlying storage and proxy topology before provisioning infrastructure.

Storage and proxy boundaries define each database contract

Cloud SQL: instance-coupled compute and blast radius

Cloud SQL manages individual PostgreSQL instances backed by regional persistent disks. In an HA configuration, a primary VM in Zone A replicates synchronously to a standby VM in Zone B. Because a Cloud SQL instance, a logical PostgreSQL database, and a Google Cloud project are distinct objects, placing multiple logical databases on one instance couples their CPU, connection limits, maintenance windows, and failover blast radius.

Fleet inventory and chargeback must track instances separately from logical databases. Consolidating low-traffic microservices onto a shared instance saves baseline VM cost, but any schema lock storm, connection-pool exhaustion, or major-version upgrade affects every tenant on that instance.

AlloyDB: disaggregated storage and independent read pools

AlloyDB organizes resources into clusters and instances. The primary HA instance consumes vCPUs across two VMs (primary and hot standby) attached to a shared distributed storage layer that scales automatically up to 128 TiB. Read-pool instances run as separate VMs (1 to 20 nodes total per cluster) reading from the same storage layer without duplicating full storage volumes per replica.

While read pools add horizontal read capacity, they do not eliminate replication lag or connection-routing responsibility. Applications must explicitly separate read-only queries onto the read-pool endpoint and define acceptable read staleness. Furthermore, if writes push cluster storage past its allocated quota, AlloyDB rejects INSERT and UPDATE transactions with a storage-exceeded error, making storage-quota alerting mandatory.

Spanner: PGAdapter proxy and Paxos-replicated splits

Spanner’s PostgreSQL interface places PGAdapter—either as an application sidecar, a local process, or an in-process library—between standard PostgreSQL drivers and Spanner’s native gRPC API. PGAdapter translates the wire protocol, while Spanner executes queries against Paxos-replicated data splits coordinated by TrueTime.

Because PGAdapter does not terminate TLS from the client, production deployments must bind it to localhost or a trusted pod network namespace. More importantly, every Spanner table requires an explicit primary key designed to avoid monotonic hotspots; migrating a PostgreSQL schema that relies on SERIAL or BIGSERIAL sequences will serialize writes onto a single split unless refactored to UUIDv4 or bit-reversed sequences.

To enforce Spanner’s maximum 7-day PITR window explicitly rather than relying on the 1-hour default, create the database, then set version_retention_period with a DDL update (the retention period cannot be passed to the create call; the allowed range is 1 hour to 7 days):

gcloud spanner databases create ledger_db \
  --instance=prod-spanner-us \
  --database-dialect=POSTGRESQL

gcloud spanner databases ddl update ledger_db \
  --instance=prod-spanner-us \
  --ddl='ALTER DATABASE "ledger_db" SET "spanner.version_retention_period" = '"'"'7d'"'"';'

For Cloud SQL and AlloyDB, verify extension availability and PITR retention directly in Terraform or gcloud during provisioning so compliance boundaries are codified rather than assumed.

Compare recovery and support boundaries

For every shortlisted service, document five operational boundaries before approving production use: failure domain (zonal vs. regional), cross-region disaster recovery mechanism, backup and PITR retention window, application reconnect behavior during failover, and the owner of quarterly restore drills. An advertised SLA covers infrastructure uptime, not application-level data corruption or unindexed query timeouts after a failover.

How It Rolls Out

Selecting and adopting a database contract should follow four sequential verification gates, each with a clear pass criterion and rollback path.

Four verification gates prevent costly database re-platforming

Gate 1: Dialect, extension, and ORM audit

Inventory every PostgreSQL extension, procedural function, custom data type, pg_catalog query, and ORM migration pattern in the codebase. Execute the application’s full schema migration suite—including BEGIN/COMMIT DDL blocks—against the target service. If targeting Spanner, verify that PGAdapter handles all driver authentication modes (password only) and COPY semantics (STDIN/STDOUT only). A psql connection check does not pass this gate; the full migration and integration test suite must execute cleanly.

Gate 2: SLA, PITR, and quota alignment

Validate that the chosen service tier meets contractual availability and data-retention requirements. Confirm whether 99.95% (Cloud SQL Enterprise) or 99.99% (Cloud SQL Enterprise Plus, AlloyDB HA, Spanner regional) suffices, or if 99.999% (Spanner multi-region) is required. Lock in PITR retention (1-35d on Cloud SQL Enterprise Plus / AlloyDB, 7d max on Spanner) and verify project-region vCPU and storage quotas so provisioning does not stall mid-rollout.

Gate 3: Peak-load and forced-failover benchmark

Replay a representative workload—matching production read/write ratios, connection concurrency, and working-set size—against the target service. During peak write load, trigger a forced HA failover (gcloud sql instances failover or AlloyDB failover) and measure connection-pool recovery time, error rates, and p99 tail latency. On Spanner, inspect key-distribution metrics to confirm no single split absorbs disproportionate write traffic.

Gate 4: PITR restore drill and cutover

Before routing production writes, execute a full point-in-time restore into an isolated clone instance and run application-level data-integrity checks. Document exact restore duration to establish an empirical Recovery Time Objective (RTO). Until production writes cut over, rollback is a trivial connection-string or DNS revert. Once production writes begin on the new engine, rollback requires either dual-writes or Change Data Capture (CDC) replication back to the legacy database.

In Practice

Google Cloud’s documented behavior across these three services reinforces why compatibility testing must go beyond wire-protocol connectivity.

In Cloud SQL for PostgreSQL, Google documents that individual PostgreSQL tables remain bounded by the upstream 32 TB table limit even when instance storage scales to 64 TB, and that Enterprise Edition caps PITR log retention at 7 days compared to 35 days on Enterprise Plus. Platform teams that select Enterprise Edition for cost savings and later discover a 30-day audit PITR requirement must upgrade editions rather than flipping a single flag.

In AlloyDB for PostgreSQL, Google documents that cluster storage scales up to 128 TiB and read pools cap at 20 total nodes across a cluster, with primary HA instances consuming vCPUs across two VMs. Because read-pool nodes share the underlying storage layer, scaling read capacity is fast, but teams must still engineer read/write splitting and monitor cluster storage quotas to prevent write rejections.

In Spanner’s PostgreSQL interface, Google’s known-issues documentation explicitly calls out behavioral differences in SQL functions (such as edge cases in string/array functions and numeric underflow) alongside PGAdapter’s documented restrictions: no client-to-PGAdapter SSL, no transactional DDL blocks, and partial pg_catalog coverage. Treating Spanner as a drop-in PostgreSQL replacement fails at ORM migration time, whereas treating it as a distributed database with a familiar query syntax succeeds when schemas are designed around distributed primary keys.

Where It Breaks

ConditionBreaks howDetectMitigate
ORM runs DDL inside transactions on SpannerPGAdapter rejects BEGIN ... CREATE TABLE ... COMMIT blocksCI schema-migration test fails immediatelySplit DDL into implicit transactions or native Spanner DDL batches
Sequential primary keys on SpannerSERIAL or timestamp keys pin writes to one Paxos splitHigh CPU on single split; elevated write latencyRefactor primary keys to UUIDv4 or bit-reversed sequences
Client expects TLS directly to PGAdapterPGAdapter does not support SSL on client-to-proxy legTLS handshake errors on startupRun PGAdapter on localhost or as a pod sidecar
30-day PITR assumed on Spanner or Cloud SQL EntSpanner caps at 7d (version_retention_period); Cloud SQL Ent caps at 7dCompliance audit fails on retention checkUse Cloud SQL Ent Plus / AlloyDB (35d) or scheduled exports
Regional HA mistaken for cross-region DRRegional outage takes down both primary and synchronous standbyRegion-level fault simulation fails RTOProvision cross-region read replica and drill promotion
Multiple critical apps share one Cloud SQL instanceNoisy neighbor saturates CPU/connections; maintenance hits allShared instance CPU throttling or lock waitsIsolate tier-1 workloads onto dedicated instances
AlloyDB cluster hits allocated storage quotaINSERT/UPDATE statements fail with storage-exceeded errorsStorage utilization alert >85%Enable auto-resize monitoring and enforce quota headroom
Stale reads routed from AlloyDB read poolApplication reads uncommitted or lagging state after writeRead-after-write consistency bugs in UIRoute read-after-write paths to primary or enforce staleness bounds

Contract mismatches surface in production under load or failover

Key Takeaways

  • Never classify Cloud SQL, AlloyDB, and Spanner as small, medium, and large tiers of PostgreSQL; each exposes a distinct storage engine, failure boundary, and SQL contract.
  • Use Cloud SQL Enterprise Plus (up to 64 TB, 128 vCPUs, 99.99% SLA, 35-day PITR) as the default managed PostgreSQL baseline unless storage, read-pool count, or failover speed forces a change.
  • Move to AlloyDB when workloads require up to 128 TiB storage, up to 20 independent read-pool nodes, or sub-60-second HA failover without rewriting PostgreSQL schemas.
  • Adopt Spanner’s PostgreSQL interface only when horizontal multi-region writes or a 99.999% SLA justify refactoring primary keys, removing transactional DDL, and running PGAdapter sidecars.
  • Validate every candidate through four gates—full ORM/dialect execution, SLA/PITR alignment, forced-failover load testing, and a timed PITR restore drill—before committing production writes.

What to Do Next

  • Problem: Map every workload’s hard constraints across PostgreSQL extensions, table/cluster size, SLA target, and PITR retention window.
  • Solution: Assign each workload to Cloud SQL, AlloyDB, or Spanner based on its binding constraint rather than familiarity or perceived tiering.
  • Proof: Pass all four verification gates—especially ORM migration execution, forced HA failover under load, and a timed PITR restore drill—in a staging environment.
  • Action: Codify the approved service boundaries, Terraform defaults (version_retention_period, HA flags, and storage alerts), and re-evaluation triggers in your platform catalog this week.

Sources to Verify