static void cluster_one_database(const char *dbname, bool verbose, const char *table, const char *host, const char *port, const char *username, enum trivalue prompt_password, const char *progname, bool echo) { PQExpBufferData sql; PGconn *conn; conn = connectDatabase(dbname, host, port, username, prompt_password, progname, echo, false); initPQExpBuffer(&sql); appendPQExpBufferStr(&sql, "CLUSTER"); if (verbose) appendPQExpBufferStr(&sql, " VERBOSE"); if (table) { appendPQExpBufferChar(&sql, ' '); appendQualifiedRelation(&sql, table, conn, progname, echo); } appendPQExpBufferChar(&sql, ';'); if (!executeMaintenanceCommand(conn, sql.data, echo)) { if (table) fprintf(stderr, _("%s: clustering of table \"%s\" in database \"%s\" failed: %s"), progname, table, PQdb(conn), PQerrorMessage(conn)); else fprintf(stderr, _("%s: clustering of database \"%s\" failed: %s"), progname, PQdb(conn), PQerrorMessage(conn)); PQfinish(conn); exit(1); } PQfinish(conn); termPQExpBuffer(&sql); }
/* * Construct a vacuum/analyze command to run based on the given options, in the * given string buffer, which may contain previous garbage. * * An optional table name can be passed; this must be already be properly * quoted. The command is semicolon-terminated. */ static void prepare_vacuum_command(PQExpBuffer sql, PGconn *conn, vacuumingOptions *vacopts, const char *table, bool table_pre_qualified, const char *progname, bool echo) { resetPQExpBuffer(sql); if (vacopts->analyze_only) { appendPQExpBufferStr(sql, "ANALYZE"); if (vacopts->verbose) appendPQExpBufferStr(sql, " VERBOSE"); } else { appendPQExpBufferStr(sql, "VACUUM"); if (PQserverVersion(conn) >= 90000) { const char *paren = " ("; const char *comma = ", "; const char *sep = paren; if (vacopts->full) { appendPQExpBuffer(sql, "%sFULL", sep); sep = comma; } if (vacopts->freeze) { appendPQExpBuffer(sql, "%sFREEZE", sep); sep = comma; } if (vacopts->verbose) { appendPQExpBuffer(sql, "%sVERBOSE", sep); sep = comma; } if (vacopts->and_analyze) { appendPQExpBuffer(sql, "%sANALYZE", sep); sep = comma; } if (sep != paren) appendPQExpBufferChar(sql, ')'); } else { if (vacopts->full) appendPQExpBufferStr(sql, " FULL"); if (vacopts->freeze) appendPQExpBufferStr(sql, " FREEZE"); if (vacopts->verbose) appendPQExpBufferStr(sql, " VERBOSE"); if (vacopts->and_analyze) appendPQExpBufferStr(sql, " ANALYZE"); } } if (table) { appendPQExpBufferChar(sql, ' '); if (table_pre_qualified) appendPQExpBufferStr(sql, table); else appendQualifiedRelation(sql, table, conn, progname, echo); } appendPQExpBufferChar(sql, ';'); }