Postsgres Guide


Postgres is a database engine that many applications use for running. In this guide, we'll cover getting the database engine running, as well as a web management UI, known as PGAdmin, for managing it

NOTE: This walkthrough assumes you are running a system on Ubuntu Linux and are already connected to a shell window either directly on the system or via a SSH session

  1. We'll start by first making sure we have our packages up to date and then install docker

    sudo apt update -y
    sudo apt install docker.io -y

  2. Next, we'll create a folder to storage our database in. I'll be placing this at /data path. You may want to replace that path if you have multiple drives with different mount points.

    sudo mkdir /data
    sudo mkdir /data/.postgres
    sudo mkdir /data/.postgres/data

  3. Now that we have our data folder, we can setup and run the docker container for the Postgres Database Engine.

    sudo docker run -d --name postgres --restart always --log-opt max-size=10m -p 5432:5432 -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=P@ssw0rd -e POSTGRES_DB=master -v /data/.postgres/data:/var/lib/postgresql/data postgres

    Let's break down the arguments that we are specifying here:

    • -d - This tells the system to start the container in detached mode and run in the background
    • --name postgres - This specifes a unique name for the container
    • --restart always - This tells the container to auto restart if it's ever stopped or on reboot of the system
    • --log-opt max-size=10m - Defines container max log file size of 10MB. Once that limit it reached, older log files will be purged/rotated to prevent the log file from being too large
    • -p 5432:5432 - This maps port 5432 on the host system to port 5432 of the container. Postgres runs on port 5432 by default and it's recommended to leave this at 5432, unless you want to run multiple instances of Postgres on the same system.
    • -e POSTGRES_USER=admin - This defines the default admin user account for the Postgres Database Engine
    • -e POSTGRES_PASSWORD=P@ssw0rd - This defines the default admin user account's password for the Postgres Database Engine
    • -e POSTGRES_DB=master - This defines the default system database for the Postgres Database Engine
    • -v /data/.postgres/data:/var/lib/postgresql/data - Defindes the volume mapping to store postgress data into the /data/.postgres/data folder


  4. Now that the Postgres engine is installed and running, we can setup and run the PGAdmin Web UI

    sudo docker run -d --name pgadmin --restart always --log-opt max-size=10m -p 81:80 -e PGADMIN_DEFAULT_EMAIL=admin@admin.com -e PGADMIN_DEFAULT_PASSWORD=P@ssw0rd dpage/pgadmin4

    Let's break down the arguments that we are specifying here:

    • -d - This tells the system to start the container in detached mode and run in the background
    • --name pgadmin - This specifes a unique name for the container
    • --restart always - This tells the container to auto restart if it's ever stopped or on reboot of the system
    • --log-opt max-size=10m - Defines container max log file size of 10MB. Once that limit it reached, older log files will be purged/rotated to prevent the log file from being too large
    • -p 81:80 - This maps port 81 on the host system to port 80 of the container. This allows us to run something else on port 80, while still being able to access the PG Admin Web UI by navigating to http://127.0.0.1:81 where 127.0.0.1 is the IP address of your system.
    • -e PGADMIN_DEFAULT_EMAIL=admin@admin.com - This defines the default admin user login account
    • -e PGADMIN_DEFAULT_PASSWORD=P@ssw0rd - This defines the default admin user login account's password


  5. Now we can navigate to the Web UI at http://127.0.0.1:81 replacing 127.0.0.1 with the IP address of your system.
    1. Login with credentials:
      • Username: admin@admin.com
      • Password: P@ssw0rd
    2. Right click on Servers
    3. Select Register -> Server
    4. On the General Tab, populate the Name field (i.e., Postgres)
    5. On the Connection Tab:
      • Populate the Host Name field with the IP Address of the server (i.e., 127.0.0.1 or 192.168.1.45)
      • Populate the username with admin
      • Populate the password with P@ssw0rd
      • Toggle Save Password on if you want the connection password to persist
      • CLick Save
      • In the server tree view, expand "Postgres" and then databases. You can now create new logins and databases and run queries on the existing databases


Congrats, you now have the Postgres Database Engine setup and ready for use. You can connect to it from applications using the IP address and port 5432

If you found this guide valueable, please consider donating to help me continue to create similar guides

Cryptocurrency & Bitcoin donation button by NOWPayments