PostgreSQL®- Running the PgClusterMonitor

  • Install Python version 3.6 or above.
  • Enable the option install pip.
  • Run the following command to install packages on both cluster sides: pip install flake8 psycopg2 urllib3 coloredlogs pywin32 servicemanager
  • config.ini located in the directory: wincc_oa_path/data/NGA/PostgreSQL/sql/Cluster Monitor Tool is for the configuration of the cluster monitoring tool meaning the executable of the tool: main.py.
  • Replace the content of the config.ini with the appropriate content of a template for your system:
    • by copying the content of the appropriate template and replacing the content of the config.ini. file

      or

    • by renaming the appropriate file "Windows: config.windows.template.ini" or Linux: "config.linux.template.ini" to config.ini.
  • Edit the following options of the template.ini file: p1 and p2 (the host, the port and the dbname).
Note: Use IP addresses instead of hostnames in the config.ini file. Change the port to the port number installed. By default, the PostgreSQL port is 5432.
[cluster]
p1 = host=localhost port=5432 dbname=winccoa user=postgres password=postgres
sslmode=prefer sslcompression=1 krbsrvname=postgres target_session_attrs=any
p2 = host=hostName port=5432 dbname=winccoa user=postgres password=postgres
sslmode=prefer sslcompression=1 krbsrvname=postgres target_session_attrs=any
[main] local_node_host_name = p1.
Note: This option is different on the two sides of the cluster: p1 on one and p2 on the other!
pg_data_path = C:/Program Files/PostgreSQL/16/data.
Note: If you installed the default installation, you do not need to change the path. If you did not install the default, adapt the path accordingly.
cmd_create_db_directories= Use the directories you created when creating the
schema:  "db", "ebvents", "alerts",
"backup". Replace by the root directory of your schema:
"C:\\postgresql_backend"
cmd_create_db_directories = (if not exist "C:\\Share\\postgresql_backend"
mkdir "C:\\postgresql_backend") && (if not exist
"C:\\postgresql_backend\\db" mkdir
"C:\\postgresql_backend\\db") && (if not exist
"C:\\postgresql_backend\\alerts" mkdir
"C:\\postgresql_backend\\alerts") && (if not exist
"C:\\postgresql_backend\\events" mkdir
"C:\\postgresql_backend\\events") && (if not exist
"C:\\postgresql_backend\\backups" mkdir
"C:\\postgresql_backend\\backups")
cmd_remove_db_directories = (del /q "C:\Program Files\PostgreSQL\16\data\*")
&& (for /d %%x in ("C:\\Program Files\\PostgreSQL\\16\\data\\*") do
@rd /s /q "%%x") && (if exist "C:\\Share\\postgresql_backend" rmdir
/s /q "C:\\Share\\postgresql_backend")
  • Replace with the real name of your network interface "Ethernet". To display the interfaces run:
    netsh interface ipv4 show interfaces
    cmd_get_network_status_string = netsh interface ipv4 show interfaces "Ethernet" | findstr /e /c:": connected"
  • cmd_success_network_status_string = connected -> If necessary according to your PostgreSQL language installation
    cmd_get_db_status_string = pg_ctl status -D "C:/Program Files/PostgreSQL/16/data"
    cmd_promote_standby_to_master = pg_ctl promote -D "C:/Program Files/PostgreSQL/16/data"
Note: If you installed the default installation, you do not need to change the path. Otherwise, adapt the paths of the following options accordingly.
  • path_to_backup: Edit the path to point to the backup directory of the schema.
  • Run the script main.py
Note: Run it as Administrator if necessary. Alternatively you can also run the Python script as a service.
  • For this navigate to directory wincc_oa_path/data/NGA/PostgreSQL/sql/Cluster Monitor Tool and run
    py windows_service.py --startup=auto install
    as an Administrator.
CAUTION:

If the command fails, verify that the \win32 directory of the Python installation contains the files pythoncom<3x>.dll' and 'pywintypes<3x>.dll'. Depending on the Python installation, the location of the files may vary.

Search for the files in your Python installation and copy them to the \win32 directory.

  • The command above created the service "PgClusterMonitor". Check the status of the "PgClusterMonitor" service in the Windows Task Manager/Services and start the service if necessary.
    Note: The PgClusterMonitor must be running on both servers.
CAUTION: If you have problems starting the service, verify that you are logged in the service as the right user: Open the Windows Start menu and type in "Services".
  • You can also install and run the service as a Linux Service. To do so, proceed as follows:
  • Create a file for service:
    sudo touch /lib/systemd/system/pg-cluster-monitor.service
  • Edit the service pg-cluster-monitor.service as follows:
    [Unit Description=PostgreSQL Cluster Monitor Service After=multi-user.target]
    [Service]
    WorkingDirectory=/pg_cluster_monitor
    User=root
    Type=idle
    ExecStart=/usr/bin/python3 /pg_cluster_monitor/main.py
    Restart=always 
    [Install]
    WantedBy=multi-user.target 
    where /pg_cluster_monitor is directory with source code. 
  • Then run the following commands:
    sudo systemctl daemon-reload sudo systemctl enable 
    pg-cluster-monitor.service sudo systemctl start
    pg-cluster-monitor.service                 
  • Check the status of the service via the command:
     systemctl status pg-cluster-monitor.service