Pgpool-II Communication Protocol (PCP) library and pcp_* utilities which are used to manage & monitor Pgpool-II cluster. Pgpool-II and all the utilities are Linux based. To develop application and web interface you have to be on some *nix system, which limit the choice of integration of Pgpool-II with other systems and platforms.
PCP Library
To overcome this limitation, I developed a Native Python based PCP library (which does not require Pgpool-II/PCP library) with name pyPCP. Being written in Python language it can be used on any system. pyPCP provides an interface for administrators to perform management operation, such as getting Pgpool-II status or terminating Pgpool-II processes remotely. You can use library get statistics about Pgpool-II interaction with client application and backend PostgreSQL servers. Pgpool-II installation is not required on local machine. Currently It is tested on Mac, Linux and Windows systems.
How to Install
You can install and update pypcp using pip.
$ pip install pypcp
Example Usage
from pypcp import PCP, ResultStateType
pcp = PCP()
pcp.pcp_connect('remote_ip', 9898, 'postgres', 'secret')
result = pcp.pcp_node_count()
if result and pcp.PCPResultStatus(result) == ResultStateType.COMMAND_OK:
print('Node Count : ', result.pcp_get_data(0))
pcp.pcp_disconnect()
Result
$ Node Count : 2
JSON support
You can also get results for each command in JSON format.
print(result.pcp_get_json_data(0))
Result:
$ {'command_status': 'success', 'node_count': 2}
PCP CLI
At the moment there around 13 pcp_* utilities are being built along with Pgpool-II. By the time we add more features/commands in PCP, number of these utilities will increase.
PCP CLI combines functionality of all those utilities in a single utility. Same as Azure, Github CLIs, pcp_cli provide groups and sub-groups of command based on relevancy.
Following example show ‘pcp_cli node count’:
$ pcp_cli node count -U postgres -H pgpool_host -v
Password:
Node Count
____________
2
Following is the list of pcp_cli commands & sub-commands:
pcp_cli pool status
pcp_cli pool stop
pcp_cli pool reload-config
pcp_cli pool check-health-stats
pcp_cli node count
pcp_cli node info
pcp_cli node attach
pcp_cli node detach
pcp_cli node promote
pcp_cli node recovery
pcp_cli process count
pcp_cli process info
pcp_cli watchdog info
Conclusion
PyPCP and PCP_CLI will provide users freedom to develop applications and website across platforms for management and monitoring PgPool-II cluster.
PyPCP is open source and can be found at following github repository.