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.
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”.
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.
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.
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
Step 7: Install PostgreSQL
- 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
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'
- Install PostgreSQL
Update the package lists and install PostgreSQL:
apt update
apt install postgresql postgresql-contrib -y
- Start and Enable PostgreSQL Service
systemctl start postgresql
systemctl enable postgresql
Step 8: Configure PostgreSQL
Switch to the PostgreSQL user:
su - postgres
Access the PostgreSQL prompt:
psql
Change the password for the PostgreSQL user:
\password postgres
Exit the PostgreSQL prompt:
\q
Return to the root user:
exit
Step 9: Install pgAdmin
- 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
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'
- Install pgAdmin
For both desktop and web modes:
apt install pgadmin4 -y
For desktop mode only:
apt install pgadmin4-desktop -y
For web mode only:
apt install pgadmin4-web -y
- Configure the Web Server for pgAdmin
If you installed pgAdmin in web mode, configure the web server:
/usr/pgadmin4/bin/setup-web.sh
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.
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.