Managed relational databases
Why use a managed relational database?
A managed relational database stores related records in tables and delegates selected operational tasks, such as hardware management and backup scheduling, to a cloud provider. The application still owns its schema, queries, access rules, data quality and recovery requirements. Think of the bookstore checkout: its stock and order records must agree even if an operation fails. A database transaction groups changes so they can be committed together or rolled back together.
Use a relational engine when relationships, constraints and transactions are central to the workload. A managed service can reduce maintenance effort, but it does not remove the need for database design, secure configuration, performance tuning or restore testing.
See a transaction protect two related tables
The following SQL is a local SQLite 3.46.1 teaching fixture, not a cloud deployment. The complete setup and checks are in lab-fixtures/offline/chapter-20-relational-databases.json. The fixture enables SQLite foreign-key enforcement for each connection. A primary key identifies a row; a foreign key links an order to an existing book; a CHECK constraint rejects negative stock.
CREATE TABLE books (id INTEGER PRIMARY KEY, stock INTEGER NOT NULL CHECK (stock >= 0));CREATE TABLE orders (id INTEGER PRIMARY KEY, book_id INTEGER NOT NULL REFERENCES books(id));INSERT INTO books VALUES (1, 3);BEGIN;UPDATE books SET stock = stock - 1 WHERE id = 1 AND stock > 0;INSERT INTO orders VALUES (101, 1);COMMIT;SELECT stock FROM books WHERE id = 1;SELECT COUNT(*) FROM orders;Expected results: stock is 2 and the order count is 1. In this fixed fixture the guarded update changes one row. In real checkout code, verify that exactly one row changed before inserting an order, handle concurrent requests and roll back on failure. If the stock update fails or changes zero rows, do not insert an order. The local test also tries a duplicate order ID after reducing stock, rolls back the transaction and verifies that stock remains 2. A transaction does not automatically undo external actions such as sending email; coordinate those separately.
Select an engine before selecting a cloud service
The database engine determines the SQL dialect, data types, extensions, drivers and transaction behavior. Start with application compatibility, not a cloud product name. For a PostgreSQL application, investigate Amazon RDS for PostgreSQL, Azure Database for PostgreSQL flexible server and Google Cloud SQL for PostgreSQL. Aurora PostgreSQL and AlloyDB are PostgreSQL-compatible alternatives with different managed architectures; compatibility is not identical behavior for all extensions, versions or administration privileges. Aurora also offers a MySQL-compatible engine. RDS and Cloud SQL have MySQL and SQL Server options; Azure SQL Database belongs to the SQL Server family and is not PostgreSQL. Azure Database for MySQL is a separate service.
Before selecting a service, inventory schema features, extension versions, driver support, collation, authentication, backup retention, regional availability and maintenance policy. Test schema migration, realistic queries and failure handling using a supported version. Do not select a larger or proprietary architecture merely because it advertises high throughput. Measure workload performance and cost.
Separate high availability, read scaling and recovery
High availability (HA) reduces service interruption during failures by maintaining a redundant database arrangement. A standby may be promoted when the primary fails. Synchronous replication can reduce loss of acknowledged writes under its documented failure assumptions, but it can add commit latency. Asynchronous replication permits lag: a reader may return an older version of the data. Use the primary, or an explicitly supported consistency mechanism, when checkout requires a current stock value.
A classic Amazon RDS Multi-AZ DB instance has a synchronous standby in another zone that does not serve application reads. The Multi-AZ DB cluster design has readable standby instances; separately configured read replicas serve another purpose. Azure Database for PostgreSQL flexible server offers HA standby configurations, and Cloud SQL offers regional HA with failover to a secondary zone. Verify supported regions, editions and engines; do not assume every configuration has automatic regional failover. Aurora and AlloyDB use different cluster architectures.
A backup preserves recoverable historical data. Replication normally copies changes, including mistaken deletions, so replication cannot replace backups. A snapshot provides a recovery point; point-in-time recovery (PITR) uses a backup and retained change logs to recover to an eligible time. A service may restore to a new instance or database instead of rewinding the original. Check retention, latest restorable time and restoration restrictions. A same-region standby is not automatically protection against a regional disaster.
Estimate cost and choose a first architecture
Suppose a fictional PostgreSQL bookstore needs 100 GB of database storage, one standby for zonal resilience and 30 GB of chargeable backup storage. Hypothetical monthly inputs: primary compute $80, standby compute $80, storage $0.20/GB for 200 billed GB in total, chargeable backup $0.10/GB, I/O $12, network $5, license $0. Total = 80 + 80 + 40 + 3 + 12 + 5 = $220. This is a worksheet, not any provider tariff; actual HA storage billing, included backup allowances, license terms and I/O charges vary. Read replicas, restored copies, retained snapshots and extended support may add cost.
For this workload choose an engine already supported by the application, a private database endpoint, an appropriate HA configuration, backup retention that covers the business recovery window and a tested restore plan. Use a least-privilege application role and a different migration role. Do not expose a database port to the Internet to simplify access. Start with measured requirements and review compute, storage, query performance and connections before adding replicas.
Practice and recap
Explain why a read replica does not necessarily serve the latest stock count, why an HA standby is not a historical backup, and which charges must be checked before deploying. Then continue to Database connection and recovery for connection-pool sizing and a restore drill.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Managed relational databases — knowledge check
Choose the best answer for each offline scenario.
What should determine the first engine shortlist?
After the duplicate order insert fails, what should happen to the stock update?
Which is true of a classic RDS Multi-AZ DB instance standby?
Which protects against an accidentally committed deletion?
In the fictional cost example, what is the monthly total?