> For the complete documentation index, see [llms.txt](https://ysfang82.gitbook.io/development-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ysfang82.gitbook.io/development-notes/aws-notes/service/storage/rds.md).

# RDS

**Introduction**

* Relational database service (RDS), including:&#x20;
  * Amazon Aurora
  * PostgreSQL
  * MySQL
  * MariaDB
  * Oracle
  * Microsoft SQL Server.

**Feature**

* Storage with 10Gb per database in EBS (gp2 or io1)
* 2 copies of data in each AZ with minimum of 3 AZs (can choose AZ, and have 6 copies at least)
* Backups
  * Automated Backup
    * To recover database to any point in time in a retention period (5 minutes\~35 days, 7 days as default).
    * Daily snapshots and transaction logs through the day (can do recovery down to a second)
    * Enabled by default, the backup takes the same size with DB and is saved on S3 freely
    * Will be deleted when DB is deleted
  * Snapshot
    * Manual operation, can copy cross region
    * Won't be deleted when DB is deleted
  * Additional support for Oracle
    * Oracle Export/Import Utilities
    * Oracle Data Pump Export and Import
    * Not support: Oracle Recovery Manager (RMAN), Replication Backups
* Encryption (for EBS, Snapshot)
  * Using AWS Key Management Service (KMS)
  * If a RDS is encrypted, its automated backups, read replicas, snapshots are encrypted as well
  * To encrypt an existing DB is not supported, instead create a new DB instance with encryption enabled then migrate data
* Disaster recovery with Multi-AZ deployments (**synchronous replication** for guarantee of durability)
  * supports:
    * PostgreSQL (physical replication)
    * MySQL (physical replication)
    * MariaDB (physical replication)
    * Oracle (physical replication)
    * SQL server (logical replication)
  * Have an exact copy of RDS in another AZ for automatic failover processing
  * DR for entire region down
    * Promote a read replica in a different region to stand alone DB (Single AZ).
    * Then reconfigure it as multi-AZ.
  * If being asked for data durability, still need to set up backups rather than only depending on multi-AZ.
* Read Replica (for scalability, it's **eventual consistent**)
  * Improve performance by using **asynchronous replication** from the primary RDS instance to the read replicas
  * Must have automatic backups turned on in order to deploy a read replica
  * Can have up to 5 replicas to any database
  * Can have replicas of read replicas
  * Can become an independent database but break the replication
  * [Read replica supports Multi-AZ](https://aws.amazon.com/about-aws/whats-new/2018/01/amazon-rds-read-replicas-now-support-multi-az-deployments/)
  * Support for:
    * Aurora
    * PostgreSQL
    * MySQL
    * MariaDB
  * **Read replica can be in another region**
  * Read Replicas use automatic backups for managing read replica logs
    * To disable automatic backup, remove the read replicas first.
* [Difference between Multi-AZ and Read Replicas in Amazon RDS](https://medium.com/awesome-cloud/aws-difference-between-multi-az-and-read-replicas-in-amazon-rds-60fe848ef53a)
* [To export RDS data to a MySQL instance running external to Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Exporting.NonRDSRepl.html)
  * Prepare an external MySQL DB instance.
  * Prepare the source RDS MySQL DB instance for replication.
  * Use the mysqldump utility to transfer the database from the source MySQL DB instance to the external MySQL database.
  * Start replication to the external MySQL database.
  * After the export completes, stop replication.
* RDS maintenance
  * For updates marked as `Required`, You receive a notice from Amazon RDS indicating when the update will be performed, if you defer a required update.&#x20;
  * For updates marked as `Available`, you can defer indefinitely.
* [Transparent Data Encryption (TDE)](https://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/Appendix.SQLServer.Options.TDE.html) are supported with Oracle, SQL Server.
* IAM Authentication for MySQL and PostgreSQL (authorization still happens inside RDS).
* Can copy an un-encrypted RDS snapshot into an encrypted one.
* CloudTrail cannot be used to track queries within RDS.
* Anti-patterns and suitable solutions
  * Lots of binary objects (S3)
  * Automated scalability, unstructured data, key-value data (DynamoDB)
  * Unsupport RDB types (Oracle DB2, SAP HANA), complete control of DB (EC2)
* Cross region failover

![RDS Cross Region Failover](https://3303577320-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4cDbT2F2VmcAohuhSN%2F-MERF-vamlK6eKyibgGD%2F-MERI_g45iXDvVQD8-g0%2FScreen%20Shot%202020-08-11%20at%202.55.44%20PM.png?alt=media\&token=c58b0887-3c06-4454-9e68-7c28ae63d633)

**DynamoDB Scaling vs RDS Scaling**

* DynamoDB offers a "push button" for easy scaling and leads no down time
* RDS needs manual operation to scale out (add replicas)/up (add instance size)

[**Amazon RDS on VMware database**](https://aws.amazon.com/rds/vmware/faqs/)

* RDS in on-premises VMware environments.&#x20;
* **Migration to RDS by promoting RDS Read Replica, no need for DMS**.
