PostgreSQL, a powerful opensource object-relational database has seen a new release… version 10 and this brief tutorial is going to show students and new users how to easily install it on Ubuntu 16.04 / 17.10 and 18.04 LTS….
For those who don’t know PostgreSQL, or simple Postgres, here’s a brief overview…
PostgreSQL is a general purpose and object-relational database management system, probably the most advanced open source database system…. you can also add custom functions using different programming languages such as C/C++, Java, etc…
It is used by major corporations and businesses looking for high performance database systems…
Most people will tell you a thing or two about MySQL and MariaDB… however, for professionals, PostgresSQL reigns..
To learn how to install PostgreSQL Ubuntu, follow the steps below
Step 1: Add PostgresSQL Repository to Ubuntu
Adding PostgresSQL repository to Ubuntu is easy… all you have to run is run the commands below to add the repository key.,., the key is there to authenticate and validate pcakges from the repository….
Run the commands below to add the repository key and the repository…
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main" > /etc/apt/sources.list.d/PostgreSQL.list'
When you’re done… continue below…
Step 2: Update and Install PostgreSQL
Now that the repository and key are added, run the commands below to update and install the latest PostgresSQL packages..
To install PostgreSQL 10, run the commands below
sudo apt update sudo apt-get install postgresql-10
After isntalling PostgreSQL, the commands below can be used to stop, start, enable and check its status
sudo systemctl stop postgresql.service sudo systemctl start postgresql.service sudo systemctl enable postgresql.service sudo systemctl status postgresql.service
This is what the status command shows
● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor prese Active: active (exited) since Sat 2018-06-02 11:03:33 CDT; 15s ago Main PID: 5461 (code=exited, status=0/SUCCESS) Tasks: 0 (limit: 3532) CGroup: /system.slice/postgresql.service Jun 02 11:03:33 ubuntu1804 systemd: Starting PostgreSQL RDBMS... Jun 02 11:03:33 ubuntu1804 systemd: Started PostgreSQL RDBMS. lines 1-9/9 (END)
Step 3: Accessing PostgreSQL
Now that PostgreSQL is installed, to access its interactive shell and manage databases… you need to log in as the postgres user… to do that run the commands below:
sudo su -l postgres
Then use the psql command in an interactive shell when you want to create and manage PostgreSQL databases.
Step 4: Changing PostgreSQL User Password…
After installing PostgreSQL, it’s a good idea to create / change the default PostgreSQL user password… Run the commands below to create / change the user password in the bash shell and not PostgreSQL interactive shell..
Set password for Linux user (postgres)
sudo passwd postgres
After setting a new password, everytime you want to accesss PostgreSQL interactive shell, you’ll be prompted to confirm the password you created after running the commands above…
Set password for DB administrator (postgres)
su - postgres psql
On psql shell, run below command to change database admin password.
postgres=# \password OR postgres=# \password postgres
This is how to install PostgreSQL on Ubuntu and set the user and database admin passwords…
If you want to install PostgreSQL web client, like phpMyAdmin, run the commands below
sudo apt-get install pgadmin3
You may also like the post below: