HOW TO INSTALL POSTGRESQL (PSQL) IN UBUNTU 16.04

0
22
HOW TO INSTALL POSTGRESQL (PSQL) IN UBUNTU 16.04

HOW TO INSTALL POSTGRESQL (PSQL) IN UBUNTU 16.04

Introduction
In this article we are going to learn How to install Postgresql (psql) in Ubuntu 16.04. Postgresql is a open source database management system. It’s also called as ORDBMS i.e. Object Relational Database Management System. The main developer of Postgresql (psql) is PostgreSQL Global Development Group written the application using C programming language and initially released it’s first version on year 1996 under PostgreSQL License.

The purpose of this application is it stores your data securely in his system called database and user can retrieve the stored data using SQL client application. It’s an cross platform application available for major operating systems i.e. Linux, Unix, Microsoft Windows, Solaris and MacOS. You can download the repository of Postgresql (psql) from Github. There are some limitations has been defined by developer team in Postgresql (psql) i.e. Your table size cannot be more then 32 TB, Maximum field size & row size are 1 GB & 1.6 GB. There is no limitation for database size. You can use unlimited size of database.
For more Information and features of Postgresql (psql) you can visit the official website.
Follow the below steps to install Postgresql (psql) in Ubuntu 16.04
Before start the installation of Postgresql (psql) let’s update the packages & repositories of Ubuntu 16.04 using below command.

elinuxbook@ubuntu:~$ sudo apt-get update # Update Packages & Repositories
Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease
Reading package lists… Done

After updating the packages & repositories now we are ready to install Postgresql (psql) application and to install so we don’t have to install any 3rd party PPA repository as it’s a part of default repository of Ubuntu 16.04. So let’s go ahead and install the same using below command.

elinuxbook@ubuntu:~$ sudo apt-get install postgresql postgresql-contrib # Install the Package
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
libpq5 postgresql-9.5 postgresql-client-9.5 postgresql-client-common postgresql-common postgresql-contrib-9.5 sysstat
Suggested packages:
postgresql-doc locales-all postgresql-doc-9.5 libdbd-pg-perl isag
The following NEW packages will be installed:
libpq5 postgresql postgresql-9.5 postgresql-client-9.5 postgresql-client-common postgresql-common postgresql-contrib postgresql-contrib-9.5 sysstat
0 upgraded, 9 newly installed, 0 to remove and 497 not upgraded.
Need to get 4,841 kB of archives.
After this operation, 19.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y —> Enter ‘y’ to continue the installation




Also Read :

As you can see above we have successfully installed the Postgresql (psql) package. Now to confirm the same use the below command.

elinuxbook@ubuntu:~$ sudo dpkg -l postgresql # Confirm installed Package
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-====================================-=======================-=======================-=============================================================================
ii postgresql 9.5+173ubuntu0.1 all object-relational SQL database (supported version)

Now to login in to the application you have to switch to root user. So to switch to root user use the below command.
elinuxbook@ubuntu:~$ sudo su # Switch to root User

Now we are ready to login Postgresql (psql) application. By default we have to login the application using the user postgres.  Hence to login the same use the below command
root@ubuntu:/home/elinuxbook# su – postgres # Login the application

Now to get the sql prompt just type the command psql.  Refer the command below.

postgres@ubuntu:~$ psql # Command to get the SQL Prompt
psql (9.5.11)
Type “help” for help.

postgres=# # Postgresql Prompt

For commands and syntax of this application just type the command help or you can also type \h. Refer the command below.
postgres=# help —> For command Help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

postgres=# \h —> For command Help

By default the postgres user comes with blank password but you can set password for postgres using below command.
postgres=# \password postgres # Set Password
Enter new password: —> Type a new password
Enter it again: —> Retype the Password

To come out from the postgres prompt just type the command \q.

postgres=# \q —> Logout from Postgresql (psql)

This is how we can install Postgresql (psql) in Ubuntu 16.04. If you found this article useful then Like us, Share this post on your preferred Social media, Subscribe our Newsletter OR if you have something to say then feel free to comment on the comment box below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here