Support Online
Skip to main content

Configuring Server Mode in Ubuntu

What Will You Learn in This Guide?

This guide teaches you how to install pgAdmin 4 in Server Mode on an Ubuntu-based server, run it in a Python virtual environment, and expose it to the web with Nginx + Gunicorn.

1. Technical Summary

Purpose: To install pgAdmin 4 in a Python virtual environment and provide graphical PostgreSQL management.
Steps: Dependency installation → venv activation → pgAdmin installation → config → Gunicorn + Nginx → PostgreSQL connection.


2. Installing pgAdmin 4 and Dependencies

2.1 Update package directory:

sudo apt update

This command refreshes the package list on the system.

2.2 Install dependencies:

sudo apt install libgmp3-dev libpq-dev

Installs the basic libraries required for pgAdmin to work.


2.3 Create the necessary directories:

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

Creates folders for pgAdmin's session, storage and log files.

2.4 Edit directory permissions:

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

Grants temporary permission for pgAdmin to write during installation.

2.5 Activate the virtual environment:

cd environments/
source my_env/bin/activate

Allows you to install pgAdmin in an isolated Python environment.


Update 2.6 pip:

python -m pip install -U pip

Ensures that pip in the virtual environment is up to date.

Download the 2.7 pgAdmin wheel file:

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

Downloads the Python distribution package for pgAdmin 4.


Install the 2.8 wheel package:

python -m pip install wheel

Provides the necessary tools to install .whl files.

Install the 2.9 pgAdmin 4 package:

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

Installs pgAdmin into the virtual environment.

Install the 2.10 Gunicorn WSGI server:

python -m pip install gunicorn

Installs the application server that will run pgAdmin on the web.


3. pgAdmin 4 Configuration

3.1 Create config_local.py:

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

Opens the file to customize pgAdmin settings.

3.2 Add the following configuration:

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

Puts pgAdmin into Server Mode and defines the necessary file paths.


3.3 Run the initial user account setup:

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

Creates an admin account to log in to the pgAdmin panel.


4. Gunicorn and Nginx Configuration

4.1 Sample Nginx reverse proxy configuration:

server {
listen 80;
server_name panel.ornek.com;

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

Nginx redirects external requests to the Gunicorn socket.


4.2 Launch Gunicorn:

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

Runs the pgAdmin application via Gunicorn.


5. Assigning a Password to PostgreSQL User

5.1 Introduction to PostgreSQL:

sudo -u sammy psql

Opens command line as PostgreSQL super user.

5.2 Assign password to user:

ALTER USER sammy PASSWORD 'GüçlüBirParola123';

Enables pgAdmin to connect to PostgreSQL.

5.3 Quit PostgreSQL:

\q

Ends the PSQL session.


6. Accessing the pgAdmin Web Interface

  • Type in your browser:
http://panel.ornek.com

You will reach the pgAdmin login screen.


7. Adding PostgreSQL Server to pgAdmin

7.1 Connection settings:

  • Host: localhost
  • Port: 5432
  • Maintenance DB: sammy
  • Username: sammy
  • Password: the password you specify

Creates connection between pgAdmin and PostgreSQL.


8. Creating a Table and Adding Data

8.1 Sample INSERT query:

INSERT INTO public."table01"(col1, col2, col3)
VALUES ('Juneau', 14, 337),
('Bismark', 90, 2334),
('Lansing', 51, 556);

Adds sample data to the table you create.


Frequently Asked Questions

1. Why is pgAdmin 4 preferred? Because it offers a modern, fast and web-based management panel.

2. What does Server Mode do? It turns pgAdmin into a multi-user web panel.

3. Why use Gunicorn and Nginx together? Gunicorn runs the application, Nginx provides secure access from the outside world.

4. Why does PostgreSQL require a password? GUI tools require password-based connection.

5. What to do to run Gunicorn permanently? Supervisor or systemd service is created.


Result

With this guide, you installed and configured pgAdmin 4 on Ubuntu and integrated it with PostgreSQL.
You can now manage your database via the graphical web panel.

You can visit the GenixNode platform for more content.