How to install PostgreSQL (PSQL) in Ubuntu 18.04 – Advanced Open Source Database
In this article, we are going to learn How to install PostgreSQL (PSQL) in Ubuntu 18.04 – Advanced Open Source Database management system. It’s also called ORDBMS i.e. Object-Relational Database Management System. The main developer of Postgresql (PSQL) is PostgreSQL Global Development Group. The program is used in C programming language and initially released its first version on 1996 under PostgreSQL License. The purpose of this application is to securely store your data in a database and the database user can retrieve the archived data using the SQL Client application. This is a cross-platform application available for major operating systems like Linux, Unix, Microsoft Windows, Solaris, and MacOS. You can download PostgreSQL (PSQL) repository from Github Some limitations have been set by the developer team in PostGrace (Github) e.g. Your table size cannot be more than 32 TB, maximum field size and row size is 1 GB and 1.6 GB. There is no limit to the database size. You can use the unlimited size of the database.
Follow the below steps to install PostgreSQL (PSQL) in Ubuntu 18.04 – Advanced Open Source Database:
Before starting the installation of PostgreSQL (PSQL) let’s update the packages & repositories of Ubuntu 18.04 using below command.
itsmarttricks@mangesh:~$ sudo apt-get update [sudo] password for itsmarttricks: Ign:1 cdrom://Ubuntu 18.04.1 LTS _Bionic Beaver_ - Release amd64 (20180725) bionic InRelease Err:2 cdrom://Ubuntu 18.04.1 LTS _Bionic Beaver_ - Release amd64 (20180725) bionic Release Please use apt-cdrom to make this CD-ROM recognized by APT. apt-get update cannot be used to add new CD-ROMs Ign:3 http://dl.google.com/linux/chrome/deb stable InRelease Err:4 http://ppa.launchpad.net/aseman/desktop-apps/ubuntu bionic InRelease
After updating the packages & repositories is now ready for install PostgreSQL (PSQL) application and to install so we do not have any third party PPA repository as it is a part of default repository of Ubuntu 18.04. So let’s go ahead and install the same using below command.
itsmarttricks@mangesh:~$ sudo apt-get install postgresql postgresql-contrib Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: 0 upgraded, 8 newly installed, 0 to remove and 231 not upgraded. Need to get 5,287 kB of archives. After this operation, 20.9 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpq5 amd64 10.6-0ubuntu0.18.04.1 [107 kB] Get:2 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 postgresql-client-common all 190 [29.5 kB] Get:3 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 postgresql-client-10 amd64 10.6-0ubuntu0.18.04.1 [934 kB] Get:4 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 postgresql-common all 190 [157 kB] Get:5 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 postgresql-10 amd64 10.6-0ubuntu0.18.04.1 [3,754 kB]
As we can see above, we have successfully installed PostgreSQL (PSQL) package. Now use the following command.
itsmarttricks@mangesh:~$ sudo dpkg -l postgresql 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 10+190 all object-relational SQL database (s
Also Read – How to Install MySQL 8.0 in Ubuntu 18.04
You now have to switch to the root user to login to the application. Then use the following commands to access the root user.
itsmarttricks@mangesh:~$ sudo su
We are now ready to login to the PostgreSQL (PSQL) application. By default, we have to log in to the application using user postgres. So use the following command
root@mangesh:/home/itsmarttricks# su - postgres
Now to get the SQL prompt just type the command PSQL. Refer the command below.
postgres@mangesh:~$ psql psql (10.6 (Ubuntu 10.6-0ubuntu0.18.04.1)) Type "help" for help. postgres=#
Just type command help or you can also type \ h for the commands and syntax of this application. See the following commands.
postgres=# 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 OR postgres=# \h
By default the postgres user comes with blank password but you can set password for postgres using below command.
postgres=# \password postgres Enter new password: Enter it again:
Type \q command only to exit the postgres prompt.
postgres=# \q postgres@mangesh:~$
How To Uninstall PostgreSQL (PSQL) in Ubuntu 18.04?
For any reasons, if you don’t like PostgreSQL (PSQL) and want to uninstall the application from your system using the following command.
itsmarttricks@mangesh:~$ sudo apt-get --purge remove postgresql [sudo] password for itsmarttricks: Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: postgresql* 0 upgraded, 0 newly installed, 1 to remove and 231 not upgraded. After this operation, 63.5 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 190416 files and directories currently installed.) Removing postgresql (10+190) ...
That’s all, In this article, we have explained the How to install PostgreSQL (PSQL) in Ubuntu 18.04 – Advanced Open Source Database. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.