Install PostgreSQL on Ubuntu (for single/multiple nodes with an external DB)

  1. Create the file repository configuration:

    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

  2. Import the repository signing key:

    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

  3. Update the package lists:

    sudo apt-get update

  4. Install PostgreSQL:

    sudo apt-get -y install postgresql

  5. Open the PostgreSQL port (default, 5432) in the firewall.
  6. Configure PostgreSQL to accept remote connections:

    a. Go to this location: /etc/postgresql/12/main

    Note: /12/ is the version number; in your case, if you have installed a different version, the path will reflect that.

    b. Edit the postgresql.conf file and replace the line:

    #listen_addresses = 'localhost'

    with

    listen_addresses = '*'

    Note: * is for any IP. Alternatively, you can add IPs delimited by commas.

    c. Edit the pg_hba.conf file and add the following lines at the end:

    host    all             all              0.0.0.0/0                  md5

    host    all             all              ::/0                           md5

  7. Restart the PostgreSQL server:

    sudo service postgresql restart

  8. Connect to the PostgreSQL server:

    sudo -u postgres psql

  9. (Optional) Change the password of the postgres user (by default it has no password):

    ALTER ROLE postgres WITH PASSWORD 'password';

  10. Create Databases and Roles:

    CREATE ROLE dc_user LOGIN PASSWORD 'dc_password';
    ALTER USER dc_user WITH CREATEDB;
    CREATE DATABASE dc_db;
    GRANT ALL PRIVILEGES ON DATABASE dc_db TO dc_user;

    CREATE ROLE uam_user LOGIN PASSWORD 'uam_password';
    ALTER USER uam_user WITH CREATEDB;
    CREATE DATABASE uam_db;
    GRANT ALL PRIVILEGES ON DATABASE uam_db TO uam_user;

    CREATE ROLE quartz_user LOGIN PASSWORD 'quartz_password';
    ALTER USER quartz_user WITH CREATEDB;
    CREATE DATABASE quartz_db;
    GRANT ALL PRIVILEGES ON DATABASE quartz_db TO quartz_user;

    CREATE ROLE notification_user LOGIN PASSWORD 'notification_password';
    ALTER USER notification_user WITH CREATEDB;
    CREATE DATABASE notification_db;
    GRANT ALL PRIVILEGES ON DATABASE notification_db TO notification_user;

    CREATE ROLE audit_user LOGIN PASSWORD 'audit_password';
    ALTER USER audit_user WITH CREATEDB;
    CREATE DATABASE audit_db;
    GRANT ALL PRIVILEGES ON DATABASE audit_db TO audit_user;

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.