Install Postgres Database & pgAdmin4 on Ubuntu 20.04
2 min readMay 13, 2021
- Go to the terminal and update system software packages
sudo apt update
- Install the package of PostgreSQL and it’s contrib files
sudo apt install postgresql postgresql-contrib
- Once the installation done check the status of postgresql
sudo systemctl is-active postgresql
OR
sudo systemctl status postgresql
- If status is active then go to next step and create database using below command
sudo pg_isready
- To connect the database
sudo su - postgres
- Now create user
$ psql
psql (12.6 (Ubuntu 12.6-0ubuntu0.20.04.1))
Type "help" for help.postgres-# CREATE USER dev_test WITH SUPERUSER PASSWORD 'root';
- Create database
postgres’# create database testing;
- Grant role to the users
postgres'# grant all privileges on database testing to dev_test;
- To check whether connection is secure or not for this we need to check pg_hba.conf file
sudo vim /etc/postgresql/12/main/pg_hba.conf
- Once it is done now install pgadmin4
Install the public key for the repositorycurl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
# Create the file repository configuration:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'# Create the repository configuration file:
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
- Now install pgadmin packages
sudo apt install pgadmin4
- After installation of pgadmin4 do server setup
- Now play around queries
Thank you for reading .Give it try and share your feedback :)