How to Install PostgreSQL 9.6 on Debian and Ubuntu
Abstract: Verify PostgreSQL Database To set a password for the postgre database administrator useruse the password command below. $ sudo passwd postgres
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 RepositoryThis 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 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 mainOn 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 updateAdd 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.6Install 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.
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 statusStart 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 # psqlVerify PostgreSQL Database
To set a password for the postgre database administrator user, use this command:
postgres=# \password postgresSet 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 $ psqlSet 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:
- Installing MariaDB 10.1 in Debian Jessie and Running Various MariaDB Queries
- How to Change a Default MySQL/MariaDB Data Directory in Linux
- How to Install and Secure MariaDB 10 in CentOS 7
- How to Install and Secure MariaDB 10 in CentOS 6
- 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.