Install Last PgAdmin 4 on RHEL/CentOS 7

Featured image

PgAdmin 4 is a rewrite of the popular pgAdmin3 management tool for the PostgreSQL (http://www.postgresql.org) database. Installing the last version under CentOS 7 can be a bit tricky, here it is one way how to do it.

Download the Python wheel for the last pgAdmin release listed on the following page : https://www.pgadmin.org/download/pgadmin-4-python-wheel/.

cd ~/Downloads
wget https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.10/pip/pgadmin4-4.10-py2.py3-none-any.whl

The pgAdmin 4 team advices to use a virtual environment therefore create one dedicated to pgAdmin.

conda create -n pgadmin4 python=3.6

Activate this new environment.

conda activate pgadmin4

Install the Python wheel you just download.

pip install pgadmin4-4.10-py2.py3-none-any.whl

Check the pgAdmin4 installation location.

sudo find / -name pgAdmin4.py

It should return something like:

/home/username/anaconda3/envs/pgadmin4/lib/python3.6/site-packages/pgadmin4/pgAdmin4.py

Edit a config_local.py in the same directory.

vi /home/username/anaconda3/envs/pgadmin4/lib/python3.6/site-packages/pgadmin4/config_local.py

Insert (i) in it the following content:

import os
DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/'))
LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
SQLITE_PATH = os.path.join(DATA_DIR, 'pgadmin4.db')
SESSION_DB_PATH = os.path.join(DATA_DIR, 'sessions') 
STORAGE_DIR = os.path.join(DATA_DIR, 'storage')
SERVER_MODE = False

Save and close this configuration file (:wq).

Run pgAdmin 4.

python $(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib() + '/pgadmin4/pgAdmin4.py')")

Open the given to address (http://127.0.0.1:5050) to access the PgAdmin 4 interface.

Create a shortcut

Create a dedicated folder for your shortcuts.

mkdir ~/.shortcuts
touch ~/.shortcuts/pgadmin4
chmod +x ~/.shortcuts/pgadmin4

Edit in it a bash script for pgadmin4

vi ~/.shortcuts/pgadmin4

..with the following content:

#!/bin/bash
eval "$(conda shell.bash hook)"
conda activate pgadmin4
python /home/username/anaconda3/envs/pgadmin4/lib/python3.6/site-packages/pgadmin4/pgAdmin4.py

Save and close it (:wq).

Add the ~/.shortcuts directory to your ~/.bashrc file.

echo 'export PATH="/home/username/.shortcuts:$PATH"' >> ~/.bashrc

In a new terminal window, you will now be able to launch pgAdmin 4 just by typing the pgadmin4 command.

Connecting to a PostgreSQL database with pgAdmin4

  • Open pgAdmin4
  • Under the Browser panel right click on Servers > Create > Server…
  • Enter any relevant name for your server eg: Localhost
  • Click on the Connection tab
  • Enter a Host (on your own local system the default is “localhost” otherwise the IP address of the system where the PostgreSQL database is installed)
  • Enter the Port (the default port for PostgreSQL server is “5432”)
  • Enter the Maintenance Database name (the default is postgres)
  • Enter the Username (the default user is postgres)
  • Enter the Password (the password for the postgres user)
  • Save

Now the server and its objects should appear.

See also

Monitor SSIS job and package executions

date_range 02/09/2020

Featured image

How to monitor SSIS job and package executions.

Enable network connectivity between Docker containers on CentOS 8

date_range 15/08/2020

Featured image

Enable a network connectivity between Docker containers on CentOS 8.

Setup a GitHub repository to serve your Sphinx documentation

date_range 07/04/2020

Featured image

Sphinx and GitHub provide an efficient and free way to publish your documentation online. Here we describe how to do so.