How to Connect External Postgres

How to Connect External Postgres

To install an external PostgreSQL server, ensure the PostgreSQL version matches the inbuilt PostgreSQL version series of the ServiceDesk Plus application. For example:

  • If ServiceDesk Plus version is 14010 with PostgreSQL version 10.21, install an external PostgreSQL server in the 10.x series ≤ 10.21.

We recommend using Linux as the operating system for the external PostgreSQL server.


To check the inbuilt PostgreSQL version, navigate to <Application Folder>/pgsql/bin/ and execute the following commands:
  • Linux./psql --version
  • Windowspsql.exe --version

Steps to Follow on the PostgreSQL Server

A. Start the External PostgreSQL Server and Open PSQL Console

  1. Start PostgreSQL on Linux:
    sudo service postgresql start
    pg_lsclusters
    sudo -u postgres psql
    

    Info
    This logs into the default PostgreSQL console on port 5432 using the postgres database.


B. Create a New User

  1. Execute the following command based on your PostgreSQL version:

    • For PostgreSQL ≥ 10:
      CREATE USER <username> WITH CREATEDB LOGIN REPLICATION 
      ENCRYPTED PASSWORD '<password>';
      
    • For PostgreSQL < 10:
      CREATE USER <username> WITH SUPERUSER CREATEDB LOGIN REPLICATION 
      ENCRYPTED PASSWORD '<password>';
      
  2. Logout and re-login as the new user:

    \q
    psql -h <host> -p <port> -d postgres -U <newly created user>
    
  3. List all roles and users:

    \du
    

C. Create a Database

  1. Create a new database:

    CREATE DATABASE <new_db_name> WITH OWNER = <your_owner_name> ENCODING = 'UTF8' 
    LC_COLLATE = 'C' LC_CTYPE = 'C' TEMPLATE = template0;
    
  2. Navigate to the new database:

    \c <database_name>
    
  3. List all databases:

    \l
    

D. Create Extensions

  1. Execute the following commands:

    CREATE EXTENSION IF NOT EXISTS pg_trgm;
    CREATE EXTENSION IF NOT EXISTS pgcrypto;
    CREATE EXTENSION IF NOT EXISTS citext;
    
  2. Verify extensions:

    \dx
    

E. Configure the Application Machine Address (If Different from PostgreSQL Server)

  1. Edit pg_hba.conf (e.g., In Linux it is placed in, /etc/postgresql/<version>/main): Add a host row to enable connections. Example:

    host    all    all    XX.XX.XX.XX/XX    md5
    

    Info
    Avoid using 0.0.0.0/0 as it allows access from all machines (not recommended).

  2. Edit postgresql.conf:
    Add the following at the end of the file:

    listen_addresses = '<IP address(es)>'
    

    Avoid using * to listen on all IP interfaces (not recommended).

  3. Restart the PostgreSQL server:

    sudo service postgresql restart
    


Steps to Follow on the Product

  1. Navigate to <prod_home>/bin directory and run:

    • Linux: changeDBServer.sh
    • Windows: changeDBServer.bat

    Configure the database, port, username, and password.

  2. Navigate to <prod_home>/conf/ directory and modify customer-config.xml:

    • Set StartDBServer to FALSE.
  3. Start the application.




                  New to ADSelfService Plus?

                    • Related Articles

                    • How to connect to external postgres(external DB)

                      1. From the postgres installed path navigate to bin folder and open a command prompt 2. Execute the command --> pg_ctl -D "C:\Program Files\PostgreSQL\10\data" start (Postgres server gets started) 3. Connect to DB using the command-->psql -U postgres ...
                    • External Postges - PG Extension Issue

                      Error: If cxs who are using external postgres(not bundled postgres) faces below error, 1. Migration fails with "Upgrade halted. Please create postgres extension pg_trgm and try again" error. (or) 2. Start-up fails with "Application startup halted. ...
                    • Migration failure for Postgres Database with a blank space in it

                      Trace : \ManageEngine\ServiceDesk\Patch\AdventNet_ManageEngine_ServiceDesk_Plus-14.2.0-SP-1.0.0\SERVICEDESK\PreInstall\pg_migrate\pgsql_old\bin\pg_dumpall.exe", -U, postgres, -p, 65433, -h, 127.0.0.1, -r, -w, |, ...
                    • How to resolve Connectivity issues with Postgresql Database from our product?

                      Log Traces Feb 20, 2024 6:40:00 PM [SYSERR] [INFO] : java.sql.SQLException: java.lang.Exception: Exception during getConnection from pool Exception occurred during get connection from datasource Nov 15, 2023 1:29:10 PM [SYSERR] [INFO] : Caused by: ...
                    • Remote read only access to database for Postgres customers

                      Frequently customers want to connect some reporting / dashboard application like PowerBI or Tableau with our Postgres database server. By default, the bundled Postgres is configured to only listen to the local machine. We can configure to allow ...