In this guide, we will install and set up a PostgreSQL database on an Ubuntu instance using Alibaba Cloud Elastic Compute Service (ECS).
But before we begin, it is important to know that there are different ways to set up a PostgreSQL database on any cloud provider. For Alibaba Cloud, you can create an instance and set it up manually using Elastic Compute Service (ECS) or by using ApsaraDB RDS.
So before I proceed with the guide, I would point out some few differences between using an ECS or ApsaraDB RDS for your database.
For ApsaraDB RDS (Relational Database Service)
To follow along with this guide, you need to have an instance installed with Ubuntu OS. You can also check this guide on How to create an instance.
After completing the prerequisites, follow the steps below
SSHinto your instance using your key pair for Linux user. For windows, you can use SSH client such as putty to connect to your instance.
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install postgresql
To edit the configuration file(
sudo vim /etc/postgresql/9.5/main/pg_hba.conf.
9.5 is the version of postgreSQL installed. As at the time of writing this article,
9.5 is the default installation for postgreSQL on ubuntu OS.
pg_hba.confin vim, you can use any editor of your choice. Update the file which read something like this
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 md5
This would enable us connect to our database instance.
postgresql.conffile to enable remote connection from anywhere(IP address).
postgresql.conf file run
sudo vim /etc/postgresql/9.5/main/postgresql.conf. Use
:set number to enable the line numbers and look for line 59 which should be like this
#listen_addresses = 'localhost'
Update it to this
listen_addresses = '*'
sudo /etc/init.d/postgresql restart
sudo - su postgres psql
psql command gives us access to the Postgres interactive terminal
CREATE USER ubuntu_user SUPERUSER;
ALTER USER power_user WITH PASSWORD 'password';
CREATE DATABASE mydatabase WITH OWNER power_user;
\q. We can view the content of our database and make changes to it with psql. We can also connect to our database using a database client.
We would be using a database client called postico. you can use any database client of your choices.
new favouriteto add your connection parameters
The field parameters in the screenshot above are explained below
nicknamefield can be anything
Hostfield contains the public IP address of our ECS instance
Userfield contains the username we created earlier which is
passwordfield is for the password we created for the
With ApsaraDB RDS you can get a database instance up and running in minutes. But if you are looking for full control such as configuration and security, then Elastic Compute Service (ECS) is definitely the way to go.
Alibaba Clouder - June 5, 2019
Alibaba Clouder - June 10, 2019
Alibaba Clouder - June 4, 2019
Alibaba Clouder - June 10, 2019
Alibaba Clouder - December 26, 2018
Alibaba Clouder - March 22, 2019
An online computing service that offers elastic and secure virtual cloud servers to cater all your cloud hosting needs.Learn More
An on-demand database hosting service for MySQL, SQL Server and PostgreSQL with automated monitoring, backup and disaster recovery capabilitiesLearn More
An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the worldLearn More
More Posts by Alibaba Clouder