2 * $Header: /cvsroot/pgpool/pgpool-II/pcp/pcp_systemdb_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 "systemDB 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];
41 SystemDBInfo *systemdb_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 if (pcp_connect(host, port, user, pass))
109 pcp_errorstr(errorcode);
113 if ((systemdb_info = pcp_systemdb_info()) == NULL)
115 pcp_errorstr(errorcode);
119 printf("%s %d %s %s %s %s %d %d\n",
120 systemdb_info->hostname,
123 systemdb_info->password[0] == '\0' ? "''" : systemdb_info->password,
124 systemdb_info->schema_name,
125 systemdb_info->database_name,
126 systemdb_info->dist_def_num,
127 systemdb_info->system_db_status);
129 for (i = 0; i < systemdb_info->dist_def_num; i++)
131 DistDefInfo *ddi = &systemdb_info->dist_def_slot[i];
133 printf("%s %s %s %s %d ",
137 ddi->dist_key_col_name,
140 for (j = 0; j < ddi->col_num; j++)
141 printf("%s ", ddi->col_list[j]);
143 for (j = 0; j < ddi->col_num; j++)
144 printf("%s ", ddi->type_list[j]);
146 printf("%s\n", ddi->dist_def_func);
149 free_systemdb_info(systemdb_info);
160 fprintf(stderr, "pcp_systemdb_info - display the pgpool-II systemDB information\n\n");
161 fprintf(stderr, "Usage: pcp_systemdb_info [-d] timeout hostname port# username password\n");
162 fprintf(stderr, "Usage: pcp_systemdb_info -h\n\n");
163 fprintf(stderr, " -d - enable debug message (optional)\n");
164 fprintf(stderr, " timeout - connection timeout value in seconds. command exits on timeout\n");
165 fprintf(stderr, " hostname - pgpool-II hostname\n");
166 fprintf(stderr, " port# - pgpool-II port number\n");
167 fprintf(stderr, " username - username for PCP authentication\n");
168 fprintf(stderr, " password - password for PCP authentication\n");
169 fprintf(stderr, " -h - print this help\n");