static void reindex_system_catalogs(const char *dbname, const char *host, const char *port, const char *username, enum trivalue prompt_password, const char *progname, bool echo) { PQExpBufferData sql; PGconn *conn; initPQExpBuffer(&sql); appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;\n", dbname); conn = connectDatabase(dbname, host, port, username, prompt_password, progname, false); if (!executeMaintenanceCommand(conn, sql.data, echo)) { fprintf(stderr, _("%s: reindexing of system catalogs failed: %s"), progname, PQerrorMessage(conn)); PQfinish(conn); exit(1); } PQfinish(conn); termPQExpBuffer(&sql); }
/* * Execute a vacuum/analyze command to the server. * * Result status is checked only if 'async' is false. */ static void run_vacuum_command(PGconn *conn, const char *sql, bool echo, const char *dbname, const char *table, const char *progname, bool async) { if (async) { if (echo) printf("%s\n", sql); PQsendQuery(conn, sql); } else if (!executeMaintenanceCommand(conn, sql, echo)) { if (table) fprintf(stderr, _("%s: vacuuming of table \"%s\" in database \"%s\" failed: %s"), progname, table, dbname, PQerrorMessage(conn)); else fprintf(stderr, _("%s: vacuuming of database \"%s\" failed: %s"), progname, dbname, PQerrorMessage(conn)); PQfinish(conn); exit(1); } }
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; initPQExpBuffer(&sql); appendPQExpBuffer(&sql, "CLUSTER"); if (verbose) appendPQExpBuffer(&sql, " VERBOSE"); if (table) appendPQExpBuffer(&sql, " %s", table); appendPQExpBuffer(&sql, ";\n"); conn = connectDatabase(dbname, host, port, username, prompt_password, progname, false); if (!executeMaintenanceCommand(conn, sql.data, echo)) { if (table) fprintf(stderr, _("%s: clustering of table \"%s\" in database \"%s\" failed: %s"), progname, table, dbname, PQerrorMessage(conn)); else fprintf(stderr, _("%s: clustering of database \"%s\" failed: %s"), progname, dbname, PQerrorMessage(conn)); PQfinish(conn); exit(1); } PQfinish(conn); termPQExpBuffer(&sql); }
static void reindex_one_database(const char *name, const char *dbname, const char *type, const char *host, const char *port, const char *username, enum trivalue prompt_password, const char *progname, bool echo, bool verbose) { PQExpBufferData sql; PGconn *conn; initPQExpBuffer(&sql); appendPQExpBufferStr(&sql, "REINDEX"); if (verbose) appendPQExpBufferStr(&sql, " (VERBOSE)"); if (strcmp(type, "TABLE") == 0) appendPQExpBuffer(&sql, " TABLE %s", name); else if (strcmp(type, "INDEX") == 0) appendPQExpBuffer(&sql, " INDEX %s", name); else if (strcmp(type, "SCHEMA") == 0) appendPQExpBuffer(&sql, " SCHEMA %s", name); else if (strcmp(type, "DATABASE") == 0) appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name)); appendPQExpBufferChar(&sql, ';'); conn = connectDatabase(dbname, host, port, username, prompt_password, progname, false, false); if (!executeMaintenanceCommand(conn, sql.data, echo)) { if (strcmp(type, "TABLE") == 0) fprintf(stderr, _("%s: reindexing of table \"%s\" in database \"%s\" failed: %s"), progname, name, dbname, PQerrorMessage(conn)); if (strcmp(type, "INDEX") == 0) fprintf(stderr, _("%s: reindexing of index \"%s\" in database \"%s\" failed: %s"), progname, name, dbname, PQerrorMessage(conn)); if (strcmp(type, "SCHEMA") == 0) fprintf(stderr, _("%s: reindexing of schema \"%s\" in database \"%s\" failed: %s"), progname, name, dbname, PQerrorMessage(conn)); else fprintf(stderr, _("%s: reindexing of database \"%s\" failed: %s"), progname, dbname, PQerrorMessage(conn)); PQfinish(conn); exit(1); } PQfinish(conn); termPQExpBuffer(&sql); }
static void vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze, bool freeze, 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; initPQExpBuffer(&sql); appendPQExpBuffer(&sql, "VACUUM"); if (full) appendPQExpBuffer(&sql, " FULL"); if (verbose) appendPQExpBuffer(&sql, " VERBOSE"); if (freeze) appendPQExpBuffer(&sql, " FREEZE"); if (analyze) appendPQExpBuffer(&sql, " ANALYZE"); if (table) appendPQExpBuffer(&sql, " %s", table); appendPQExpBuffer(&sql, ";\n"); conn = connectDatabase(dbname, host, port, username, prompt_password, progname); if (!executeMaintenanceCommand(conn, sql.data, echo)) { if (table) fprintf(stderr, _("%s: vacuuming of table \"%s\" in database \"%s\" failed: %s"), progname, table, dbname, PQerrorMessage(conn)); else fprintf(stderr, _("%s: vacuuming of database \"%s\" failed: %s"), progname, dbname, PQerrorMessage(conn)); PQfinish(conn); exit(1); } PQfinish(conn); termPQExpBuffer(&sql); }
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, 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) pg_log_error("clustering of table \"%s\" in database \"%s\" failed: %s", table, PQdb(conn), PQerrorMessage(conn)); else pg_log_error("clustering of database \"%s\" failed: %s", PQdb(conn), PQerrorMessage(conn)); PQfinish(conn); exit(1); } PQfinish(conn); termPQExpBuffer(&sql); }
static void vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyze, bool analyze_only, bool freeze, 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; initPQExpBuffer(&sql); conn = connectDatabase(dbname, host, port, username, prompt_password, progname, false); if (analyze_only) { appendPQExpBufferStr(&sql, "ANALYZE"); if (verbose) appendPQExpBufferStr(&sql, " VERBOSE"); } else { appendPQExpBufferStr(&sql, "VACUUM"); if (PQserverVersion(conn) >= 90000) { const char *paren = " ("; const char *comma = ", "; const char *sep = paren; if (full) { appendPQExpBuffer(&sql, "%sFULL", sep); sep = comma; } if (freeze) { appendPQExpBuffer(&sql, "%sFREEZE", sep); sep = comma; } if (verbose) { appendPQExpBuffer(&sql, "%sVERBOSE", sep); sep = comma; } if (and_analyze) { appendPQExpBuffer(&sql, "%sANALYZE", sep); sep = comma; } if (sep != paren) appendPQExpBufferStr(&sql, ")"); } else { if (full) appendPQExpBufferStr(&sql, " FULL"); if (freeze) appendPQExpBufferStr(&sql, " FREEZE"); if (verbose) appendPQExpBufferStr(&sql, " VERBOSE"); if (and_analyze) appendPQExpBufferStr(&sql, " ANALYZE"); } } if (table) appendPQExpBuffer(&sql, " %s", table); appendPQExpBufferStr(&sql, ";\n"); if (!executeMaintenanceCommand(conn, sql.data, echo)) { if (table) fprintf(stderr, _("%s: vacuuming of table \"%s\" in database \"%s\" failed: %s"), progname, table, dbname, PQerrorMessage(conn)); else fprintf(stderr, _("%s: vacuuming of database \"%s\" failed: %s"), progname, dbname, PQerrorMessage(conn)); PQfinish(conn); exit(1); } PQfinish(conn); termPQExpBuffer(&sql); }