2 * $Header: /cvsroot/pgpool/pgpool-II/pcp/pcp_node_info.c,v 1.3 2008/12/31 10:25:40 t-ishii Exp $
4 * pgpool: a language independent connection pool server for PostgreSQL
5 * written by Tatsuo Ishii
7 * Copyright (c) 2003-2008 PgPool Global Development Group
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose and without fee is hereby
11 * granted, provided that the above copyright notice appear in all
12 * copies and that both that copyright notice and this permission
13 * notice appear in supporting documentation, and that the name of the
14 * author not be used in advertising or publicity pertaining to
15 * distribution of the software without specific, written prior
16 * permission. The author makes no representations about the
17 * suitability of this software for any purpose. It is provided "as
18 * is" without express or implied warranty.
20 * Client program to send "node info" command.
30 static void usage(void);
31 static void myexit(ErrorCode e);
34 main(int argc, char **argv)
37 char host[MAX_DB_HOST_NAMELEN];
39 char user[MAX_USER_PASSWD_LEN];
40 char pass[MAX_USER_PASSWD_LEN];
42 BackendInfo *backend_info;
45 while ((ch = getopt(argc, argv, "hd")) != -1) {
64 pcp_errorstr(errorcode);
68 timeout = atol(argv[0]);
71 pcp_errorstr(errorcode);
75 if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN)
78 pcp_errorstr(errorcode);
81 strcpy(host, argv[1]);
84 if (port <= 1024 || port > 65535)
87 pcp_errorstr(errorcode);
91 if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN)
94 pcp_errorstr(errorcode);
97 strcpy(user, argv[3]);
99 if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN)
101 errorcode = INVALERR;
102 pcp_errorstr(errorcode);
105 strcpy(pass, argv[4]);
107 nodeID = atoi(argv[5]);
108 if (nodeID < 0 || nodeID > MAX_NUM_BACKENDS)
110 errorcode = INVALERR;
111 pcp_errorstr(errorcode);
115 pcp_set_timeout(timeout);
117 if (pcp_connect(host, port, user, pass))
119 pcp_errorstr(errorcode);
123 if ((backend_info = pcp_node_info(nodeID)) == NULL)
125 pcp_errorstr(errorcode);
129 printf("%s %d %d %f\n",
130 backend_info->backend_hostname,
131 backend_info->backend_port,
132 backend_info->backend_status,
133 backend_info->backend_weight);
146 fprintf(stderr, "pcp_node_info - display a pgpool-II node's information\n\n");
147 fprintf(stderr, "Usage: pcp_node_info [-d] timeout hostname port# username password nodeID\n");
148 fprintf(stderr, "Usage: pcp_node_info -h\n\n");
149 fprintf(stderr, " -d - enable debug message (optional)\n");
150 fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n");
151 fprintf(stderr, " hostname - pgpool-II hostname\n");
152 fprintf(stderr, " port# - pgpool-II port number\n");
153 fprintf(stderr, " username - username for PCP authentication\n");
154 fprintf(stderr, " password - password for PCP authentication\n");
155 fprintf(stderr, " nodeID - ID of a node to get information for\n");
156 fprintf(stderr, " -h - print this help\n");