You are on page 1of 16

AWS Region :

Region consists of multiple datacenters called as Available Zones (AZ)

Each AZ has independent power, cooling, and physical security and is connected via redundant,
ultra-low-latency networks. AWS customers focused on high availability can design their applications
to run in multiple AZs to achieve even greater fault-tolerance. AWS infrastructure Regions meet the
highest levels of security, compliance, and data protection.

AWS Availability Zones:

All AZs in an AWS Region are interconnected with high-bandwidth, low-latency networking, over fully
redundant, dedicated metro fiber providing high-throughput, low-latency networking between AZs. All
traffic between AZs is encrypted. The network performance is sufficient to accomplish synchronous
replication between AZs. AZs make partitioning applications for high availability easy. If an
application is partitioned across AZs, companies are better isolated and protected from issues such
as power outages, lightning strikes, tornadoes, earthquakes, and more. AZs are physically
separated by a meaningful distance, many kilometers, from any other AZ, although all are within 100
km (60 miles) of each other.

Amazon Aurora

Amazon Aurora (Aurora) is a fully managed relational database engine that's compatible with
MySQL and PostgreSQL. 

An Amazon Aurora DB cluster consists of one or more DB instances and a cluster volume that
manages the data for those DB instances. 

An Aurora cluster volume is a virtual database storage volume that spans multiple


Availability Zones, with each Availability Zone having a copy of the DB cluster data. Two
types of DB instances make up an Aurora DB cluster:

 Primary DB instance – Supports read and write operations, and performs all of the data
modifications to the cluster volume. Each Aurora DB cluster has one primary DB
instance.
 Aurora Replica – Connects to the same storage volume as the primary DB instance and
supports only read operations. Each Aurora DB cluster can have up to 15 Aurora
Replicas in addition to the primary DB instance. Maintain high availability by locating
Aurora Replicas in separate Availability Zones. Aurora automatically fails over to an
Aurora Replica in case the primary DB instance becomes unavailable. You can specify
the failover priority for Aurora Replicas. Aurora Replicas can also offload read
workloads from the primary DB instance.
Backtracking in Aurora
By using backtracking in Aurora, you return the state of an Aurora cluster to a specific
point in time, without restoring data from a backup. It completes within seconds, even
for large databases. 

Aurora backtracking is available for Aurora MySQL only. It's not available for Aurora
PostgreSQL.

Amazon RDS Proxy


Amazon RDS Proxy is a fully managed, highly available database proxy that makes
applications more scalable by pooling and sharing established database connections.
With RDS Proxy, failover times for Aurora are reduced by up to 66 percent.
Cluster endpoint
A cluster endpoint (or writer endpoint) for an Aurora DB cluster connects to the
current primary DB instance for that DB cluster. This endpoint is the only one that can
perform write operations such as DDL statements. Because of this, the cluster endpoint
is the one that you connect to when you first set up a cluster or when your cluster only
contains a single DB instance.

Each Aurora DB cluster has one cluster endpoint and one primary DB instance.

The cluster endpoint provides failover support for read/write connections to the DB
cluster. If the current primary DB instance of a DB cluster fails, Aurora automatically
fails over to a new primary DB instance. During a failover, the DB cluster continues to
serve connection requests to the cluster endpoint from the new primary DB instance,
with minimal interruption of service.

The following example illustrates a cluster endpoint for an Aurora MySQL DB cluster.

mydbcluster.cluster-123456789012.us-east-1.rds.amazonaws.com:3306

Reader endpoint
A reader endpoint for an Aurora DB cluster provides load-balancing support for read-
only connections to the DB cluster. Use the reader endpoint for read operations, such
as queries. By processing those statements on the read-only Aurora Replicas, this
endpoint reduces the overhead on the primary instance. It also helps the cluster to scale
the capacity to handle simultaneous SELECT queries, proportional to the number of
Aurora Replicas in the cluster. Each Aurora DB cluster has one reader endpoint.

If the cluster contains one or more Aurora Replicas, the reader endpoint load-balances
each connection request among the Aurora Replicas. In that case, you can only
perform read-only statements such as SELECT in that session. If the cluster only
contains a primary instance and no Aurora Replicas, the reader endpoint connects to
the primary instance. In that case, you can perform write operations through the
endpoint.

The following example illustrates a reader endpoint for an Aurora MySQL DB cluster.

mydbcluster.cluster-ro-123456789012.us-east-1.rds.amazonaws.com:3306

Custom endpoint
A custom endpoint for an Aurora cluster represents a set of DB instances that you
choose. When you connect to the endpoint, Aurora performs load balancing and
chooses one of the instances in the group to handle the connection. You define which
instances this endpoint refers to, and you decide what purpose the endpoint serves.

An Aurora DB cluster has no custom endpoints until you create one. You can create up
to five custom endpoints for each provisioned Aurora cluster. You can't use custom
endpoints for Aurora Serverless clusters.

Instance endpoint
An instance endpoint connects to a specific DB instance within an Aurora cluster.
Each DB instance in a DB cluster has its own unique instance endpoint. So there is one
instance endpoint for the current primary DB instance of the DB cluster, and there is
one instance endpoint for each of the Aurora Replicas in the DB cluster.

mydbinstance.123456789012.us-east-1.rds.amazonaws.com:3306

How to get Cluster Endpoint information ?

aws rds describe-db-clusters --query '*[].


{Endpoint:Endpoint,ReaderEndpoint:ReaderEndpoint,CustomEndpoints:CustomEndpoi
nts}'
Overview of Aurora storage
Aurora data is stored in the cluster volume, which is a single, virtual volume that uses
solid state drives (SSDs). A cluster volume consists of copies of the data across three
Availability Zones in a single AWS Region. Because the data is automatically replicated
across Availability Zones, your data is highly durable with less possibility of data loss.
This replication also ensures that your database is more available during a failover. It
does so because the data copies already exist in the other Availability Zones and
continue to serve data requests to the DB instances in your DB cluster. The amount of
replication is independent of the number of DB instances in your cluster.

Introducing the Aurora Storage Engine | AWS Database Blog (amazon.com)


How to Connect to AWS -Aurora Postgres Instance:

psql --host=pg-cluster-01.cluster-cyl1dmhpwxpb.us-east-2.rds.amazonaws.com --port=5432 --


username=postgres --password --dbname=pgdb

1) Creating tablespace in AWS Aurora Postgres:

Tablespace is like a bigfile tablespace in oracle, it contains one single file.

To List all tablespaces:

pgdb=> \db
List of tablespaces
Name | Owner | Location
------------+----------+----------
pg_default | rdsadmin |
pg_global | rdsadmin |
(2 rows)

pgdb=> create tablespace data_tbsp location '/data_tbsp' ;


CREATE TABLESPACE
pgdb=> \db
List of tablespaces
Name | Owner | Location
------------+----------+----------------------------------
data_tbsp | postgres | /rdsdbdata/tablespaces/data_tbsp
pg_default | rdsadmin |
pg_global | rdsadmin |
(3 rows)

2) Creating the users:

List the users:

pgdb=> \du
List of roles
Role name | Attributes | Member of

-----------------+------------------------------------------------------------+-------------------------------------
------------------------
postgres | Create role, Create DB +| {rds_superuser}
| Password valid until infinity |
rds_ad | Cannot login | {}
rds_iam | Cannot login | {}
rds_password | Cannot login | {}
rds_replication | Cannot login | {}
rds_superuser | Cannot login | {pg_monitor,pg_signal_backend,rds_re
plication,rds_password}
rdsadmin | Superuser, Create role, Create DB, Replication, Bypass RLS+| {}
| Password valid until infinity |

CREATE USER miriam WITH PASSWORD 'jw8s0F4'

pgdb=> create user app_user with password 'Power228$' ;

CREATE ROLE

pgdb=> GRANT ALL PRIVILEGES ON DATABASE pgdb to app_user ;

GRANT
psql --host=pg-cluster-01.cluster-cyl1dmhpwxpb.us-east-2.rds.amazonaws.com --port=5432 --
username=app_user --password --dbname=pgdb

3) Databases:

Most Postgres servers have three databases defined by


default: template0, template1 and postgres. template0 and template1 are skeleton databases
that are or can be used by the CREATE DATABASE command. postgres is the default database
you will connect to before you have created any other databases. 

pgdb=> \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
pgdb | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
rdsadmin | rdsadmin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | rdsadmin=CTc/rdsadmin
template0 | rdsadmin | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/rdsadmin +
| | | | | rdsadmin=CTc/rdsadmin
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)

pgdb=> select current_database() ;

current_database

------------------

pgdb

(1 row)
To switch to another databases:

pgdb=> \connect postgres


Password:
psql (12.8, server 12.7)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
You are now connected to database "postgres" as user "postgres".

4) Create Schema:

pgdb=> create schema app_schema ;

CREATE SCHEMA

To list all the schemas:

pgdb=> \dn
List of schemas
Name | Owner
------------+----------
app_schema | postgres
public | postgres
(2 rows)

5) Create table:

pgdb=> create table app_schema.test_table_01 ( id int) tablespace data_tbsp ;

CREATE TABLE
pgdb=> insert into app_schema.test_table_01 values (1) ;

INSERT 0 1

pgdb=> select * from app_schema.test_table_01 ;

id

----

AUTOCOMMIT is turned on by default in postgres

pgdb=> \set autocommit on ;

pgdb=> \echo :autocommit

on;

pgdb=> \set autocommit off;

pgdb=> \echo :autocommit

off;
AWS CLI

-bash-4.2$ echo $HOME


/var/lib/pgsql

-bash-4.2$ cd $HOME/.aws

-bash-4.2$ ls -ltr
total 4
-rw-r--r--. 1 postgres postgres 136 Sep 2 16:55 config

-bash-4.2$ cat config


[default]
aws_access_key_id = AKIAQCUMZUZ4AQTBTUXN
aws_secret_access_key = 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
region = us-east-2

-bash-4.2$ aws rds describe-db-clusters

{
"DBClusters": [
{
"MasterUsername": "postgres",
"ReaderEndpoint": "pg-cluster-01.cluster-ro-cyl1dmhpwxpb.us-east-2.rds.amazonaws.com",
"HttpEndpointEnabled": false,
"ReadReplicaIdentifiers": [],
"VpcSecurityGroups": [
{
"Status": "active",
"VpcSecurityGroupId": "sg-0f75ccce52c5caaa6"
}
],
"CopyTagsToSnapshot": false,
"HostedZoneId": "Z2XHWR1WZ565X2",
"EngineMode": "provisioned",
"Status": "available",
"MultiAZ": true,
"LatestRestorableTime": "2021-09-02T21:57:20.873Z",
"PreferredBackupWindow": "09:34-10:04",
"DBSubnetGroup": "default-vpc-0bd335e3a338ec446",
"AllocatedStorage": 1,
"ActivityStreamStatus": "stopped",
"BackupRetentionPeriod": 1,
"PreferredMaintenanceWindow": "mon:07:00-mon:09:00",
"Engine": "aurora-postgresql",
"Endpoint": "pg-cluster-01.cluster-cyl1dmhpwxpb.us-east-2.rds.amazonaws.com",
"AssociatedRoles": [],
"EarliestRestorableTime": "2021-09-02T21:24:18.567Z",
"CrossAccountClone": false,
"IAMDatabaseAuthenticationEnabled": false,
"ClusterCreateTime": "2021-09-02T21:23:06.794Z",
"EngineVersion": "12.7",
"DeletionProtection": false,
"DBClusterIdentifier": "pg-cluster-01",
"DbClusterResourceId": "cluster-FKDAIUYTUFNYZ5T23H2OAWQNYU",
"DBClusterMembers": [
{
"IsClusterWriter": false,
"DBClusterParameterGroupStatus": "in-sync",
"PromotionTier": 1,
"DBInstanceIdentifier": "pg-cluster-01-instance-1-us-east-2c"
},
{
"IsClusterWriter": true,
"DBClusterParameterGroupStatus": "in-sync",
"PromotionTier": 1,
"DBInstanceIdentifier": "pg-cluster-01-instance-1"
}
],
"DBClusterArn": "arn:aws:rds:us-east-2:005663991416:cluster:pg-cluster-01",
"KmsKeyId": "arn:aws:kms:us-east-2:005663991416:key/4803271a-a2cb-42b6-9de0-
dc72ac397b31",
"StorageEncrypted": true,
"DatabaseName": "pgdb",
"DBClusterParameterGroup": "default.aurora-postgresql12",
"AvailabilityZones": [
"us-east-2b",
"us-east-2c",
"us-east-2a"
],
"Port": 5432
}
]
}

How to get the aurora version ?

postgres> select aurora_version() ;

postgres> select version() ;

How to Get Endpoints for a cluster ?

-bash-4.2$ aws rds describe-db-clusters --query '*[].


{Endpoint:Endpoint,ReaderEndpoint:ReaderEndpoint,CustomEndpoints:CustomEndpoints}'

[
{
"CustomEndpoints": null,
"Endpoint": "pg-cluster-01.cluster-cyl1dmhpwxpb.us-east-2.rds.amazonaws.com",
"ReaderEndpoint": "pg-cluster-01.cluster-ro-cyl1dmhpwxpb.us-east-2.rds.amazonaws.com"
}
]

How to get the Latest and Earliest Restore point times:

-bash-4.2$ aws rds describe-db-clusters --query '*[].


{DBClusterIdentifier:DBClusterIdentifier,EarliestRestorableTime:EarliestRestorableTime,LatestRestora
bleTime:LatestRestorableTime}'
[
{
"EarliestRestorableTime": "2021-09-02T21:24:18.567Z",
"LatestRestorableTime": "2021-09-03T03:54:13.563Z",
"DBClusterIdentifier": "pg-cluster-01"
}
]
AWS Backup and Recovery:

AWS Aurora Backup’s to S3 automatically, no need for manually taking backup.

Backup Window is for system:

Aws rds create-db-cluster [--preferred-maintenance-window <value>]

--preferred-maintenance-window  

 Must be in the format hh24:mi-hh24:mi .


 Must be in Universal Coordinated Time (UTC).
 Must not conflict with the preferred maintenance window.
 Must be at least 30 minutes.
modify-db-cluster

--db-cluster-identifier <value>

--preferred-backup-window <value>]

[--preferred-maintenance-window <value>

Backup Retention:

You can specify a backup retention period, from 1 to 35 days

Restore the AWS Aurora Cluster ?

Using aws cli:

aws rds restore-db-cluster-to-point-in-time \


--source-db-cluster-identifier pg-cluster-01 \
--db-cluster-identifier pg-cluster-02 \
--restore-to-time 2021-09-07T01:03:59.380Z

You might also like