Techies.

Using pgAdmin to manage your bots PostgeSQL database

In this article, you will learn how to connect to your application's PostgreSQL database using pgAdmin


Note, this article assumes you are using docker to run your application as per the How do I view my app? article.

Initial steps

  1. Start your application if it is not already running
docker-compose up -d
  1. After a few moments, the docker containers should start, one of which is running pgAdmin. Before connecting to pgAdmin, you will need to know the port number it is listening on.
docker-compose ps

Doing so will show you the running containers, one of which is pgAdmin (in this case, the third one)

Name                   Command               State                    Ports
-------------------------------------------------------------------------------------------------
a086_client_1    docker-entrypoint.sh sh -c ...   Up
a086_db_1        docker-entrypoint.sh postgres    Up      5432/tcp
a086_pgAdmin_1   /entrypoint.sh                   Up      443/tcp, 80/tcp, 0.0.0.0:9091->9090/tcp
a086_server_1    sh -c  dotnet new tool-man ...   Up      0.0.0.0:8001->5000/tcp
  1. Under the “ports” column for the “pgAdmin” container, look for the entry which contains 0.0.0.0:xxxx. In this case, it is 0.0.0.0:9091 (Please note that different bots may use different ports) This indicates that we can access pgAdmin on port 9091 of the local host. (eg http://localhost:9091)

Logging in

  1. Open your browser to the URL you determined above (eg http://localhost:9091) and you will be presented with a login screen.
  2. The credentials for the login screen can be found in the docker-compose.yml file in the root of your repository. Specifically, look for the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD environment variables.

Image
Image

  1. If this is your first time logging in to pgAdmin, you will need to add the connection to your application’s PostgreSQL server, otherwise you can skip these steps.

a) Before you proceed, you will need to know the credentials to the PostgreSQL database. This can be found in the docker-compose.yml file in the root of your repository. Specifically, look for the POSTGRES_DB, POSTGRES_USER, and POSTGRES_PASSWORD environment variables.

Image

b) Click “Add New Server”

Image

c) On the first tab (General), give your connection a name. This can be anything you like, though we recommend using the name of your application

Image

d) On the second tab (Connection), fill in the following fields, then click the Save button

Host name/address:  db
  Maintenance database:  [the value of the POSTGRES_DB environment variable from step 3a above]
  Username:  [the value of the POSTGRES_USER environment variable from step 3a above]
  Password:  [the value of the POSTGRES_PASSWORD environment variable from step 3a above]
  Save Password:  Checked/Ticked

Image

  1. Your connection should now show up on in the left-hand menu. If it doesn’t automatically connect (little red cross on the connection), you can click on the connection and it should initiate the connection

Image

  1. You should now be connected to your PostgreSQL database and can manage the database, tables, data, etc.

Image

For further information on how to use pgAdmin, head over to pgAdmin’s website and check out the official documentation: https://www.pgadmin.org/docs/

Last updated: 27 August 2020


Related articles