Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3ccb97b

Browse files
committed
pg_dump --only-analyze
Implement pg_dump --only-analyze for use by pg_migrator to only analyze all databases.
1 parent 8cdb85b commit 3ccb97b

File tree

2 files changed

+81
-37
lines changed

2 files changed

+81
-37
lines changed

doc/src/sgml/ref/vacuumdb.sgml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.45 2009/11/27 17:41:26 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/vacuumdb.sgml,v 1.46 2010/01/06 02:59:44 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -24,9 +24,10 @@ PostgreSQL documentation
2424
<command>vacuumdb</command>
2525
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
2626
<group><arg>--full</arg><arg>-f</arg></group>
27+
<group><arg>--freeze</arg><arg>-F</arg></group>
2728
<group><arg>--verbose</arg><arg>-v</arg></group>
2829
<group><arg>--analyze</arg><arg>-z</arg></group>
29-
<group><arg>--freeze</arg><arg>-F</arg></group>
30+
<group><arg>--only-analyze</arg><arg>-o</arg></group>
3031
<arg>--table | -t <replaceable>table</replaceable>
3132
<arg>( <replaceable class="parameter">column</replaceable> [,...] )</arg>
3233
</arg>
@@ -36,9 +37,10 @@ PostgreSQL documentation
3637
<arg rep="repeat"><replaceable>connection-options</replaceable></arg>
3738
<group><arg>--all</arg><arg>-a</arg></group>
3839
<group><arg>--full</arg><arg>-f</arg></group>
40+
<group><arg>--freeze</arg><arg>-F</arg></group>
3941
<group><arg>--verbose</arg><arg>-v</arg></group>
4042
<group><arg>--analyze</arg><arg>-z</arg></group>
41-
<group><arg>--freeze</arg><arg>-F</arg></group>
43+
<group><arg>--only-analyze</arg><arg>-o</arg></group>
4244
</cmdsynopsis>
4345
</refsynopsisdiv>
4446

@@ -56,8 +58,9 @@ PostgreSQL documentation
5658
<para>
5759
<application>vacuumdb</application> is a wrapper around the SQL
5860
command <xref linkend="SQL-VACUUM" endterm="SQL-VACUUM-title">.
59-
There is no effective difference between vacuuming databases via
60-
this utility and via other methods for accessing the server.
61+
There is no effective difference between vacuuming and analyzing
62+
databases via this utility and via other methods for accessing the
63+
server.
6164
</para>
6265

6366
</refsect1>
@@ -116,6 +119,26 @@ PostgreSQL documentation
116119
</listitem>
117120
</varlistentry>
118121

122+
<varlistentry>
123+
<term><option>-F</option></term>
124+
<term><option>--freeze</option></term>
125+
<listitem>
126+
<para>
127+
Aggressively <quote>freeze</quote> tuples.
128+
</para>
129+
</listitem>
130+
</varlistentry>
131+
132+
<varlistentry>
133+
<term><option>-o</option></term>
134+
<term><option>--only-analyze</option></term>
135+
<listitem>
136+
<para>
137+
Only calculate statistics for use by the optimizer (no vacuum).
138+
</para>
139+
</listitem>
140+
</varlistentry>
141+
119142
<varlistentry>
120143
<term><option>-q</></term>
121144
<term><option>--quiet</></term>
@@ -133,7 +156,7 @@ PostgreSQL documentation
133156
<para>
134157
Clean or analyze <replaceable class="parameter">table</replaceable> only.
135158
Column names can be specified only in conjunction with
136-
the <option>--analyze</option> option.
159+
the <option>--analyze</option> or <option>--only-analyze</option> options.
137160
</para>
138161
<tip>
139162
<para>
@@ -164,15 +187,6 @@ PostgreSQL documentation
164187
</listitem>
165188
</varlistentry>
166189

167-
<varlistentry>
168-
<term><option>-F</option></term>
169-
<term><option>--freeze</option></term>
170-
<listitem>
171-
<para>
172-
Aggressively <quote>freeze</quote> tuples.
173-
</para>
174-
</listitem>
175-
</varlistentry>
176190
</variablelist>
177191
</para>
178192

src/bin/scripts/vacuumdb.c

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.28 2010/01/02 16:58:00 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.29 2010/01/06 02:59:46 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -14,12 +14,13 @@
1414
#include "common.h"
1515

1616

17-
static void vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
18-
bool freeze, const char *table,
19-
const char *host, const char *port,
17+
static void vacuum_one_database(const char *dbname, bool full, bool verbose,
18+
bool and_analyze, bool only_analyze, bool freeze,
19+
const char *table, const char *host, const char *port,
2020
const char *username, enum trivalue prompt_password,
2121
const char *progname, bool echo);
22-
static void vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
22+
static void vacuum_all_databases(bool full, bool verbose, bool and_analyze,
23+
bool only_analyze, bool freeze,
2324
const char *host, const char *port,
2425
const char *username, enum trivalue prompt_password,
2526
const char *progname, bool echo, bool quiet);
@@ -40,6 +41,7 @@ main(int argc, char *argv[])
4041
{"quiet", no_argument, NULL, 'q'},
4142
{"dbname", required_argument, NULL, 'd'},
4243
{"analyze", no_argument, NULL, 'z'},
44+
{"only-analyze", no_argument, NULL, 'o'},
4345
{"freeze", no_argument, NULL, 'F'},
4446
{"all", no_argument, NULL, 'a'},
4547
{"table", required_argument, NULL, 't'},
@@ -59,7 +61,8 @@ main(int argc, char *argv[])
5961
enum trivalue prompt_password = TRI_DEFAULT;
6062
bool echo = false;
6163
bool quiet = false;
62-
bool analyze = false;
64+
bool and_analyze = false;
65+
bool only_analyze = false;
6366
bool freeze = false;
6467
bool alldb = false;
6568
char *table = NULL;
@@ -100,7 +103,10 @@ main(int argc, char *argv[])
100103
dbname = optarg;
101104
break;
102105
case 'z':
103-
analyze = true;
106+
and_analyze = true;
107+
break;
108+
case 'o':
109+
only_analyze = true;
104110
break;
105111
case 'F':
106112
freeze = true;
@@ -139,6 +145,23 @@ main(int argc, char *argv[])
139145

140146
setup_cancel_handler();
141147

148+
if (only_analyze)
149+
{
150+
if (full)
151+
{
152+
fprintf(stderr, _("%s: cannot use the \"full\" option when performing only analyze\n"),
153+
progname);
154+
exit(1);
155+
}
156+
if (freeze)
157+
{
158+
fprintf(stderr, _("%s: cannot use the \"freeze\" option when performing only analyze\n"),
159+
progname);
160+
exit(1);
161+
}
162+
/* ignore 'and_analyze' */
163+
}
164+
142165
if (alldb)
143166
{
144167
if (dbname)
@@ -154,7 +177,7 @@ main(int argc, char *argv[])
154177
exit(1);
155178
}
156179

157-
vacuum_all_databases(full, verbose, analyze, freeze,
180+
vacuum_all_databases(full, verbose, and_analyze, only_analyze, freeze,
158181
host, port, username, prompt_password,
159182
progname, echo, quiet);
160183
}
@@ -170,7 +193,8 @@ main(int argc, char *argv[])
170193
dbname = get_user_name(progname);
171194
}
172195

173-
vacuum_one_database(dbname, full, verbose, analyze, freeze, table,
196+
vacuum_one_database(dbname, full, verbose, and_analyze, only_analyze,
197+
freeze, table,
174198
host, port, username, prompt_password,
175199
progname, echo);
176200
}
@@ -180,8 +204,8 @@ main(int argc, char *argv[])
180204

181205

182206
static void
183-
vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
184-
bool freeze, const char *table,
207+
vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyze,
208+
bool only_analyze, bool freeze, const char *table,
185209
const char *host, const char *port,
186210
const char *username, enum trivalue prompt_password,
187211
const char *progname, bool echo)
@@ -192,15 +216,20 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
192216

193217
initPQExpBuffer(&sql);
194218

195-
appendPQExpBuffer(&sql, "VACUUM");
196-
if (full)
197-
appendPQExpBuffer(&sql, " FULL");
198-
if (freeze)
199-
appendPQExpBuffer(&sql, " FREEZE");
219+
if (only_analyze)
220+
appendPQExpBuffer(&sql, "ANALYZE");
221+
else
222+
{
223+
appendPQExpBuffer(&sql, "VACUUM");
224+
if (full)
225+
appendPQExpBuffer(&sql, " FULL");
226+
if (freeze)
227+
appendPQExpBuffer(&sql, " FREEZE");
228+
if (and_analyze)
229+
appendPQExpBuffer(&sql, " ANALYZE");
230+
}
200231
if (verbose)
201232
appendPQExpBuffer(&sql, " VERBOSE");
202-
if (analyze)
203-
appendPQExpBuffer(&sql, " ANALYZE");
204233
if (table)
205234
appendPQExpBuffer(&sql, " %s", table);
206235
appendPQExpBuffer(&sql, ";\n");
@@ -223,8 +252,8 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool analyze,
223252

224253

225254
static void
226-
vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
227-
const char *host, const char *port,
255+
vacuum_all_databases(bool full, bool verbose, bool and_analyze, bool only_analyze,
256+
bool freeze, const char *host, const char *port,
228257
const char *username, enum trivalue prompt_password,
229258
const char *progname, bool echo, bool quiet)
230259
{
@@ -246,8 +275,8 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, bool freeze,
246275
fflush(stdout);
247276
}
248277

249-
vacuum_one_database(dbname, full, verbose, analyze, freeze, NULL,
250-
host, port, username, prompt_password,
278+
vacuum_one_database(dbname, full, verbose, and_analyze, only_analyze,
279+
freeze, NULL, host, port, username, prompt_password,
251280
progname, echo);
252281
}
253282

@@ -267,6 +296,7 @@ help(const char *progname)
267296
printf(_(" -e, --echo show the commands being sent to the server\n"));
268297
printf(_(" -f, --full do full vacuuming\n"));
269298
printf(_(" -F, --freeze freeze row transaction information\n"));
299+
printf(_(" -o, --only-analyze only update optimizer hints\n"));
270300
printf(_(" -q, --quiet don't write any messages\n"));
271301
printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table only\n"));
272302
printf(_(" -v, --verbose write a lot of output\n"));

0 commit comments

Comments
 (0)