Toad World Blog

Creating and Managing PostgreSQL in Amazon RDS

Apr 3, 2017 10:13:48 AM by Nassyam Basha

Introduction

PostgreSQL, or Postgres, has proven to be a powerful open source RDBMS with lightweight software which is free of charge. Postgres is supported in nearly all operating systems including Linux, UNIX, and Windows. In this article we will learn how to create and manage a Postgres instance through Amazon RDS, as well as how to manage a database with the PGAdmin utility. We will cover a few additional features of RDS.

 

Amazon Cloud

Amazon Cloud offers an easy-to-adopt cloud services platform with compute, storage, and support for various services including database support, game development, application services, developer tools, and so on. This article is focuses on hosting a Postgres database on the Amazon Web Services (AWS) cloud. When considering hosting a database in the Amazon cloud two major options for where to host are available. Amazon introduced RDS – Relational Data Services—specifically for hosting relational databases such as Oracle database, MS SQL server, MySQL and Postgres. Amazon RDS offers great flexibility; you simply select which database and what version and so on, and it can directly launch the database. The other option is EC2 – Elastic Cloud, which gives direct host access, and here we can install either Windows or Linux or UNIX and on top of that, we can install compatible database software or applications. In this article, our example shows how to launch a database instance in Amazon RDS and how to access and manage it.

 

Launching Postgres - RDS

Initially you should have access to the Amazon Cloud and make sure that you are fully aware of how to use its resources and how they will be charged. After successfully subscribing to the Amazon cloud you will have access to the RDS dashboard via the link https://console.aws.amazon.com/rds/home

 3487.basha creating 1.png-550x9999

 

Click on “Get Started Now”; this will take us to the list of database offerings in Amazon cloud; in our scenario we are going to select “PostgreSQL” and click on “Select”.

 6102.basha creating 2.png-550x9999

 

After selecting the desired database engine, Postgres, we can select the database purpose: Production or Dev/Test. Production Database offers a few more features such as multi AZ (Availability zone), which creates the primary database in one zone and replicates it in a different zone for high availability. Using this feature RDS can perform failover anytime automatically. In this article, however, we are selecting Dev/Test.

8267.basha creating 3.png-550x9999

Next we can specify the Postgres version, instance details, instance shape/class information, how much storage is required, and so on. Provide the master username and password to manage this service. Using this we will connect to the service.

8015.basha creating 4.png-550x9999

After crosschecking the entered details, click on “Next Step”. You will be prompted to enter security group information (Virtual Private cloud - VPC), port information, and so on. You can also choose an option to “Create new VPC”.

 5444.basha creating 5.png-550x9999

 

In the Backup section, shown below, we need to select the retention period, backup window and so on, as shown below. Use these settings for comprehensive availability of database backups; you can also enable enhanced monitoring.

0247.basha creating 6.png-550x9999

 

After all the fields are entered, now we can click on “Launch DB instance”. An acknowledgement appears, as shown below, as instance creation is started.

5037.basha creating 7.png-550x9999

7103.basha creating 8.png-550x9999

This total process takes barely a few minutes. In order to view the created instance we can click on “View your DB instances”. As shown below, we can see the status as “Creating” and as soon as this process is completed the status changes to “Available”.

3884.basha creating 9.png-550x9999

After a few minutes of waiting, we can see the instance is available and we can see all the information such as Public DNS, utilization information, and connection information.

7026.basha creating 10.png-550x9999

 

Enable Connectivity

So far, we have just created the database instance; now we need to enable the port and enable the traffic so that we can connect to the database engine from an external network. This can be done by enabling the traffic from “VPC Security Groups”, however to access and use this option, we need to go to the EC2 console. Note that we have to perform the changes for the VPC we have selected/created related to our instance.

3806.basha creating 11.png-550x9999

 

Connecting to a Postgres Database

Now we have deployed our database and now we can connect to the Postgres instance using the database client software.

Note that Amazon offers various tiers of cloud services. If we used EC2, we could deploy the host with Linux or Windows, download and install Postgres manually—and then we would have direct host access. For Amazon EC2 Linux/Unix servers, we would use If we have a dedicated host and we can directly connect to the instance by using PuTTY/SSH or RDP, and for Windows systems we would use RDP.

Because we are using an RDS instance, we don’t know where out database is hosted, so we need to use a client utility to connect to it. There are various client utilities available:

  1. pgAdmin – management tool for Postgres
  2. psql – Postgres client.

In this example we will explore pgAdmin. First we need to gather the RDS information which we specified when creating the instance:

  1. Public DNS
  2. Port
  3. Database name
  4. Username
  5. Password
  6. SSL Mode à Allow

Now we will download the pgAdmin utility from www.pgadmin.org.

We select the desired version for Windows; we can download the file directly without any signups.

6521.basha creating 12.png-550x9999

This is a direct installer typical for Windows. The screen confirms that the installation of pgAdmin is completed. Now we will add the new server to connect our previously created Postgres Instance. Click on “Add New Server”.

4863.basha creating 13.png-550x9999

This will prompt us to enter the fields of DNS/Host, Port, username, password, database name, and so on. Before clicking on Save, we can test the connection and if it is successful then click on Save to save our configuration.

8686.basha creating 14.png-550x9999

After successfully connecting, we can click on our PGDB database, which we created in RDS. The dashboard shows such information as transactions per second, user information and various other important information.

2311.basha creating 15.png-550x9999

The utility pgAdmin provides many features we can use to comprehensively monitor the connection; also we can run any queries/transactions from Query Launcher, which can be accessed from Tools.

 

AWS additional support to RDS Instances

Apart from Postgres database administration, AWS provides some additional support to the created instances such as enhanced monitoring and alarms. In enhanced monitoring, we can review CPU utilization, memory usage, storage space usage, read/write IOPS, and so on, for our instances at a glance. To do this, select the instance name and click on “Show Monitoring”.

0753.basha creating 16.png-550x9999

 

Creating Alarms

After the deployment of the database, Monitoring of the server or the database is highly recommended to know the database availability or to track the usages of the resources such as high utilization in server or mount point usage. Amazon supports a few built-in alarms, which is very critical to the instance. Let’s suppose we need to be notified whenever the user connections reach a specified limit; we can do this with Amazon Alarm. You can explore this option by clicking “Create Rules” and selecting the instance. Once we click on “Create Alarm” the console enables us to set the notification type, what metrics we prefer to configure and the limit. We can create an alarm based on our specifications.

7181.basha creating 17.png-550x9999

After scheduling the alarm, we can see the created alarm and also a warning that the database connections are greater than 1.

We can click on “View” to check on more information about this alert.

 

Summary

Amazon provides an easy way to host databases in the cloud. In this article, we learned we have learned how to create a Postgres database engine in the cloud, as well as how to access it from an external network.

We have also covered various utilities available to access our Postgres database such as pgAdmin with systematically on how to connect. Finally we have explored of AWS RDS enhanced monitoring and creating alarms based on thresholds.

Tags: PostgreSQL

Nassyam Basha

Written by Nassyam Basha

Oracle DBA on 9i/10g/11g/12c with RAC 10g/11g on Linux/UNIX and Windows platforms including exposure on dBase, Foxpro, ORACLE 8i with forms & reports and always in front row to work on challenging tasks. I'm an Oracle 11g Certified Master and Oracle ACE Director.

Specialties:

  • ORACLE 8i/9i/10g/11g/12c
  • RAC 10g/11g/12c,
  • Strong Exposure on Data Guard.
  • Grid Control/EM 11.1/12c/13c
  • Exadata,
  • Oracle Cloud

Co-Author of Oracle DataGuard 11gR2 Beginners Guide[PACKT] Author of OTN articles Member of AIOUG, Speaker @OTN Tour, AIOUG Tech Day and SANGAM14/15/16, TROUG, OUGF Oracle Guru certified by My Oracle Support Community Frequent Contributer in OTN: https://community.oracle.com/people/CKPT , oracle-lists and etc.. Member of Customer advisory board(MOSC) Website: www.oracle-ckpt.com

Member of OraWorld Team: Facebook Page: https://www.facebook.com/oraworldteam Tweet @oraworld_team www.oraworld-team.com

Certifications: Oracle 11g Certified Master. Oracle Exadata Database Machine Certified Implementation Specialist Oracle 11g Certified Professional. Oracle 10g Certified Professional. Oracle Partner Certified Specialist