24 #include "catalog/pg_class_d.h"
53 static int vacuumlo(
const char *database,
const struct _param *param);
85 #define PARAMS_ARRAY_SIZE 7
96 keywords[3] =
"password";
98 keywords[4] =
"dbname";
100 keywords[5] =
"fallback_application_name";
109 pg_log_error(
"connection to database \"%s\" failed", database);
136 fprintf(
stdout,
"Test run: no large objects will be removed!\n");
153 strcat(
buf,
"CREATE TEMP TABLE vacuum_l AS ");
155 strcat(
buf,
"SELECT oid AS lo FROM pg_largeobject_metadata");
157 strcat(
buf,
"SELECT DISTINCT loid AS lo FROM pg_largeobject");
173 strcat(
buf,
"ANALYZE vacuum_l");
194 strcat(
buf,
"SELECT s.nspname, c.relname, a.attname ");
195 strcat(
buf,
"FROM pg_class c, pg_attribute a, pg_namespace s, pg_type t ");
196 strcat(
buf,
"WHERE a.attnum > 0 AND NOT a.attisdropped ");
197 strcat(
buf,
" AND a.attrelid = c.oid ");
198 strcat(
buf,
" AND a.atttypid = t.oid ");
199 strcat(
buf,
" AND c.relnamespace = s.oid ");
200 strcat(
buf,
" AND t.typname in ('oid', 'lo') ");
202 strcat(
buf,
" AND s.nspname !~ '^pg_'");
223 fprintf(
stdout,
"Checking %s in %s.%s\n", field, schema, table);
229 if (!schema || !table || !field)
241 "DELETE FROM vacuum_l "
242 "WHERE lo IN (SELECT %s FROM %s.%s)",
243 field, schema, table);
286 "DECLARE myportal CURSOR WITH HOLD FOR SELECT lo FROM vacuum_l");
321 for (
i = 0;
i < matched;
i++)
399 fprintf(
stdout,
"\rWould remove %ld large objects from database \"%s\".\n",
403 "\rSuccessfully removed %ld large objects from database \"%s\".\n",
406 fprintf(
stdout,
"\rRemoval from database \"%s\" failed at object %ld of %ld.\n",
407 database, deleted, matched);
416 printf(
"%s removes unreferenced large objects from databases.\n\n",
progname);
419 printf(
" -l, --limit=LIMIT commit after removing each LIMIT large objects\n");
420 printf(
" -n, --dry-run don't remove large objects, just show what would be done\n");
421 printf(
" -v, --verbose write a lot of progress messages\n");
422 printf(
" -V, --version output version information, then exit\n");
423 printf(
" -?, --help show this help, then exit\n");
424 printf(
"\nConnection options:\n");
425 printf(
" -h, --host=HOSTNAME database server host or socket directory\n");
426 printf(
" -p, --port=PORT database server port\n");
427 printf(
" -U, --username=USERNAME user name to connect as\n");
428 printf(
" -w, --no-password never prompt for password\n");
429 printf(
" -W, --password force password prompt\n");
431 printf(
"Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
432 printf(
"%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
439 static struct option long_options[] = {
476 if (strcmp(argv[1],
"--help") == 0 || strcmp(argv[1],
"-?") == 0)
481 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
483 puts(
"vacuumlo (PostgreSQL) " PG_VERSION);
488 while ((
c =
getopt_long(argc, argv,
"h:l:np:U:vwW", long_options, &optindex)) != -1)
498 pg_fatal(
"transaction limit must not be negative (0 disables)");
532 pg_log_error(
"missing required argument: database name");
static Datum values[MAXATTR]
#define ALWAYS_SECURE_SEARCH_PATH_SQL
static void PGresult * res
int PQserverVersion(const PGconn *conn)
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
int PQconnectionNeedsPassword(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
void PQfinish(PGconn *conn)
void PQfreemem(void *ptr)
char * PQescapeIdentifier(PGconn *conn, const char *str, size_t len)
ExecStatusType PQresultStatus(const PGresult *res)
int PQntuples(const PGresult *res)
PGresult * PQexec(PGconn *conn, const char *query)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
int lo_unlink(PGconn *conn, Oid lobjId)
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(...)
PGDLLIMPORT char * optarg
const char * get_progname(const char *argv0)
char * simple_prompt(const char *prompt, bool echo)
static void usage(const char *progname)
int main(int argc, char **argv)
#define PARAMS_ARRAY_SIZE
static int vacuumlo(const char *database, const struct _param *param)