PostgreSQL Source Code: src/bin/scripts/clusterdb.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

19

20

25 bool quiet);

27

28

29int

30main(int argc, char *argv[])

31{

32 static struct option long_options[] = {

45 {NULL, 0, NULL, 0}

46 };

47

49 int optindex;

50 int c;

51

52 const char *dbname = NULL;

53 const char *maintenance_db = NULL;

54 char *host = NULL;

55 char *port = NULL;

59 bool echo = false;

60 bool quiet = false;

61 bool alldb = false;

64

68

70

71 while ((c = getopt_long(argc, argv, "ad:eh:p:qt:U:vwW", long_options, &optindex)) != -1)

72 {

73 switch (c)

74 {

75 case 'a':

76 alldb = true;

77 break;

78 case 'd':

80 break;

81 case 'e':

82 echo = true;

83 break;

84 case 'h':

86 break;

87 case 'p':

89 break;

90 case 'q':

91 quiet = true;

92 break;

93 case 't':

95 break;

96 case 'U':

98 break;

99 case 'v':

101 break;

102 case 'w':

103 prompt_password = TRI_NO;

104 break;

105 case 'W':

106 prompt_password = TRI_YES;

107 break;

108 case 2:

110 break;

111 default:

112

114 exit(1);

115 }

116 }

117

118

119

120

121

123 {

126 }

127

129 {

130 pg_log_error("too many command-line arguments (first is \"%s\")",

133 exit(1);

134 }

135

136

137 cparams.pghost = host;

142

144

145 if (alldb)

146 {

148 pg_fatal("cannot cluster all databases and a specific one at the same time");

149

150 cparams.dbname = maintenance_db;

151

154 }

155 else

156 {

158 {

159 if (getenv("PGDATABASE"))

160 dbname = getenv("PGDATABASE");

161 else if (getenv("PGUSER"))

162 dbname = getenv("PGUSER");

163 else

165 }

166

168

169 if (tables.head != NULL)

170 {

172

173 for (cell = tables.head; cell; cell = cell->next)

174 {

177 }

178 }

179 else

182 }

183

184 exit(0);

185}

186

187

188static void

191{

193

195

197

199

204 {

207 }

209

211 {

213 pg_log_error("clustering of table \"%s\" in database \"%s\" failed: %s",

215 else

216 pg_log_error("clustering of database \"%s\" failed: %s",

219 exit(1);

220 }

223}

224

225

226static void

229 bool quiet)

230{

233 int i;

234

237 "SELECT datname FROM pg_database WHERE datallowconn AND datconnlimit <> -2 ORDER BY 1;",

238 echo);

240

242 {

244

245 if (!quiet)

246 {

249 }

250

252

253 if (tables->head != NULL)

254 {

256

257 for (cell = tables->head; cell; cell = cell->next)

260 }

261 else

264 }

265

267}

268

269

270static void

272{

273 printf(_("%s clusters all previously clustered tables in a database.\n\n"), progname);

276 printf(_("\nOptions:\n"));

277 printf(_(" -a, --all cluster all databases\n"));

278 printf(_(" -d, --dbname=DBNAME database to cluster\n"));

279 printf(_(" -e, --echo show the commands being sent to the server\n"));

280 printf(_(" -q, --quiet don't write any messages\n"));

281 printf(_(" -t, --table=TABLE cluster specific table(s) only\n"));

282 printf(_(" -v, --verbose write a lot of output\n"));

283 printf(_(" -V, --version output version information, then exit\n"));

284 printf(_(" -?, --help show this help, then exit\n"));

285 printf(_("\nConnection options:\n"));

286 printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));

287 printf(_(" -p, --port=PORT database server port\n"));

288 printf(_(" -U, --username=USERNAME user name to connect as\n"));

289 printf(_(" -w, --no-password never prompt for password\n"));

290 printf(_(" -W, --password force password prompt\n"));

291 printf(_(" --maintenance-db=DBNAME alternate maintenance database\n"));

292 printf(_("\nRead the description of the SQL command CLUSTER for details.\n"));

293 printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);

294 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);

295}

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)

PGconn * connectDatabase(const ConnParams *cparams, const char *progname, bool echo, bool fail_ok, bool allow_password_reuse)

PGresult * executeQuery(PGconn *conn, const char *query)

char * PQdb(const PGconn *conn)

void PQfinish(PGconn *conn)

char * PQerrorMessage(const PGconn *conn)

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

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)

PGDLLIMPORT char * optarg

static const struct lconv_member_info table[]

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)