31 main(
int argc,
char *argv[])
33 static struct option long_options[] = {
54 const char *maintenance_db = NULL;
72 while ((
c =
getopt_long(argc, argv,
"ad:eh:p:qt:U:vwW", long_options, &optindex)) != -1)
131 pg_log_error(
"too many command-line arguments (first is \"%s\")",
149 pg_fatal(
"cannot cluster all databases and a specific one at the same time");
151 cparams.
dbname = maintenance_db;
160 if (getenv(
"PGDATABASE"))
161 dbname = getenv(
"PGDATABASE");
162 else if (getenv(
"PGUSER"))
163 dbname = getenv(
"PGUSER");
170 if (tables.
head != NULL)
174 for (cell = tables.
head; cell; cell = cell->
next)
214 pg_log_error(
"clustering of table \"%s\" in database \"%s\" failed: %s",
217 pg_log_error(
"clustering of database \"%s\" failed: %s",
238 "SELECT datname FROM pg_database WHERE datallowconn AND datconnlimit <> -2 ORDER BY 1;",
254 if (tables->
head != NULL)
258 for (cell = tables->
head; cell; cell = cell->
next)
274 printf(
_(
"%s clusters all previously clustered tables in a database.\n\n"),
progname);
278 printf(
_(
" -a, --all cluster all databases\n"));
279 printf(
_(
" -d, --dbname=DBNAME database to cluster\n"));
280 printf(
_(
" -e, --echo show the commands being sent to the server\n"));
281 printf(
_(
" -q, --quiet don't write any messages\n"));
282 printf(
_(
" -t, --table=TABLE cluster specific table(s) only\n"));
283 printf(
_(
" -v, --verbose write a lot of output\n"));
284 printf(
_(
" -V, --version output version information, then exit\n"));
285 printf(
_(
" -?, --help show this help, then exit\n"));
286 printf(
_(
"\nConnection options:\n"));
287 printf(
_(
" -h, --host=HOSTNAME database server host or socket directory\n"));
288 printf(
_(
" -p, --port=PORT database server port\n"));
289 printf(
_(
" -U, --username=USERNAME user name to connect as\n"));
290 printf(
_(
" -w, --no-password never prompt for password\n"));
291 printf(
_(
" -W, --password force password prompt\n"));
292 printf(
_(
" --maintenance-db=DBNAME alternate maintenance database\n"));
293 printf(
_(
"\nRead the description of the SQL command CLUSTER for details.\n"));
294 printf(
_(
"\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
295 printf(
_(
"%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
void appendQualifiedRelation(PQExpBuffer buf, const char *spec, PGconn *conn, bool echo)
#define PG_TEXTDOMAIN(domain)
void setup_cancel_handler(void(*query_cancel_callback)(void))
int main(int argc, char *argv[])
static void cluster_all_databases(ConnParams *cparams, SimpleStringList *tables, const char *progname, bool verbose, bool echo, bool quiet)
static void help(const char *progname)
static void cluster_one_database(const ConnParams *cparams, const char *table, const char *progname, bool verbose, bool echo)
void set_pglocale_pgservice(const char *argv0, const char *app)
PGconn * connectMaintenanceDatabase(ConnParams *cparams, const char *progname, bool echo)
char * PQdb(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
void PQfinish(PGconn *conn)
int PQntuples(const PGresult *res)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
char * pg_strdup(const char *in)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
static void const char fflush(stdout)
void pg_logging_init(const char *argv0)
#define pg_log_error(...)
#define pg_log_error_hint(...)
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
static PGconn * connectDatabase(const char *dbname, const char *connection_string, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error)
static PGresult * executeQuery(PGconn *conn, const char *query)
PGDLLIMPORT char * optarg
const char * get_progname(const char *argv0)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
bool executeMaintenanceCommand(PGconn *conn, const char *query, bool echo)
void simple_string_list_append(SimpleStringList *list, const char *val)
char val[FLEXIBLE_ARRAY_MEMBER]
struct SimpleStringListCell * next
SimpleStringListCell * head
enum trivalue prompt_password
const char * get_user_name_or_exit(const char *progname)