This guide provides a detailed step-by-step process for installing PostgreSQL and pgAdmin on Ubuntu 22.04, suitable for both beginners and experienced users.

Step 1: Initiating Instance Creation

  • Creating a New Instance:
  • Click on the blue “Create” button located in the top-right corner of the page.
  • Select “Add New Instance” to begin setting up a new virtual machine.
Shape.host Resources dashboard showing the Create menu and available instance templates.

Step 2: Choosing a Location

  • Select a Data Center:
  • On the “Create New Instance” page, choose your preferred data center location. For example, you might select “Amsterdam, Netherlands”.
Shape.host instance form with Amsterdam selected as the data center location.

Step 3: Selecting a Plan

  • Choose a Plan:
  • Pick a plan that meets your requirements. Options vary in specifications and price, from $3.5 to $22 per month, offering different CPU, memory, storage, and bandwidth.
  • Choose an Operating System:
  • Scroll to the “Choose an image” section and select Ubuntu 22.04 from the list of available distributions.
Shape.host instance form with the $22 monthly plan and Ubuntu image selected.

Step 4: Authentication Method

  • Select an Authentication Method:
  • Choose between SSH keys (recommended for better security) or a password for root access. In this guide, we’ll proceed with the password option.
  • Complete Instance Creation:
  • Click the “Create Instance” button at the bottom of the page to finalize the setup.
Shape.host instance form showing authentication, hostname and instance creation options.

Step 5: Connecting to Your Instance

  • Retrieve SSH Credentials:
  • Note the IP address of your newly created instance from the Shape.host dashboard.
  • Retrieve SSH Credentials
    • Note the IP address of your newly created instance from the Shape.host dashboard.
  • Connect via SSH
  • Open a terminal on your local machine and use the following command to connect to your instance:
ssh root@your_instance_ip
  • Replace your_instance_ip with the actual IP address of your instance.

Prerequisites

  • A server running Ubuntu 22.04
  • Root access to the server
  • Basic knowledge of terminal commands

Step 6: Update Your System

Before starting the installation, update your system packages to the latest versions.

apt update && apt upgrade -y
Terminal showing APT package management commands and output.

Step 7: Install PostgreSQL

  1. Add PostgreSQL Repository

First, import the PostgreSQL signing key:

curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
Terminal showing PostgreSQL package repository setup commands.

Next, add the PostgreSQL repository:

sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Terminal showing sh commands or output during Install PostgreSQL.
  1. Install PostgreSQL

Update the package lists and install PostgreSQL:

apt update
apt install postgresql postgresql-contrib -y
Terminal showing APT package management commands and output.
  1. Start and Enable PostgreSQL Service
systemctl start postgresql
systemctl enable postgresql
Terminal showing systemd service management commands or output.

Step 8: Configure PostgreSQL

Switch to the PostgreSQL user:

su - postgres
Terminal showing su commands or output during Configure PostgreSQL.

Access the PostgreSQL prompt:

psql
Terminal showing su commands or output during Configure PostgreSQL.

Change the password for the PostgreSQL user:

\password postgres
Terminal showing su commands or output during Configure PostgreSQL.

Exit the PostgreSQL prompt:

\q
PostgreSQL prompt for changing the database administrator password.

Return to the root user:

exit
Terminal showing a PostgreSQL session exit command.

Step 9: Install pgAdmin

  1. Add pgAdmin Repository

Import the pgAdmin signing key:

curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg
Terminal showing curl commands or output during Install pgAdmin.

Create the repository configuration file:

sh -c 'echo "deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
Terminal showing APT package management commands and output.
  1. Install pgAdmin

For both desktop and web modes:

apt install pgadmin4 -y
Terminal showing APT package management commands and output.

For desktop mode only:

apt install pgadmin4-desktop -y

For web mode only:

apt install pgadmin4-web -y
  1. Configure the Web Server for pgAdmin

If you installed pgAdmin in web mode, configure the web server:

/usr/pgadmin4/bin/setup-web.sh
Terminal showing sh commands or output during Install pgAdmin.
Terminal showing sh commands or output during Install pgAdmin.

Step 10: Access pgAdmin

Open a web browser and navigate to:

http://<your_server_ip>/pgadmin4

Log in with the email and password you set during the web setup.

pgAdmin sign-in form.
pgAdmin dashboard.

For hosting PostgreSQL and pgAdmin, consider using Shape.host’s Linux SSD VPS services. Shape.host provides robust and scalable cloud solutions tailored for various needs, ensuring high performance and reliability for your PostgreSQL and pgAdmin applications. With their Cloud VPS, you can easily scale resources as your application grows, providing an optimal user experience.