PostgreSQL is a powerful, highly scalable, open source and cross-platform object-relational database system that runs on Unix-like operating systems including Linux and Windows OS. It is an enterprise level database system which is highly reliable and offers data integrity and correctness to users.

In our earlier article, we’ve explained PostgreSQL 10 installation on CentOS/RHEL and Fedora. In this article, we will explain how to install PostgreSQL 9.6 on Debian, Ubuntu and its derivatives using official PostgreSQL APT repository.

Add PostgreSQL APT Repository

This official PostgreSQL APT repository will combine with your Linux system and offers automatic updates for all supported versions of PostgreSQL on Debian and Ubuntu distributions.

To add the apt repository, first create the file /etc/apt/sources.list.d/pgdg.list, and add a line for the repository as per your distribution.

On Ubuntu Systems

--------------- On Ubuntu 17.04 ---------------
deb http://apt.postgresql.org/pub/repos/apt/ zesty-pgdg main
--------------- On Ubuntu 16.04 ---------------
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
--------------- On Ubuntu 14.04 ---------------
deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main

On Debian Systems

--------------- On Stretch 9.x ---------------
deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main
--------------- On Jessie 8.x ---------------
deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main
--------------- On Wheezy 7.x ---------------
deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main


Then import the repository signing key, and update the system package lists like this.

$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt update 
Add PostgreSQL Key

Add PostgreSQL Key

Install PostgreSQL Server

Once you have added the PostgreSQL apt repository in your respective Linux distribution, now install PostgreSQL server and client packages as follows:

$ sudo apt install postgresql-9.6-server postgresql-9.6 
Install Postgresql Database Server

Install Postgresql Database Server

Important: Unlike in RHEL/CentOS/Fedora where you have to manually initialize the database system, in Ubuntu/Debian, it is initialized automatically. Therefore simply proceed to start database server as described in the next section.

The PostgreSQL data directory /var/lib/postgresql/9.6/main contains all of the data files for the database.

Start and Enable PostgreSQL Server

With the database server initialized, start PostgreSQL service and enable PostgreSQL service to auto start on system boot like this.

--------------- On SystemD --------------- $ sudo systemctl start postgresql.service
$ sudo systemctl enable postgresql.service $ sudo systemctl status postgresql.service --------------- On SysVinit --------------- $ sudo service postgresql-9.6 start
$ sudo chkconfig postgresql on
$ sudo service postgresql-9.6 status
Start and Enable PostgreSQL Database

Start and Enable PostgreSQL Database

Verify PostgreSQL Installation

After installing PostgreSQL database system on your server, verify its installation by connecting to postgres database server. The PostgreSQL administrator user is named as postgres, type this command to access the user system account.

$ sudo su postgres
# cd
# psql
Verify PostgreSQL Database

Verify PostgreSQL Database

To set a password for the postgre database administrator user, use this command:

postgres=# \password postgres
Set Password for PostgreSQL Admin

Set Password for PostgreSQL Admin

To secure the postgre user system account, use the password command below.

$ sudo passwd postgres Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
$su - postgre
$ ls
$ psql
Set Password for Postgre User

Set Password for Postgre User

For more information, go to the PostgreSQL Homepage: https://www.postgresql.org/

Lastly, also read through these articles about popular database management systems:

  1. Installing MariaDB 10.1 in Debian Jessie and Running Various MariaDB Queries
  2. How to Change a Default MySQL/MariaDB Data Directory in Linux
  3. How to Install and Secure MariaDB 10 in CentOS 7
  4. How to Install and Secure MariaDB 10 in CentOS 6
  5. Install MongoDB Community Edition 3.2 on Linux Systems

That’s all for now! To share any thoughts with us, make use of the feedback form below. Remember to always stay connected to Tecmint.com for interesting Linux stuff.

Facebook Comments

More Stuff

Emblematic Group and Mozilla Team Up to Showcase Next Generation o... Everything you share on the internet is a story. You read blog posts and watch videos that make you feel connected to people across the world. Virtual...
Latest Firefox Release is Faster than Ever With the introduction of the new Firefox Quantum browser in 2017 we changed the look, feel, and performance of our core product. Since then we have la...
Competing without a Marketing Budget: When All You Have is a Produ... This is a story about the power of a good landing page, PR efforts, and marketing strategy. The refreshing twist here is that instead of explaining ho...
The Ongoing Fiasco and Mysterious Afterlife of QuadrigaCX I’d say you were a little late to the cryptocurrency party if you haven’t heard about the ongoing catastrophe that’s been QuadrigaCX these past six ...
Spread the love

Posted by News Monkey