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…
pgAdmin is a web-based interface for managing of PostgreSQL database instances easily from your web browser… This brief tutorial shows students and new users how to install PostgreSQL server on Ubuntu and manage it via pgAdmin4….
If you’re not a seasoned database administrator and you want to manage PostgreSQL easily via your favorite web browser, then use pgAdmin4…
To learn how to install PostgreSQL and pgAdmin4 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 packages 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 11, run the commands below
sudo apt update sudo apt-get install postgresql-11
After installing 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 Wed 2018-10-31 11:58:09 CDT; 12s ago
Main PID: 7930 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4663)
CGroup: /system.slice/postgresql.service
Oct 31 11:58:09 ubuntu1804 systemd[1]: Starting PostgreSQL RDBMS...
Oct 31 11:58:09 ubuntu1804 systemd[1]: Started PostgreSQL RDBMS.
Step 3: Creating PostgreSQL Linux 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
You should be prompted to create a new Linux password for postgres user..
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
After setting a new password, every time you want to access PostgreSQL interactive shell, you’ll be prompted to confirm the password you created after running the commands above…
Step 4: 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.
psql
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
After that, quit and exit..
\q exit
Step 5: Installing pgAdmin4 Web Interface
Now that PostgreSQL is installed, run the commands below to install pgAdmin4 to use to manage your PostgreSQL server…
sudo apt-get install pgadmin4 pgadmin4-apache2
During the installation you will be prompted to enter PostgreSQL user password…
Create a password for pgAdmin4 web service..
After installing, open your web browser and browse to the server hostname or IP address followed by pgAdmin4 URI
http://example.com/pgadmin4
Enter the web interface initial user account as shown in the image above..
Login and add a new PostgreSQL server…
Enjoy!
That’s it! You may want to restrict access to only local IP address…
You may also like the post below: