

# Overview of Amazon RDS Blue/Green Deployments
<a name="blue-green-deployments-overview"></a>

By using Amazon RDS Blue/Green Deployments, you can make and test database changes before implementing them in a production environment. A *blue/green deployment* creates a staging environment that copies the production environment. In a blue/green deployment, the *blue environment* is the current production environment. The *green environment* is the staging environment and stays in sync with the current production environment.

You can make changes to the RDS DB instances in the green environment without affecting production workloads. For example, you can upgrade the major or minor DB engine version, upgrade the underlying file system configuration, or change database parameters in the staging environment. You can thoroughly test changes in the green environment. When ready, you can *switch over* the environments to transition the green environment to be the new production environment. The switchover typically takes under a minute with no data loss and no need for application changes.

Because the green environment is a copy of the topology of the production environment, the green environment includes the features used by the DB instance. These features include the read replicas, the storage configuration, DB snapshots, automated backups, Performance Insights, and Enhanced Monitoring. If the blue DB instance is a Multi-AZ DB instance deployment, then the green DB instance is also a Multi-AZ DB instance deployment.

**Note**  
Currently, blue/green deployments are supported only for RDS for MariaDB, RDS for MySQL, and RDS for PostgreSQL. For Amazon Aurora availability, see [Overview of Amazon Aurora Blue/Green Deployments](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/blue-green-deployments-overview.html) in the *Amazon Aurora User Guide*.  
Under certain conditions, RDS for PostgreSQL uses logical replication instead of physical replication to keep the green environment in sync with the blue environment. For more information, see [PostgreSQL replication methods for blue/green deployments](blue-green-deployments-replication-type.md).

Amazon RDS Blue/Green Deployments support Amazon RDS Proxy and smart drivers. These solutions reduce writer node upgrade downtime during switchover by detecting the topology change and redirecting connections to the new production environment without waiting for DNS propagation.

**Topics**
+ [Region and version availability](#blue-green-deployments-region-version-availability)
+ [Benefits of using Amazon RDS Blue/Green Deployments](#blue-green-deployments-benefits)
+ [Workflow of a blue/green deployment](#blue-green-deployments-major-steps)
+ [Authorizing access to Amazon RDS blue/green deployment operations](blue-green-deployments-authorizing-access.md)
+ [Limitations and considerations for Amazon RDS blue/green deployments](blue-green-deployments-considerations.md)
+ [Best practices for Amazon RDS blue/green deployments](blue-green-deployments-best-practices.md)

## Region and version availability
<a name="blue-green-deployments-region-version-availability"></a>

Feature availability and support varies across specific versions of each database engine, and across AWS Regions. For more information, see [Supported Regions and DB engines for Amazon RDS Blue/Green Deployments](Concepts.RDS_Fea_Regions_DB-eng.Feature.BlueGreenDeployments.md).

## Benefits of using Amazon RDS Blue/Green Deployments
<a name="blue-green-deployments-benefits"></a>

By using Amazon RDS Blue/Green Deployments, you can stay current on security patches, improve database performance, and adopt newer database features with short, predictable downtime. Blue/green deployments reduce the risks and downtime for database updates, such as major or minor engine version upgrades.

Blue/green deployments provide the following benefits:
+ Easily create a production-ready staging environment.
+ Automatically replicate database changes from the production environment to the staging environment.
+ Test database changes in a safe staging environment without affecting the production environment.
+ Stay current with database patches and system updates.
+ Implement and test newer database features.
+ Switch over your staging environment to be the new production environment without changes to your application.
+ Safely switch over through the use of built-in switchover guardrails.
+ Eliminate data loss during switchover.
+ Switch over quickly, typically under a minute depending on your workload.

## Workflow of a blue/green deployment
<a name="blue-green-deployments-major-steps"></a>

Complete the following major steps when you use a blue/green deployment for database updates.

1. Identify a production environment that requires updates.

   For example, the production environment in this image has a Multi-AZ DB instance deployment (mydb1) and a read replica (mydb2).  
![\[Production (blue) environment in a blue/green deployment\]](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/images/blue-green-deployment-blue-environment.png)

1. Create the blue/green deployment. For instructions, see [Creating a blue/green deployment in Amazon RDS](blue-green-deployments-creating.md).

   The following image shows an example of a blue/green deployment of the production environment from step 1. While creating the blue/green deployment, RDS copies the complete topology and configuration of the primary DB instance to create the green environment. The copied DB instance names are appended with `-green-random-characters`. The staging environment in the image contains a Multi-AZ DB instance deployment (mydb1-green-**abc123**) and a read replica (mydb2-green-**abc123**).  
![\[Blue/green deployment\]](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/images/blue-green-deployment.png)

   When you create the blue/green deployment, you can upgrade your DB engine version and specify a different DB parameter group for the DB instances in the green environment. RDS also configures replication from the primary DB instance in the blue environment to the primary DB instance in the green environment.

   After you create the blue/green deployment, the DB instance in the green environment is read-only by default.

1. Make additional changes to the staging environment, if required. For example, you might change the DB instance class used by one or more DB instances in the green environment.

   For information about modifying a DB instance, see [Modifying an Amazon RDS DB instance](Overview.DBInstance.Modifying.md).

1. Test your staging environment.

   During testing, we recommend that you keep your databases in the green environment read only. Enable write operations on the green environment with caution because they can result in replication conflicts. They can also result in unintended data in the production databases after switchover. To enable write operations for RDS for MySQL, set the `read_only` parameter to `1`, and wait for the parameter group to synchronize. Since `read_only` is a dynamic parameter, so a reboot isn't required. Once synchronized, change `read_only` from `1` to `0`. For RDS for PostgreSQL deployments that use logical replication, set the `default_transaction_read_only` parameter to `off` at the session level. For those that use physical replication, you can't enable write operations on the green environment.

1. When ready, switch over to transition the staging environment to be the new production environment. For instructions, see [Switching a blue/green deployment in Amazon RDS](blue-green-deployments-switching.md).

   The switchover results in downtime. The downtime is usually under one minute, but it can be longer depending on your workload.

   The following image shows the DB instances after the switchover.  
![\[DB instances after switching over a blue/green deployment\]](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/images/blue-green-deployment-switchover.png)

   After the switchover, the DB instances that were in the green environment become the new production DB instances. The names and endpoints in the current production environment are assigned to the newly switched over production environment, requiring no changes to your application. As a result, your production traffic now flows to the new production environment. The DB instances in the previous blue environment are renamed by appending `-oldn` to the current name, where `n` is a number. For example, assume the name of the DB instance in the blue environment is `mydb1`. After switchover, the DB instance name will be `mydb1-old1`.

   In the example in the image, the following changes occur during switchover:
   + The green environment Multi-AZ DB instance deployment named `mydb1-green-abc123` becomes the production Multi-AZ DB instance deployment named `mydb1`.
   + The green environment read replica named `mydb2-green-abc123` becomes the production read replica `mydb2`.
   + The blue environment Multi-AZ DB instance deployment named `mydb1` becomes `mydb1-old1`.
   + The blue environment read replica named `mydb2` becomes `mydb2-old1`.

1. If you no longer need a blue/green deployment, you can delete it. For instructions, see [Deleting a blue/green deployment in Amazon RDS](blue-green-deployments-deleting.md).

   After switchover, the previous production environment isn't deleted so that you can use it for regression testing, if necessary.

# Authorizing access to Amazon RDS blue/green deployment operations
<a name="blue-green-deployments-authorizing-access"></a>

Users must have the required permissions to perform operations related to blue/green deployments. You can create IAM policies that grant users and roles permission to perform specific API operations on the specified resources they need. You can then attach those policies to the IAM permission sets or roles that require those permissions. For more information, see [Identity and access management for Amazon RDS](UsingWithRDS.IAM.md).

The user who creates a blue/green deployment must have permissions to perform the following RDS operations:
+ `rds:CreateBlueGreenDeployment`
+ `rds:AddTagsToResource` 
+ `rds:CreateDBInstanceReadReplica` 

The user who switches over a blue/green deployment must have permissions to perform the following RDS operations:
+ `rds:SwitchoverBlueGreenDeployment`
+ `rds:ModifyDBInstance` 
+ `rds:PromoteReadReplica` 

The user who deletes a blue/green deployment must have permissions to perform the following RDS operation:
+ `rds:DeleteBlueGreenDeployment`
+ `rds:DeleteDBInstance` 

Amazon RDS provisions and modifies resources in the staging environment on your behalf. These resources include DB instances that use an internally defined naming convention. Therefore, attached IAM policies can't contain partial resource name patterns such as `my-db-prefix-*`. Only wildcards (\$1) are supported. In general, we recommend using resource tags and other supported attributes to control access to these resources, rather than wildcards. For more information, see [Actions, resources, and condition keys for Amazon RDS](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonrds.html).

# Limitations and considerations for Amazon RDS blue/green deployments
<a name="blue-green-deployments-considerations"></a>

Blue/green deployments in Amazon RDS require careful consideration of factors such as replication slots, resource management, instance sizing, and potential impacts on database performance. The following sections provide guidance to help you optimize your deployment strategy to ensure minimal downtime, seamless transitions, and effective management of your database environment.

**Topics**
+ [Limitations for blue/green deployments](#blue-green-deployments-limitations)
+ [Considerations for blue/green deployments](#blue-green-deployments-consider)

## Limitations for blue/green deployments
<a name="blue-green-deployments-limitations"></a>

The following limitations apply to blue/green deployments.

**Topics**
+ [General limitations for blue/green deployments](#blue-green-deployments-limitations-general)
+ [RDS for MySQL limitations for blue/green deployments](#blue-green-deployments-limitations-mysql)
+ [RDS for PostgreSQL limitations for blue/green deployments with physical replication](#blue-green-deployments-limitations-postgres-physical)
+ [RDS for PostgreSQL limitations for blue/green deployments with logical replication](#blue-green-deployments-limitations-postgres-logical)

### General limitations for blue/green deployments
<a name="blue-green-deployments-limitations-general"></a>

The following general limitations apply to blue/green deployments:
+ Blue/green deployments don't support managing master user passwords with AWS Secrets Manager.
+ If dedicated log volume (DLV) is enabled on the blue database, it must be enabled on *all* DB instances, including read replicas.
+ During switchover, the blue and green environments can't have zero-ETL integrations with Amazon Redshift. You must delete the integration first and switch over, then recreate the integration.
+ The Event Scheduler (`event_scheduler` parameter) must be disabled on the green environment when you create a blue/green deployment. This prevents events from being generated in the green environment and causing inconsistencies.
+ You can't change an unencrypted DB instance into an encrypted DB instance. In addition, you can't change an encrypted DB instance into an unencrypted DB instance.
+ You can't change a blue DB instance to a higher engine version than its corresponding green DB instance.
+ The resources in the blue environment and green environment must be in the same AWS account.
+ If you use Amazon RDS Proxy, you must register your blue cluster with the proxy before creating a blue/green deployment. If a blue/green deployment already exists for a given blue cluster, registering that blue cluster to Amazon RDS Proxy will be blocked.
+ Amazon RDS Proxy with blue/green deployments is not supported for Aurora Global Databases.
+ Blue/green deployments aren't supported for the following features:
  + Cascading read replicas
  + Cross-Region read replicas
  + CloudFormation
  + Multi-AZ DB cluster deployments

    Blue/green deployments are supported for Multi-AZ DB instance deployments. For more information about Multi-AZ deployments, see [Configuring and managing a Multi-AZ deployment for Amazon RDS](Concepts.MultiAZ.md).

### RDS for MySQL limitations for blue/green deployments
<a name="blue-green-deployments-limitations-mysql"></a>

The following limitations apply to RDS for MySQL blue/green deployments:
+ The blue DB instance can't be an external binlog replica.
+ If the source database is associated with a custom option group, you can't specify a major version upgrade when you create the blue/green deployment.

  In this case, you can create a blue/green deployment without specifying a major version upgrade. Then, you can upgrade the database in the green environment. For more information, see [Upgrading a DB instance engine version](USER_UpgradeDBInstance.Upgrading.md).
+ Blue/green deployments don't support the AWS JDBC Driver for MySQL. For more information, see [Known Limitations](https://github.com/awslabs/aws-mysql-jdbc?tab=readme-ov-file#known-limitations) on GitHub.

### RDS for PostgreSQL limitations for blue/green deployments with physical replication
<a name="blue-green-deployments-limitations-postgres-physical"></a>

The following limitations apply to RDS for PostgreSQL blue/green deployments that use physical replication. For an explanation of when blue/green deployments use physical replication instead of logical replication, see [PostgreSQL replication methods for blue/green deployments](blue-green-deployments-replication-type.md).
+ After the green environment is created, you can't perform a manual major version upgrade.
+ Blue/green deployments that use physical replication don't support schema changes on the green environment, as it is strictly read-only.
+ The blue DB instance can't be a logical source (publisher) or replica (subscriber).
+ Blue/Green deployments have the following limitations when configuring delayed replication in RDS for PostgreSQL:
  + **Green source instance** — The `recovery_min_apply_delay parameter` is disregarded, even if configured in the parameter group. Any delay settings on the green source instance do not take effect.
  + **Green replica instance** — The `recovery_min_apply_delay parameter` is fully supported and applied to the PostgreSQL configuration file. Delay settings function as expected during the switchover workflow.
  + Delayed replication isn't compatible with RDS Blue/Green deployments for major version upgrades.

### RDS for PostgreSQL limitations for blue/green deployments with logical replication
<a name="blue-green-deployments-limitations-postgres-logical"></a>

The following limitations apply to RDS for PostgreSQL blue/green deployments that use logical replication. For an explanation of when blue/green deployments use logical replication instead of physical replication, see [PostgreSQL replication methods for blue/green deployments](blue-green-deployments-replication-type.md).
+ [Unlogged](https://www.postgresql.org/docs/16/sql-createtable.html#SQL-CREATETABLE-UNLOGGED) tables aren't replicated to the green environment.
+ The blue DB instance can't be a logical source (publisher) or replica (subscriber).
+ If the blue DB instance is configured as the foreign server of a foreign data wrapper (FDW) extension, you must use the instance endpoint name instead of IP addresses. This allows the configuration to remain functional after switchover.
+ In a blue/green deployment, each database requires a logical replication slot. As the number of databases grows, resource overhead increases and can potentially lead to replication lag, especially if the DB instance isn't sufficiently scaled. The impact depends on factors such as database workload and the number of connections. To mitigate this, consider scaling up your DB instance class or reducing the number of databases on the source instance.
+ The logical replication [apply process](https://www.postgresql.org/docs/current/logical-replication-architecture.html) in the green environment is single-threaded. If the blue environment generates a high volume of write traffic, the green environment might not be able to keep up. This can lead to replication lag or failure, especially for workloads that produce continuous high write throughput. Make sure to test your workloads thoroughly. For scenarios that require major version upgrades and handling high-volume write workloads, consider alternative approaches such as using [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/data-migrations.html).
+ Blue/Green deployments have the following limitations when configuring delayed replication in RDS for PostgreSQL:
  + **Green source instance** — The `recovery_min_apply_delay parameter` is disregarded, even if configured in the parameter group. Any delay settings on the green source instance do not take effect.
  + **Green replica instance** — The `recovery_min_apply_delay parameter` is fully supported and applied to the PostgreSQL configuration file. Delay settings function as expected during the switchover workflow.
  + Delayed replication isn't compatible with RDS Blue/Green deployments for major version upgrades.
+ Creating new partitions on partitioned tables isn't supported during blue/green deployments for RDS for PostgreSQL. Creating new partitions involves data definition language (DDL) operations such as `CREATE TABLE`, which aren't replicated from the blue environment to the green environment. However, existing partitioned tables and their data will be replicated to the green environment.
+ The following limitations apply to PostgreSQL extensions:
  + The `pg_partman` extension must be disabled in the blue environment when you create a blue/green deployment. The extension performs DDL operations such as `CREATE TABLE`, which break logical replication from the blue environment to the green environment.
  + The `pg_cron` extension must remain disabled on all green databases after the blue/green deployment is created. The extension has background workers that run as superuser and bypass the read-only setting of the green environment, which might cause replication conflicts.
  + The `pglogical` and `pgactive` extensions must be disabled on the blue environment when you create a blue/green deployment. After you switch over the green environment to be the new production environment, you can enable the extensions again. In addition, the blue database can’t be a logical subscriber of an external instance.
  + If you're using the `pgAudit` extension, it must remain in the shared libraries (`shared_preload_libraries`) on the custom DB parameter groups for both the blue and the green DB instances. For more information, see [Setting up the pgAudit extension](Appendix.PostgreSQL.CommonDBATasks.pgaudit.basic-setup.md).

#### Logical replication-specific limitations for blue/green deployments
<a name="blue-green-deployments-limitations-postgres"></a>

PostgreSQL has certain restrictions related to logical replication, which translate to limitations when creating blue/green deployments for RDS for PostgreSQL DB instances.

The following table describes logical replication limitations that apply to blue/green deployments for RDS for PostgreSQL. For more information, see [Restrictions](https://www.postgresql.org/docs/current/logical-replication-restrictions.html) in the PostgreSQL logical replication documentation.


| Limitation | Explanation | 
| --- | --- | 
| Data definition language (DDL) statements, such as CREATE TABLE and CREATE SCHEMA, aren't replicated from the blue environment to the green environment. |  If Amazon RDS detects a DDL change in the blue environment, your green databases enter a state of **Replication degraded**. You must delete the blue/green deployment and all green databases, then recreate it.  | 
| Data control language (DCL) statements, such as GRANT and REVOKE, aren't replicated from the blue environment to the green environment. |  If Amazon RDS PostgreSQL detects an attempt to execute a DCL statement in the blue environment, you will see a warning message. There is no configuration or API available to change this behavior, as it is a limitation of the blue/green deployment process.  | 
| NEXTVAL operations on sequence objects aren't synchronized between the blue environment and the green environment. |  During switchover, Amazon RDS increments sequence values in the green environment to match those in the blue environment. If you have thousands of sequences, this can delay switchover.  | 
| Large objects in the blue environment aren't replicated to the green environment. This includes both existing large objects and any newly created or modified large objects during the blue/green deployment process. |  If Amazon RDS detects the creation or modification of large objects in the blue environment that are stored in the `pg_largeobject` system table, your green databases enter a state of **Replication degraded**. You must delete the blue/green deployment and all green databases, then recreate it.  | 
|  Materialized views aren’t automatically refreshed in the green environment.  |  Refreshing materialized views in the blue environment doesn't refresh them in the green environment. After switchover, you can manually refresh them using the [REFRESH MATERIALIZED VIEW](https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html) command, or schedule a refresh.  | 
|  UPDATE and DELETE operations aren't permitted on tables that don't have a primary key.  |  Before you create a blue/green deployment, make sure that all tables have a primary key or use `REPLICA IDENTITY FULL`. However, only use `REPLICA IDENTITY FULL` if no primary or unique key exists, as it affects replication performance. For more information, see the [PostgreSQL documentation](https://www.postgresql.org/docs/current/logical-replication-restrictions.html).  | 

## Considerations for blue/green deployments
<a name="blue-green-deployments-consider"></a>

Amazon RDS tracks resources in blue/green deployments with the `DbiResourceId` of each resource. This resource ID is an AWS Region-unique, immutable identifier for the resource.

The *resource* ID is separate from the DB ***instance* ID. Each one is listed in the database configuration in the RDS console.

The name (instance ID) of a resource changes when you switch over a blue/green deployment, but each resource keeps the same resource ID. For example, a DB instance identifier might be `mydb` in the blue environment. After switchover, the same DB instance might be renamed to `mydb-old1`. However, the resource ID of the DB instance doesn't change during switchover. So, when you switch over the green resources to be the new production resources, their resource IDs don't match the blue resource IDs that were previously in production.

After you switch over a blue/green deployment, consider updating the resource IDs to those of the newly transitioned production resources for integrated features and services that you used with the production resources. Specifically, consider the following updates:
+ If you perform filtering using the RDS API and resource IDs, adjust the resource IDs used in filtering after switchover.
+ If you use CloudTrail for auditing resources, adjust the consumers of the CloudTrail to track the new resource IDs after switchover. For more information, see [Monitoring Amazon RDS API calls in AWS CloudTrail](logging-using-cloudtrail.md).
+ If you use the Performance Insights API, adjust the resource IDs in calls to the API after switchover. For more information, see [Monitoring DB load with Performance Insights on Amazon RDS](USER_PerfInsights.md).

  You can monitor a database with the same name after switchover, but it doesn't contain the data from before the switchover.
+ If you use resource IDs in IAM policies, make sure you add the resource IDs of the newly transitioned resources when necessary. For more information, see [Identity and access management for Amazon RDS](UsingWithRDS.IAM.md).
+ If you have IAM roles associated with your DB instance, make sure to reassociate them after switchover. Attached roles aren't automatically copied to the green environment.
+ If you authenticate to your DB instance using [IAM database authentication](UsingWithRDS.IAMDBAuth.md), make sure that the IAM policy used for database access has both the blue and the green databases listed under the `Resource` element of the policy. This is required in order to connect to the green database after switchover. For more information, see [Creating and using an IAM policy for IAM database access](UsingWithRDS.IAMDBAuth.IAMPolicy.md).
+ If you use AWS Backup to manage automated backups of resources in a blue/green deployment, adjust the resource IDs used by AWS Backup after switchover. For more information, see [Using AWS Backup to manage automated backups for Amazon RDS](AutomatedBackups.AWSBackup.md).
+ If you want to restore a manual or automated DB snapshot for a DB instance that was part of a blue/green deployment, make sure you restore the correct DB snapshot by examining the time when the snapshot was taken. For more information, see [Restoring to a DB instance](USER_RestoreFromSnapshot.md).
+ If you want to describe a previous blue environment DB instance automated backup or restore it to a point in time, use the resource ID for the operation.

  Because the name of the DB instance changes during switchover, you can't use its previous name for `DescribeDBInstanceAutomatedBackups` or `RestoreDBInstanceToPointInTime` operations.

  For more information, see [Restoring a DB instance to a specified time for Amazon RDS](USER_PIT.md).
+ When you add a read replica to a DB instance in the green environment of a blue/green deployment, the new read replica won't replace a read replica in the blue environment when you switch over. However, the new read replica is retained in the new production environment after switchover.
+ After you switch over, AWS Database Migration Service (AWS DMS) replication tasks can't resume because the checkpoint from the blue environment is invalid in the green environment. You must recreate the DMS task with a new checkpoint to continue replication.
+ When you delete a DB instance in the green environment of a blue/green deployment, you can't create a new DB instance to replace it in the blue/green deployment.

  If you create a new DB instance with the same name and Amazon Resource Name (ARN) as the deleted DB instance, it has a different `DbiResourceId`, so it isn't part of the green environment.

  The following behavior results if you delete a DB instance in the green environment:
  + If the DB instance in the blue environment with the same name exists, it won't be switched over to the DB instance in the green environment. This DB instance won't be renamed by adding `-oldn` to the DB instance name.
  + Any application that points to the DB instance in the blue environment continues to use the same DB instance after switchover.

  The same behavior applies to DB instances and read replicas.
+ If you use resource tags for access control or operational management, you need to understand that tag changes aren't synchronized between blue and green environments until switchover. When you create a blue/green deployment, tags from the blue environment are copied to the green environment. After creation, any tag modifications that you make to either environment aren't automatically synchronized. During switchover, blue environment tags replace all tags in the green environment. Apply all necessary tags to the blue environment before you create the blue/green deployment, or reapply required tags to the new production environment after switchover. For more information about tags, see [Tagging Amazon RDS resources](USER_Tagging.md).

# Best practices for Amazon RDS blue/green deployments
<a name="blue-green-deployments-best-practices"></a>

The following are best practices for blue/green deployments.

**Topics**
+ [General best practices for blue/green deployments](#blue-green-deployments-best-practices-general)
+ [RDS for MySQL best practices for blue/green deployments](#blue-green-deployments-best-practices-mysql)
+ [RDS for MySQL best practices for blue/green deployments](#blue-green-deployments-best-practices-agd)
+ [PostgreSQL replication methods for blue/green deployments](blue-green-deployments-replication-type.md)

## General best practices for blue/green deployments
<a name="blue-green-deployments-best-practices-general"></a>

Consider the following general best practices when you create a blue/green deployment.
+ Thoroughly test the DB instances in the green environment before switching over.
+ Keep your databases in the green environment read only. We recommend that you enable write operations on the green environment with caution because they can result in replication conflicts. They can also result in unintended data in the production databases after switchover.
+ If you use a blue/green deployment to implement schema changes, make only replication-compatible changes.

  For example, you can add new columns at the end of a table without disrupting replication from the blue deployment to the green deployment. However, schema changes, such as renaming columns or renaming tables, break replication to the green deployment.

  For more information about replication-compatible changes, see [Replication with Differing Table Definitions on Source and Replica](https://dev.mysql.com/doc/refman/8.0/en/replication-features-differing-tables.html) in the MySQL documentation and [Restrictions](https://www.postgresql.org/docs/current/logical-replication-restrictions.html) in the PostgreSQL logical replication documentation.
**Note**  
This limitation doesn't apply to RDS for PostgreSQL blue/green deployments that use physical replication. For more information, see [RDS for PostgreSQL limitations for blue/green deployments with physical replication](blue-green-deployments-considerations.md#blue-green-deployments-limitations-postgres-physical).
+ After you create the blue/green deployment, handle lazy loading if necessary. Make sure data loading is complete before switching over. For more information, see [Lazy loading and storage initialization for blue/green deployments](blue-green-deployments-creating.md#blue-green-deployments-creating-lazy-loading).
+ When you switch over a blue/green deployment, follow the switchover best practices. For more information, see [Switchover best practices](blue-green-deployments-switching.md#blue-green-deployments-switching-best-practices).

## RDS for MySQL best practices for blue/green deployments
<a name="blue-green-deployments-best-practices-mysql"></a>

Consider the following best practices when you create a blue/green deployment from an RDS for MySQL DB instance.
+ Avoid using non-transactional storage engines, such as MyISAM, that aren't optimized for replication.
+ Optimize read replicas and the green environment for binary log replication. If supported by your DB engine, enable GTID, parallel, and crash-safe replication to ensure data consistency and durability before you create your blue/green deployment. For more information, see [Using GTID-based replication](mysql-replication-gtid.md).
+ If the green environment experiences replica lag, consider the following:
  + Temporarily set the `innodb_flush_log_at_trx_commit` parameter to `2` in the green DB parameter group. After replication catches up, revert to the default value of `1` before switchover. If an unexpected shutdown or crash occurs with the temporary parameter value, rebuild the green environment to avoid undetected data corruption. 
  + To reduce write latency and improve replication throughput, temporarily change green Multi-AZ DB instances to Single-AZ DB instances. Re-enable Multi-AZ right before switchover.

## RDS for MySQL best practices for blue/green deployments
<a name="blue-green-deployments-best-practices-agd"></a>

In addition to the above listed general and engine specific best practices, consider the following best practices for RDS for MySQL DB instance
+ Monitor the following CloudWatch metrics to identify periods of low activity in your production environment:
  + `DatabaseConnections`
  + `ActiveTransactions`

  Schedule the blue/green switchover during your planned maintenance window or during a period of low activity.
+ Blue/Green switchover duration varies based on your workload and the number of secondary regions. When you initiate a blue/green switchover, the service waits for replica lag to reach zero before proceeding. We recommend checking replica lag before initiating a switchover.
+ If you intend to use a DB parameter or DB Cluster parameter group other than the default one for your green environment, create the desired parameter group with the same name in all secondary regions before initiating the blue/green deployment.

### RDS for PostgreSQL best practices for blue/green deployments
<a name="blue-green-deployments-best-practices-postgres"></a>

Consider the following best practices when you create a blue/green deployment from an RDS for PostgreSQL DB instance.

**Topics**
+ [RDS for PostgreSQL general best practices for blue/green deployments](#blue-green-deployments-best-practices-postgres-general)
+ [RDS for PostgreSQL best practices for blue/green deployments with physical replication](#blue-green-deployments-best-practices-postgres-physical)
+ [RDS for PostgreSQL best practices for blue/green deployments with logical replication](#blue-green-deployments-best-practices-postgres-logical)

#### RDS for PostgreSQL general best practices for blue/green deployments
<a name="blue-green-deployments-best-practices-postgres-general"></a>

Consider the following general best practices when you create a blue/green deployment from an RDS for PostgreSQL DB instance.
+ Update all of your PostgreSQL extensions to the latest version before you create a blue/green deployment. For more information, see [Upgrading PostgreSQL extensions in RDS for PostgreSQL databases](USER_UpgradeDBInstance.PostgreSQL.ExtensionUpgrades.md).
+ Long-running transactions can cause significant replica lag. To reduce replica lag, consider doing the following:
  + Reduce long-running transactions that can be delayed until after the green environment catches up to the blue environment.
  + Reduce bulk operations on the blue environment until after the green environment catches up to the blue environment.
  + Initiate a manual vacuum freeze operation on busy tables prior to creating the blue/green deployment.
  + For PostgreSQL version 12 and higher, disable the `index_cleanup` parameter on large or busy tables to increase the rate of normal maintenance on blue databases. For more information, see [Vacuuming a table as quickly as possible](Appendix.PostgreSQL.CommonDBATasks.Autovacuum.LargeIndexes.md#Appendix.PostgreSQL.CommonDBATasks.Autovacuum.LargeIndexes.Executing).
**Note**  
Regularly skipping index cleanup during vacuuming can lead to index bloat, which might degrade scan performance. As a best practice, use this approach only while using a blue/green deployment. Once the deployment is complete, we recommend resuming regular index maintenance and cleanup.
+ Slow replication can cause senders and receivers to restart often, which delays synchronization. To ensure that they remain active, disable timeouts by setting the `wal_sender_timeout` parameter to `0` in the blue environment, and the `wal_receiver_timeout` parameter to `0` in the green environment.
+ To prevent write-ahead log (WAL) segments from being removed from the blue environment, set the `wal_keep_segments` parameter to 15625 for PostgreSQL version 13 and lower. For version 14 and higher, set the `wal_keep_size` parameter too 1 TiB, if there's enough free storage space.

#### RDS for PostgreSQL best practices for blue/green deployments with physical replication
<a name="blue-green-deployments-best-practices-postgres-physical"></a>

With physical replication, Amazon RDS creates a read replica of the source DB instance. For related parameters, monitoring, tuning, and troubleshooting, see [Working with read replicas for Amazon RDS for PostgreSQL](USER_PostgreSQL.Replication.ReadReplicas.md).

For an explanation of when blue/green deployments use physical replication instead of logical replication, see [PostgreSQL replication methods for blue/green deployments](blue-green-deployments-replication-type.md).

#### RDS for PostgreSQL best practices for blue/green deployments with logical replication
<a name="blue-green-deployments-best-practices-postgres-logical"></a>

Consider the following best practices when you create a blue/green deployment that uses logical replication. For an explanation of when blue/green deployments use logical replication instead of physical replication, see [PostgreSQL replication methods for blue/green deployments](blue-green-deployments-replication-type.md).
+ If your database has sufficient freeable memory, increase the value of the `logical_decoding_work_mem` DB parameter in the blue environment. Doing so allows for less decoding on disk and instead uses memory. For more information, see the [PostgreSQL documentation](https://www.postgresql.org/docs/13/runtime-config-resource.html#GUC-LOGICAL-DECODING-WORK-MEM).
  + You can monitor transaction overflow being written to disk using the `ReplicationSlotDiskUsage` CloudWatch metric. This metric offers insights into the disk usage of replication slots, helping identify when transaction data exceeds memory capacity and is stored on disk. You can monitor freeable memory with the `FreeableMemory` CloudWatch metric. For more information, see [Amazon CloudWatch instance-level metrics for Amazon RDS](rds-metrics.md#rds-cw-metrics-instance).
  + In RDS for PostgreSQL version 14 and higher, you can monitor the size of logical overflow files using the `[pg\$1stat\$1replication\$1slots](https://www.postgresql.org/docs/14/monitoring-stats.html#MONITORING-PG-STAT-REPLICATION-SLOTS-VIEW)` system view.
+ If you’re using the `aws_s3` extension, give the green DB instance access to Amazon S3 through an IAM role after the green environment is created. This allows the import and export commands to continue functioning after switchover. For instructions, see [Setting up access to an Amazon S3 bucket](postgresql-s3-export-access-bucket.md).
+ Review the performance of your UPDATE and DELETE statements and evaluate whether creating an index on the column used in the WHERE clause can optimize these queries. This can enhance performance when the operations are replayed in the green environment.
+ If you're using triggers, make sure they don't interfere with the creating, updating, and dropping of `pg_catalog.pg_publication`, `pg_catalog.pg_subscription`, and `pg_catalog.pg_replication_slots` objects whose names start with 'rds'.
+ If you specify a higher engine version for the green environment, run the `ANALYZE` operation on all databases to refresh the `pg_statistic` table. Optimizer statistics aren't transferred during a major version upgrade, so you must regenerate all statistics to avoid performance issues. For additional best practices during major version upgrades, see [How to perform a major version upgrade for RDS for PostgreSQL](USER_UpgradeDBInstance.PostgreSQL.MajorVersion.Process.md).
+ Avoid configuring triggers as `ENABLE REPLICA` or `ENABLE ALWAYS` if the trigger is used on the source to manipulate data. Otherwise, the replication system propagates changes and executes the trigger, which leads to duplication.

# PostgreSQL replication methods for blue/green deployments
<a name="blue-green-deployments-replication-type"></a>

Amazon RDS for PostgreSQL primarily uses physical replication for blue/green deployments. However, if you request a major version upgrade when you create the blue/green deployment, and your source DB instance runs one of the PostgreSQL versions listed in the table below, Amazon RDS uses logical replication instead.

The following table outlines when Amazon RDS uses physical versus logical replication for PostgreSQL blue/green deployments.


| Source PostgreSQL DB instance version | Upgrade action in blue/green deployment | Replication method | 
| --- | --- | --- | 
|  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-replication-type.html)  | Major version upgrade(green instance on higher major engine version than blue) | Logical replication | 
| All supported versions | Minor version upgrade, or no upgrade(green instance on same major engine version as blue) | Physical replication | 

**Note**  
Major version upgrades are not supported for blue/green deployments with source RDS for PostgreSQL versions 15.3 and lower, 14.8 and lower, 13.11 and lower, 12.15 and lower, or 11.20 and lower.

For information about the limitations of blue/green deployments that use physical and logical replication, see the following sections:
+ [RDS for PostgreSQL limitations for blue/green deployments with physical replication](blue-green-deployments-considerations.md#blue-green-deployments-limitations-postgres-physical)
+ [RDS for PostgreSQL limitations for blue/green deployments with logical replication](blue-green-deployments-considerations.md#blue-green-deployments-limitations-postgres-logical)