Description


When launched, the pgvip service (module pgvip.c) loads parameters from the pgvip.conf configuration file into global variables (global.h,global.c), generates final operating system commands based on templates with variables, starts the threads. All configuration file parameters and final commands correspond to global variables of the same name with the prefix g_.

Check threads with an interval of {time_check_interval} execute commands {command_db_state},{command_vip_state} and set the result to the global variable g_status. Only commands that were executed with an error are written to the system log.

Action thread with the interval {time_command_ssh_timeout_int+time_check_interval_int+1} sequentially executes actions from the list (array of procedures), which, if the condition from the g_status variable is successfully checked, OS commands are executed (usually one). The results of the actions are not analyzed, they will be obtained by checking on all web servers.
Written in the system log:


Threads

Thread Purpose Module Function
CHECKER_MASTER_DB checking the status of master database checker.c checker_master_db_thread
CHECKER_STANDBY_DB checking the status of standby database checker.c checker_standby_db_thread
CHECKER_MASTER_VIP checking virtual IP address on the master server checker.c checker_master_vip_thread
CHECKER_STANDBY_VIP checking virtual IP address on the standby server checker.c checker_standby_vip_thread
ACTION_EXECUTOR performing actions action.c action_executor_thread
MONITORING sending metric to the monitoring system, notification monitoring.c monitoring_thread
LOGGER log rotation, checking for updates util_log.c _log_thread
ADMINISTRATION processing of status, stop and show commands util_admin.c _admin_thread


Actions

The action table is generated from the action.c module.
To get the command text by the variable name, need to execute in the command line
pgvip show config | grep [var]

Action (procedure) Condition (if) Commands (vars)
action_master_vip_auto_down_execute status.master_vip_auto_down==G_VIP_AUTO_DOWN_NOT_EXECUTING command_master_vip_auto_down_execute
action_master_vip_up status.standby_db_state!=G_DB_STATE_READ_WRITE &&
status.master_db_state==G_DB_STATE_READ_WRITE &&
status.master_vip_state==G_VIP_STATE_DOWN &&
status.master_vip_auto_down==G_VIP_AUTO_DOWN_EXECUTING
command_master_vip_up
action_master_vip_down status.master_vip_state==G_VIP_STATE_UP &&
(status.master_db_state!=G_DB_STATE_READ_WRITE ||
status.standby_db_state==G_DB_STATE_READ_WRITE)
command_master_vip_down
action_standby_vip_auto_down_execute status.standby_vip_auto_down==G_VIP_AUTO_DOWN_NOT_EXECUTING command_standby_vip_auto_down_execute
action_standby_vip_up status.master_vip_state!=G_VIP_STATE_UP &&
status.standby_db_state==G_DB_STATE_READ_WRITE &&
status.standby_vip_state==G_VIP_STATE_DOWN &&
status.standby_vip_auto_down==G_VIP_AUTO_DOWN_EXECUTING
command_standby_vip_up
action_standby_vip_down status.standby_vip_state==G_VIP_STATE_UP &&
status.standby_db_state!=G_DB_STATE_READ_WRITE
command_standby_vip_down
action_standby_db_promote status.master_db_state!=G_DB_STATE_READ_WRITE &&
status.standby_db_state==G_DB_STATE_IN_RECOVERY &&
(time_now()-status.value_time)>g_time_standby_promote_delay_int &&
status.standby_db_lag<=g_time_standby_allowable_lag_int
command_master_vip_down
command_standby_db_promote
command_standby_vip_up
action_master_db_break status.master_db_state==G_DB_STATE_READ_WRITE &&
status.standby_db_state==G_DB_STATE_READ_WRITE
command_master_db_break


Command line

Command line parameters (after installation, can view them by executing pgvip --help)
[root@web-server ~]# pgvip --help
PGVIP is a PostgreSQL master-standby auto failover service via a virtual IP address
version 25.1.1, linux 64 bits

All parameters (IP addresses, OS commands, timings) in the configuration file /etc/pgsuite/pgvip.conf

Usage:
  pgvip {COMMAND}

Commands:
  start        start execution in another process
  execute      execute in current process
  status       show status
  stop         stop execution
  show config  show runtime configuration
  help|man     print this help

Examples:
  pgvip execute
  pgvip status
  pgvip show config