Tutorials  /  Ubuntu

How To Install and Configure pgAdmin 4 in Server Mode on Ubuntu 22.04

Ccentron Redaktion · January 2025 ·3 min read ·Ubuntu, Tutorial

pgAdmin is a powerful open-source platform for administering and developing PostgreSQL and related database management systems. Built with Python and jQuery, it fully supports all PostgreSQL features. pgAdmin allows you to perform tasks ranging from writing SQL queries to monitoring databases and configuring advanced architectures.

This tutorial will guide you through installing and configuring the latest version of pgAdmin on an Ubuntu 18.04 server, accessing pgAdmin via a web browser, and connecting it to a PostgreSQL database.

Prerequisites

To follow this tutorial, ensure you have:

  • An Ubuntu 18.04 server with a non-root user having sudo privileges and a firewall configured using ufw.
  • Nginx installed and set up as a reverse proxy for http://unix:/tmp/pgadmin4.sock.
  • PostgreSQL installed with a dedicated role and database for pgAdmin to connect to.
  • Python 3 and venv installed on the server.
VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Step 1 — Installing pgAdmin and Its Dependencies

The latest version, pgAdmin 4, is recommended over the outdated pgAdmin 3. This step covers installing pgAdmin 4 in a virtual environment and setting up its dependencies.

Update your server’s package index:

Code
sudo apt update

Install required dependencies:

Code
sudo apt install libgmp3-dev libpq-dev

Create directories for session data, storage, and logs:

Code
sudo mkdir -p /var/lib/pgadmin4/sessions
sudo mkdir /var/lib/pgadmin4/storage
sudo mkdir /var/log/pgadmin4

Adjust ownership of these directories:

Code
sudo chown -R sammy:sammy /var/lib/pgadmin4
sudo chown -R sammy:sammy /var/log/pgadmin4

Activate your virtual environment:

Code
cd environments/
source my_env/bin/activate

Upgrade pip:

Code
python -m pip install -U pip

Download the latest pgAdmin 4 source code:

Code
wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v6.10/pip/pgadmin4-6.10-py3-none-any.whl

Install the wheel package and pgAdmin 4:

Code
python -m pip install wheel
python -m pip install pgadmin4-6.10-py3-none-any.whl

Install Gunicorn:

Code
python -m pip install gunicorn

Step 2 — Configuring pgAdmin 4

Create a local configuration file:

Code
nano my_env/lib/python3.10/site-packages/pgadmin4/config_local.py

Add the following settings:

Code
LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'
SERVER_MODE = True

Run the setup script to create login credentials:

Code
python my_env/lib/python3.10/site-packages/pgadmin4/setup.py

Step 3 — Starting Gunicorn and Configuring Nginx

Start the Gunicorn server:

Code
gunicorn --bind unix:/tmp/pgadmin4.sock --workers=1 --threads=25 --chdir ~/environments/my_env/lib/python3.10/site-packages/pgadmin4 pgAdmin4:app

Configure Nginx as a reverse proxy:

Code
sudo nano /etc/nginx/sites-available/your_domain

Add this configuration:

Code
server {
    listen 80;
    listen [::]:80;

    server_name your_domain www.your_domain;
    
    location / {
        proxy_pass http://unix:/tmp/pgadmin4.sock;
        include proxy_params;
    }
}

Restart Nginx:

Code
sudo systemctl restart nginx

Step 4 — Accessing pgAdmin

Open your browser and visit:

http://your_server_ip

Log in with the credentials you set in Step 2.

Step 5 — Configuring Your PostgreSQL User

Access the PostgreSQL prompt:

Code
sudo -u sammy psql

Set a password for your PostgreSQL user:

Code
ALTER USER sammy PASSWORD 'password';

Exit PostgreSQL:

Code
\q

Connect pgAdmin to your PostgreSQL server by adding a new server under the "Servers" menu in pgAdmin.

Step 6 — Creating a Table in the pgAdmin Dashboard

Expand your server, database, and "Schemas." Right-click "Tables" → "Create" → "Table...".

Add columns in the Columns tab:

  • Name: Column name
  • Data type: Data type (e.g., VARCHAR, INT)
  • Primary Key: Enable if needed

Click "Save" to create the table. Use the "INSERT Script" to add data and "View/Edit Data" to view it.

Conclusion

You've installed and configured pgAdmin 4 using Gunicorn and Nginx, connected it to PostgreSQL, and learned how to create and manage tables. For more details, visit the pgAdmin documentation.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren