vacuum-cli-suggestion.context.patch
text/x-patch
Filename: vacuum-cli-suggestion.context.patch
Type: text/x-patch
Part: 1
Message:
Re: New VACUUM FULL
Patch
Format: context
| File | + | − |
|---|---|---|
| src/bin/scripts/vacuumdb.c | 32 | 0 |
*** a/src/bin/scripts/vacuumdb.c
--- b/src/bin/scripts/vacuumdb.c
***************
*** 203,225 **** vacuum_one_database(const char *dbname, bool full, bool inplace, bool verbose,
PQExpBufferData sql;
PGconn *conn;
initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "VACUUM");
! if (inplace)
{
! appendPQExpBuffer(&sql, " (FULL INPLACE");
if (freeze)
! appendPQExpBuffer(&sql, ", FREEZE");
if (verbose)
! appendPQExpBuffer(&sql, ", VERBOSE");
if (analyze)
! appendPQExpBuffer(&sql, ", ANALYZE");
! appendPQExpBuffer(&sql, ")");
}
else
{
if (full)
appendPQExpBuffer(&sql, " FULL");
if (freeze)
--- 203,250 ----
PQExpBufferData sql;
PGconn *conn;
+ int version;
+ bool first_opt = true;
initPQExpBuffer(&sql);
+ conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
+ version = PQserverVersion(conn);
+
appendPQExpBuffer(&sql, "VACUUM");
!
! if (version >= 80500)
{
! if (full)
! {
! appendPQExpBuffer(&sql, "%sFULL%s", first_opt ? " (" : ", ",
! inplace ? " INPLACE" : "");
! first_opt = false;
! }
if (freeze)
! {
! appendPQExpBuffer(&sql, "%sFREEZE", first_opt ? " (" : ", ");
! first_opt = false;
! }
if (verbose)
! {
! appendPQExpBuffer(&sql, "%sVERBOSE", first_opt ? " (" : ", ");
! first_opt = false;
! }
if (analyze)
! {
! appendPQExpBuffer(&sql, "%sANALYZE", first_opt ? " (" : ", ");
! first_opt = false;
! }
! if (!first_opt)
! appendPQExpBuffer(&sql, ")");
}
else
{
+ /*
+ * On older servers, VACUUM FULL is equivalent to VACUUM (FULL
+ * INPLACE) on newer servers, so we can ignore 'inplace'.
+ */
if (full)
appendPQExpBuffer(&sql, " FULL");
if (freeze)
***************
*** 229,239 **** vacuum_one_database(const char *dbname, bool full, bool inplace, bool verbose,
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)
--- 254,264 ----
if (analyze)
appendPQExpBuffer(&sql, " ANALYZE");
}
+
if (table)
appendPQExpBuffer(&sql, " %s", table);
appendPQExpBuffer(&sql, ";\n");
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
if (table)