How To Install PostgreSQL on Ubuntu 16.04 LTS

Advertisement

Old readers can recall that we had guides for PostgreSQL with WordPress. New and old users can recall our recent guide on how to install MongoDB. PostgreSQL is time tested and often compared head to head with MongoDB. Here is how to install PostgreSQL on Ubuntu 16.04 LTS Server via SSH. In this article we will avoid the comparison but only discuss the steps to install, configure and secure PostgreSQL.

Install PostgreSQL from the Ubuntu package repository with phppgadmin (PHP based web administration tool like PHPMyAdmin used for MySQL) :

Vim

1

sudo apt-get install postgresql postgresql-contrib phppgadmin

Change the postgres user’s Linux password:

Vim

1

sudo passwd postgres

PostgreSQL uses role for user authentication and authorization in Unix-Style. By default, PostgreSQL creates a new user called “postgres” for basic authentication. The following commands are for setting a password for the postgres database user :

Vim

1

2

su-postgres

psql-dtemplate1-c"ALTER USER postgres WITH PASSWORD 'yourpassword';"

yourpassword is example our password. This user is distinct from the postgres Linux user which is used to access the database, and the PostgreSQL user is used to perform administrative tasks. This password set in this step will be used to connect to the database.