Skip to main content

PostgreSQL

We will be using an Ubuntu / Debian machine to setup our PostgreSQL server.

Prerequisites

You will need sudo privileges for setting up PostgreSQL in the following steps.

Steps to setup PostgreSQL

  1. To install PostgreSQL, first refresh your server’s local package index:
    sudo apt update
  2. Then, install the Postgres package along with a -contrib package that adds some additional utilities and functionality:
    sudo apt install postgresql postgresql-contrib
  3. After installation, a default user PostgreSQL is created, to access the PostgreSQL shell, log in to this user:
    sudo -i -u postgres
  4. Create a new role:
    createuser --interactive
    You will be prompted with some choices to create a user based on your specifications
  5. PostgreSQL authentication system requires for each role to have a database associated with it. Let's create the required database with same name as your role:
    createdb <your_user_name>
    For example:
    createdb tdms_user
    We will assume from now on that your user is named as "tdms_user"
  6. To log in with the new user, you will need a Linux user with the same username, if you already have a user with the same name, then skip this step:
    sudo adduser tdms_user
  7. Once this account is created, log in to this user:
    sudo -i -u tdms_user
  8. Now let's log in to the PostgreSQL shell:
    psql
  9. To connect with a different database, run:
    psql -d some_other_db
    where "some_other_db" is the name of another database.

Allowing remote connections on PostgreSQL

To allow remote connections to your PostgreSQL server, you need to know your cluster version. To find the clusters available, run:

sudo pg_lsclusters

Now for your particular cluster you need to update its configuration files. Let's assume you want to allow remote connections for the cluster version 12

  1. In the file /etc/postgresql/12/main/postgresql.conf, allow your CloudTDMS IPv4 address by changing the following line:

    listen_addresses='localhost'

    to

    listen_addresses='<your_tdms_ip_address>'

    where you need to replace "<your_tdms_ip_address>" with the IP address of your CloudTDMS server

  2. In the file /etc/postgresql/12/main/pg_hba.conf, allow your CloudTDMS IPv4 address by changing the following line:

    # IPv4 local connections:
    host all all 127.0.0.1/32 md5

    to

    # IPv4 local connections:
    host all all <your_tdms_ip_address>/32 md5

    where you need to replace "<your_tdms_ip_address>" with the IP address of your CloudTDMS server

  3. Restart your cluster:

    sudo pg_ctlcluter 12 main restart

    Here again we assume you are restarting cluster with version 12

Setting up your PostgreSQL storage on CloudTDMS

Open the storages tab and insert the following values for your new PostgreSQL storage

  • Name: Name for the storage.
  • Hostname: Domain Name or IPv4 address of your PostgreSQL server
  • Port: The port on which your PostgreSQL server is listening for storages (default is 5432).
  • Username: Username of your PostgreSQL server.
  • Password: Password of your PostgreSQL user.
  • Database: The database name.