Sunday, 26 June 2022

Postgresql Read Replica

 PostgreSQL streaming read replications 


Amazon RDS users can create up to five DB instances using a snapshot of the source PostgreSQL DB instance.

 It uses the native streaming replication available on the PostgreSQL engine to asynchronously update the read replicas whenever there is a change to the source DB instance.


Amazon RDS writes all changes to the source DB instance, including data definition language (DDL). 

Replicas are read only and used to handle the read request workload.


The following diagram shows how Amazon RDS PostgreSQL performs replication between a source and a replica in the same AWS Region. 

In this example, Amazon RDS is hosting the source and read replica. The user can then stream replication directly between the source and read replica. The user has stored archived Write Ahead Logs (WALs) using an Amazon Simple Storage Service (Amazon S3) 

Then, if needed, the Amazon S3 backup can restore WALs in the read replica





Tuning Amazon RDS replication


You can tune the Amazon RDS PostgreSQL replication process to control how the replication behaves.

 This tuning can affect how far behind a replica is allowed to get before canceling newly submitted queries. 

For more information about tuning, see the Amazon RDS User Guide.


Select each + to learn more about Amazon RDS replication tuning commands


wal_keep_segments

–

This specifies the number of WAL file segments to keep on the primary instance.

Amazon RDS PostgreSQL archives segments to Amazon S3 and must download segments needed to sync a replica that has fallen behind.


hot_standby_feedback

–

This parameter is set on each replica. It controls whether the replica sends feedback to the primary database about queries running on the replica. 

This prevents the vacuum from removing tuples on the primary that are still needed to satisfy long-running queries on a replica.


max_standby_archive_delay

–

This command and the max_standby_streaming_delay command configure how long a replica will pause WAL replay to complete queries running on the replica.

If a query causes the delay to exceed the maximum, the query is canceled so that WAL replay can resume.


Aurora read replicas


Aurora further increases your horizontal scaling capability through the use of read replicas. 

Aurora uses a solid state drive (SSD) virtualized storage layer. The SSD facilitates the efficient handling of database workloads.


Aurora read replicas share the same underlying storage as the primary source instance. 

This helps reduce costs and eliminates the need to copy data to the read replicas.

 Horizontal scaling of Aurora read replicas is extremely fast, no matter how much you scale the size of the database. 

This is because there is no need to copy the data to the new read replica.


For more information about replication with Aurora, see Replication with Amazon Aurora.


To learn more about how read replicas work in Aurora, select each numerical button in order.








Cross-Region Replicas

Amazon RDS PostgreSQL also supports cross-Region replicas. 
You can create a read-only copy of your database in a separate AWS Region for global applications. 
This is useful when you want to serve read queries locally to your users to help improve performance and reduce the local response time.

You can also use these cross-Region replicas to move a failover into a separate Region for faster disaster recovery.

Cross-Region read replicas in Amazon RDS:

Improve your disaster recovery capabilities.
Scale read operations into an AWS Region closer to your users.
Help migrate from a data center in one AWS Region to a data center in another AWS Region.
Promote remote readers to a primary for faster recovery in the event of a disaster.

Cross-Region replication process

The following diagram shows how Amazon RDS performs replication from the PostgreSQL source instance in AWS Region 1. 
It streams between the source and the read replica through internet gateways to the read replica in AWS Region 2.

For more information about creating, configuring, and monitoring cross-Region replicas, 

see the RDS documentation and the AWS Database Blog for best practices with cross-Region replication.






Logical Replication

You can manually configure replication using PostgreSQL logical replication starting in PostgreSQL 10. For versions earlier than 10, 
you can use an external tool such as Bucardo or AWS Database Migration Service (AWS DMS).

Users build logical replication on top of streaming replication by applying a logical decoding process.
 This creates a set of logical changes from the binary changes recorded in the WAL.

PostgreSQL, like relational databases in general, supports two types of replication. With the first type, 
physical replication, you copy the exact binary data being written to disk on the primary server to the replica.
 Physical replication is accomplished with streaming replication such as with Amazon RDS read 
With the second type, logical replication, you create a logical copy by converting source database changes into a stream of updates 
that can be applied on the target database. Logical replication works with different major versions of PostgreSQL. 
You can use logical replication to perform an upgrade to a new version of PostgreSQL
 or replicate from an Amazon RDS PostgreSQL instance to an Amazon Aurora instance.

Publish-and-subscribe model

Logical replication uses a publish-and-subscribe model, in which subscribers pull data from the publications they subscribe to. 
Logical replication starts by copying a snapshot of the initial existing data on the publisher database.

When complete, the changes on the publisher (INSERT, UPDATE, and DELETE) are relayed to the subscriber in near real time.
 The subscriber applies data in the same order as they applied commits on the publisher.
 Following the same order helps ensure transactional 

Select each + to view additional information about the publish-and-subscribe model.
Publication
–
A publication, specified on a publisher node, is a set of changes generated from one or more database tables.

Subscription
–
A subscription, specified on a subscriber node, helps you define the connection to another database and one or more publications to which it subscribes.


Logical replication is built on the idea of a publish-and-subscribe model. You have a publisher, which is the source database. 
You have subscribers, which are the target databases. To configure logical replication, you create a publication on the publisher 
and create subscriptions on the subscribers. Then you tie them together and configure the tables that are part of that subscription.
Only the tables that you configure will be replicated from the publisher to the subscribers, and 
you can even choose to replicate only certain statements. For example,
you might want to replicate INSERT and UPDATE statements but not replicate DELETE statements. 
You can make all those replication decisions with the publication settings.

Next, review the two steps to configure replication on the publisher and subscriber database. To begin, select Start.

Creating publication and subscription
Follow these steps to configure replication on the publisher and subscriber databases.

Step 1: Create a publication
Define which tables you want to replicate by creating a publication on the source database.

Publications are created for:
All tables (FOR ALL TABLES)
Named tables (FOR TABLE x, y, z)
Publications are limited to certain statements (WITH (publish = ‘insert, update’))
To modify a publication, use ALTER PUBLICATION
Command example: CREATE PUBLICATION transpub FOR TABLE pgbench_accounts, pgbench_tellers, pgbench_branches;


Step 2: Create a subscription
Create a subscription on the target database to copy all existing data and begin the change replication process. 

Subscriptions are not configured to perform the initial data copy (WITH (copy_data=false));
If a publication uses ALTER on the source database, 
each subscription on the target database must be refreshed: ALTER SUBSCRIPTION transsub REFRESH PUBLICATION;
Command example: CREATE SUBSCRIPTION transsub CONNECTION 'dbname=gnb port=5432' PUBLICATION transpub;

Publish-and-subscribe process 

Explore the following graphic for more information about the publish-and-subscribe process. 
To navigate, select each numerical icon (in order).






Logical and physical replication differences

Logical replication differs from physical replication in several ways:

  • Users can replicate changes from an earlier version of PostgreSQL to a later version.
  • Users can choose a subset of tables to replicate.
  • Data can flow in multiple directions.
  • DDL is not replicated.
  • Logical replication requires manual configuration.




Logical replication has more flexibility because it applies logical SQL statements that represent the changes, as opposed to the physical binary changes that are specific to a major version. You can also choose a subset of tables instead of replicating the entire database. However, logical replication does not replicate DDL, so any schema changes must be manually applied to read replicas configured with logical replication. This is different from the PostgreSQL streaming replication in which DDL and schema changes are replicated. More manual configuration is required to configure a logical replication. 

Enabling logical replication for Amazon RDS

Logical replication works for replicating changes from PostgreSQL instances running on premises or self managed on Amazon Elastic Compute Cloud (Amazon EC2). It also works for upgrades in PostgreSQL versions.

Additional CPU overhead can affect performance. This additional overhead comes from converting changes made in the source database to a set of logical SQL commands run on a replica.

To review how to enable logical replication in Amazon RDS, select Start.

Amazon RDS: Enabling logical replication

Select Start to see how to enable logical replication for an Amazon RDS for PostgreSQL DB instance as a publisher.


Step 1: Required roles

The AWS user account requires the rds_superuser role to perform logical replication for the database on Amazon RDS. 

The user account also requires the rds_replication role to grant permissions to manage logical slots and stream data using logical slots.

Step 2: Set parameters

Set the rds.logical_replication static parameter to 1.

Step 3: Set connection security

Modify the inbound rules of the security group for the publisher instance (production) to allow the subscriber instance (replica) to connect. 

This is usually done by including the Internet Protocol (IP) address of the subscriber in the security group.


Step 4: Reboot the DB instance

Reboot the DB instance for the changes to the static parameter rds.logical_replication to take effect.



                                                                                                                                                                                   Logical replication with Aurora 

Aurora supports logical replication to publish changes to other PostgreSQL databases or replication clients starting with version 10.6 and later. To use logical replication with Aurora:

Confirm that your AWS user account has the rds_superuser role.
Set the rds.logical_replication parameter for a cluster parameter group, and restart the primary (writer) instance.
Modify the inbound rules of the security group for the publisher to allow the subscriber to connect. Include the IP address of the subscriber in the security group.

For more information about configuring logical replication, see the Aurora documentation.

Configure subscriber

Set the following parameters on the subscriber to these minimum values or higher.

ParameterMinimumRecommended
max_replication_slots
24
max_logical_replication_workers
24
max_worker_processes
212




Monitoring logical replication

PostgreSQL provides system views to monitor the status of replication (pg_stat_replication) and replication slots (pg_replication_slots) on the publisher. 

To monitor logical replication on the subscriber, use the pg_stat_subscription view.


Managing Database Connections



Managing connections

The creation of new database connections in PostgreSQL is expensive and uses valuable resources. 
PostgreSQL has built-in functionality for the reuse of connections.

PostgreSQL creates a new child process for every database session. These are user-backend processes. To avoid overloading your database,
 manage these connections for application requests and processes effectively.

Managing database connections is important because creating connections is expensive. 
If your application creates and closes connections continuously, you will have poor performance and response time for your users. To improve the performance of your application, make sure the application is using a connection pool and persistent connections across application requests. Be careful to have only as many connections as you really need to support your application. Each connection uses resources. If you open too many connections on the database, and keep them open in that connection pool, 
you could cause the database instance to restart if it runs out of memory resources.

Opening a connection

Every time you open a new database connection, resources must perform several key steps to successfully create a new connection. 
New connect requests and reconnecting dropped connections increase resource overhead. This resource overhead can impact your database performance.

The following image provides additional information about the connection process. To navigate, select the numerical icons (in order).




Connection pools

Creating a new connection takes time and resources, resulting in a slower response to user queries than reusing existing connections. 
To learn more about connection pools, scroll through the following slides.


xfy5Oe5JKhmSn242-pooling.png

Most application servers and programming language environments provide a client-side connection pool for the application to reuse a group of existing connections (a pool) rather than creating a new connection for each user request.


xFGEV4atLMmoSR-N-ConnectionPooling.png

For example, Java developers use open-source connection pool libraries such as Apache Commons DBCP, HikariCP, or C3PO. Ruby on Rails and .NET Npgsql developers use a connection pool built into their respective database drivers. 

Using these connection pools, each application server can access database resources and process user queries more quickly and efficiently.




OM9-6EmKKAcjjSlz-pooling3.png

As you scale your application, managing the total number of connections coming from multiple application servers becomes important.

Each application server might have a small pool of 10 database connections. However, as the application tier automatically scales from 10 to 100 to 1,000 application servers, the number of database connections grows exponentially with them. Pooling and reusing connections reduces the total database connections created.

Connection Pools 4

HvjW-2DZadwozmZy-RAM.svg

Each open connection in PostgreSQL, whether idle or active, consumes memory (about 10 MB), which reduces memory available for the database engine or file system caching.

You can control the number of incoming connections allowed to your database with the PostgreSQL parameter max_connections.


aHCdcI--TUHOMwri-ramvsconnex.svg

Ensure that the maximum connections configured on the database server and the working memory configured for each connection do not exceed available free memory. In a worst-case scenario, a database restart will occur. This restart happens if the database engine allows more connections to be opened than the available memory can accommodate.

For more information about connection management in PostgreSQL, see the PostgreSQL Wiki.


Database proxies

Add a database proxy to your database architecture to increase speed and reduce connection overhead.

Proxies provide a separate layer of database connection pools. This separate layer can reuse existing or duplicate connections. This proxy can also direct writes to the primary while offloading read requests to the read replicas.

Proxies are useful when you have many application servers or use a serverless application architecture to create a connection pool shared by all your applications.


Configuring and managing your connection pool using a client-side library, such as a Java, Python, or Ruby connection library, is appropriate when your application is small. However, as your application grows, or if you move toward a serverless application architecture, you should introduce a database proxy to manage that pool of connections in a shared layer in between your application and the database. Those connections can then be shared across multiple application servers and be reused as your application gets larger and the number of application servers continues to grow. Amazon RDS Proxy is a fully managed service that provides a connection pooling proxy layer with extensive functionality. In addition, there are two open-source PostgreSQL proxy servers—pgBouncer and pgPool 2—on Amazon EC2 that you can configure and manage on your own to support similar types of connection pooling functionality.


Amazon RDS Proxy

Amazon RDS Proxy is a highly manageable database proxy. It automatically connects to a new database instance while preserving application connections. When failovers occur, Amazon RDS Proxy routes requests directly to the new database instance. This reduces failover duration for Aurora and Amazon RDS databases by up to 66 percent.

Amazon RDS Proxy helps you manage elements such as database credentials, authentication, and access through integration with AWS Secrets Manager and AWS Identity and Access Management (IAM).

pgBouncer.png

PostgreSQL proxy servers 

PgBouncer and Pgpool-II are open-source PostgreSQL proxy servers that you can use to manage connections and traffic for your database on Amazon EC2.

One way to help increase efficiency with a database proxy is to use it to direct write queries to the primary DB instance and read-only queries to one or more read replicas.


PgBouncer

PgBouncer is an open-source connection pooling utility used in PostgreSQL to maintain a cached pool of connections. Applications interact with PostgreSQL through these connections.

A few features of PgBouncer include:

  • Provides a lightweight connection pooler
  • Queues requests
  • Helps improve availability

This graphic shows how PgBouncer works to pool connections.

pgbouncer.png

Pgpool-II

Pgpool-II is middleware that works between PostgreSQL servers and a PostgreSQL database client. For more information, see the Pgpool-II documentation.

pgpool.png

This diagram illustrates how Pgpool-II works as a proxy to direct application traffic.








Friday, 24 June 2022

Minor Version And Major Version Upgrades in PostgreSQL

 Minor version upgrades


Minor version upgrades are commonly referred to as bug-fix releases and include only changes that are backward-compatible with existing applications.

You can choose the automatic minor version upgrade option when creating or modifying a DB instance. This means that your DB instance is automatically upgraded after the new version is tested and approved.

The upgrade will occur during your predefined maintenance window.


Use the following links to get more information on minor version upgrades: 


Major version upgrades

Major version upgrades frequently contain DB changes that are not backward-compatible with previous versions of the DB. This functionality can cause your existing applications to stop working correctly. As a result, major version upgrades are not applied automatically. 
They are left to the discretion of the DB owner.

Why upgrade? 

An outdated DB is a DB at risk. Reasons to update include the following:


  • After five years, a version no longer receives support, including updates to security and bug fixes.
  • Exposure to data loss and outages can impact an organization, including financial loss.
  • Outdated DBs can be vulnerable to cyberattacks and potentially compromise confidential information.
  • Staying up to date reduces the risk of financial loss due to compromised DBs.
To learn more about the benefits of installing a major version upgrade, review each of the following tabs.

Community support
-------–
Every version of PostgreSQL is supported by the community for a defined period of time. During this time, the community releases security patches and bug fixes on a regular cycle. When the version becomes unsupported, the patches and fixes stop on that version.


Performance
--------–
With each new version of PostgreSQL, DB performance improves. Feedback from users is reviewed and considered in the process of designing new innovations.  

Security and compliance
--------–
DBs are at high risk of cyberattacks. If an organization fails to upgrade its DB, it can become more vulnerable. Organizations might also have compliance guidelines stating that the application DBs must be up to date with the latest supported versions. For these two reasons alone, PostgreSQL strongly recommends upgrading when available.

Features and extensions
-----------–
Each major upgrade has new features and extensions that can boost performance and add functionality to a DB. Each version establishes new ways of solving known DB issues and introduces DB improvements.

The next sections of the course will cover the step-by-step process for completing a major upgrade.



Specify a Version-Compatible Parameter Group

Step 1: Specify a version-compatible parameter group

Before starting a major upgrade, you should prepare a version-compatible parameter group.
If you are using a custom parameter group, you have two options.

1)You can specify a default parameter group for the new DB engine version. 
2) You can create your own custom parameter group for the new DB engine version.

For more information on setting up parameter groups, see Working with DB parameter groups in the Amazon RDS User Guide.

If you associate a new parameter group with a DB instance, reboot the DB after the upgrade completes.

If the DB instance needs to be rebooted to apply the parameter group changes, the instance's parameter group status will show pending-reboot.

You can view an instance's parameter group status in the AWS Management Console or by using a describe operation, such as describe-db-instances.

Check Version Compatibility


Step 2: Check version compatibility

Next, check that your DB's instance class is compatible with the PostgreSQL version to which you are upgrading. 
Also, ensure that the target you are upgrading to has a supported upgrade path.


Aurora PostgreSQL upgrades

You can conduct the following Aurora PostgreSQL major version upgrades:

1) Upgrade from version 9.6, minor versions 9.6.9 and later, to version 10, minor versions 10.11 or later.

2) Upgrade from version 10, minor versions 10.7 and later, to version 11, minor versions 11.7 or later. 

For more information about how to determine valid upgrade targets, see Determining which engine version to upgrade to.


Check for Unsupported Usage



Step 3: Check for unsupported usage

Next, you need to check for unsupported usage. To do this, access prepared transactions. 
Commit or rollback all open prepared transactions before attempting an upgrade.

You can use the following query to verify that there are no open prepared transactions on your instance:

SELECT count(*) FROM pg_catalog.pg_prepared_xacts;


You also need to remove all uses of reg* data types before attempting an upgrade.

With the exception of regtype and regclass, reg* data types cannot be upgraded.

The pg_upgrade utility cannot persist in this data type, which is used to do the upgrade.

To verify that there are no uses of unsupported reg* data types, use the following query for each database.






Handle Amazon RDS Read Replicas or Amazon Aurora Secondary Clusters




PostgreSQL read replicas 

During a major version upgrade, Amazon RDS also upgrades all of your in-Region read replicas along with the primary DB instance.


Amazon RDS Step 4: Promote Amazon RDS PostgreSQL read replicas

You cannot upgrade read replicas separately. It could lead to situations where the primary and replica instances have different PostgreSQL major versions. 
However, replica upgrades might increase downtime on the primary instance. To prevent a replica upgrade, promote the replica to a standalone instance 
or delete it before starting the upgrade process. 
If you delete it, be sure to recreate it after the source instance has upgraded to a different major version.



Aurora Step 4: Upgrade Aurora PostgreSQL secondary clusters

If you are using global DB clusters, make sure to upgrade the secondary clusters before the primary cluster.
This helps ensure that the primary and secondary are on the same major version. If you upgrade the primary first, 
the secondary could still try to pull data over and could result in errors.

Aurora DB clusters that are configured as logical replication publishers or subscribers cannot undergo a major version upgrade.





Perform a Backup




You should always perform a backup as part of the preparation for a major upgrade. 
This is the fifth step in the end-to-end process. A backup gives you a known restore point for your DB.

Step 5: Perform an Amazon RDS backup

In Amazon RDS, if your backup retention period is greater than 0, 
the upgrade process creates DB snapshots of your DB instance before and after upgrading.

For more information about changing your backup retention period, see Modifying an Amazon RDS DB instance.
For more information about performing a manual backup, see Creating a DB snapshot.
Step 5: Perform an Aurora backup
In Aurora, the upgrade process creates a DB cluster snapshot before upgrading.
If you prefer to do a manual backup before the upgrade process, see Creating a DB cluster snapshot for more information.




Update Extensions


Amazon RDS and Aurora users should update extensions before the major version upgrade. 
This is also true if you plan to skip a major version with the upgrade. 
For example, upgrading from versions 9.4.x, 9.5.x, or 9.6.x to version 11.x skips a major version. 
There are other considerations with extensions if you skip a major version, which you will learn about in the next lesson.

Step 6: Update Amazon RDS extension 

The extensions to update for Amazon RDS are:

  • address_standardizer 

  • address_standardizer_data_us 

  • postGIS 

  • postgis_tiger_geocoder 

  • postgis_topology 

Run the following command for each extension:

ALTER EXTENSION PostgreSQL-extension UPDATE TO 'new-version' 




Step 6: Update Aurora extension

The extensions to be updated for Aurora are:

  • pgRouting 

  • postGIS 

To learn more about upgrading extensions, review the following steps. To begin, select Start.


Upgrading extensions


Both Amazon RDS and Aurora will need special care when upgrading PostgreSQL extensions.
They have similar process steps for this segment of major upgrades.

Update an extension after an engine upgrade.

alter extension extension name update to 'new version'

A PostgreSQL engine upgrade doesn't upgrade any PostgreSQL extensions. 
To update an extension after an engine upgrade, use the ALTER EXTENSION UPDATE command.

List currently installed extensions.

select * from pg_extension;

To list your currently installed extensions, use the PostgreSQL pg_extension catalog in the command shown.


View a list of specific extension versions.

select * from pg_available_extension_version;

To view a list of the specific extension versions that are available for your installation, 
use the PostgreSQL pg_available_extension_versions view in the command shown.



Drop Extensions





Step 7: Drop extensions

A PostgreSQL engine upgrade doesn't upgrade any PostgreSQL extensions, so you must drop certain extensions before completing a major version upgrade.

Important facts about dropping extensions include the following:


1)Upgrading from versions 9.4.x, 9.5.x, or 9.6.x to version 11.x skips a major version, which means the pgRouting extension will not update. You can drop the pgRouting extension and then reinstall it to a compatible version after the upgrade.

2)The tsearch2 and chkpass extensions are no longer supported for PostgreSQL versions 11 or later. If you are upgrading to version 11.x or later, drop the tsearch2 and chkpass extensions before the upgrade.



Drop Unknown Data Types


Step 8: Drop unknown data types

PostgreSQL version 10 stopped supporting the 'unknown' data type. Therefore, you must drop unknown data types, depending on the target version. In PostgreSQL, you can drop columns using the 'unknown' data type. For version 10 and later, you must drop unknown data types to perform a major upgrade.

Example:

If a version 9.6 DB uses the 'unknown' data type, an upgrade to version 10 will show an error message such as the following:

Perform an Upgrade Dry Run


Step 9: Test the upgrade

PostgreSQL recommends that you test a major version upgrade on a duplicate of your DB before attempting the upgrade on your production DB.

There are three ways that you can create a duplicate test instance:

  • Restore your DB from a recent snapshot. 
  • Do a point-in-time restore of your DB to its latest restorable time. 
  • Clone your DB, for Aurora only.
Temporary names

During a major version upgrade, the public and template1 DBs and the public schema in every DB on the instance are temporarily renamed.

These objects appear in the logs with their original name and a random string appended. The string is appended so that custom settings such as locale and owner are preserved during the major version upgrade.

After the upgrade completes, the objects are renamed back to their original names.

An important note 

During the major version upgrade process, you cannot complete a point-in-time restore of your instance.

After Amazon RDS or Aurora performs the upgrade, an automatic backup of the instance is created.

You can perform a point-in-time restore to times before the upgrade began and after the automatic backup of your instance has completed.


Resolve a Failed Upgrade



Step 10: Resolve a failed upgrade

Sometimes an upgrade fails. If an upgrade fails with precheck procedure errors, resolve the issues before you try again.

Precheck

During the major version upgrade process, Amazon RDS for PostgreSQL first runs a precheck procedure to identify any issues that might cause the upgrade to fail.

The precheck procedure checks all potential incompatible conditions across all DBs in the instance.

Issue encountered

If the precheck encounters an issue, it creates a log event indicating that the upgrade precheck failed.

The precheck process details are in an upgrade log named pg_upgrade_precheck.log for all the DBs of a DB instance. 
Amazon RDS appends a timestamp to the file name.

You should resolve all the issues identified in the precheck log, and then retry the major version upgrade.


Upgrade the Production Instance

Step 11: Upgrade with confidence

When the dry run of your major version upgrade is successful, you should be able to upgrade your production database with confidence.

Aurora appends a timestamp to the file name for these logs. You can view these logs as you can any other log. For more information, see Working with Amazon Aurora database log files.


Post-Upgrade Activity



What's next

After an upgrade, complete these five steps. To review the steps, flip each of the following cards.


1) Review the same logs that pg_upgrade utility produces to ensure that the upgrade completed successfully.
2) Run the ANALYZE operation to refresh the pg_statistic table.
3) Confirm in the release notes which extensions you may need to upgrade.
4) Run the following command: ALTER EXTENSION PostgreSQL-extension UPDATE TO 'new-version'.
5) You can also upload the upgrade logs to Amazon CloudWatch Logs.

Rolling back 

If your upgrade fails, restore the database to the time immediately prior to running the upgrade process. You can restore it using the console.
Amazon RDS users can find directions in the Amazon RDS User Guide. For Aurora, you can restore a DB cluster to a specified time using the console. Directions can be found in the Aurora User Guide.
Note : Times are shown in your local time zone, which is indicated by an offset from Universal Coordinated Time (UTC). For example, UTC-5 is Eastern Standard Time and Central Daylight Time.


Restore using AWS Command Line Interface

Another option to restore a DB instance or cluster to a specified time is to use the AWS Command Line Interface (AWS CLI) command.
This applies to both Amazon RDS and Aurora.

restore-db-cluster-to-point-in-time

Select each + to learn more about how to restore a database instance using the AWS CLI command on select operating systems.