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

Commit a179232

Browse files
committed
vacuumdb: enable parallel mode
This mode allows vacuumdb to open several server connections to vacuum or analyze several tables simultaneously. Author: Dilip Kumar. Some reworking by Álvaro Herrera Reviewed by: Jeff Janes, Amit Kapila, Magnus Hagander, Andres Freund
1 parent 5cefbf5 commit a179232

File tree

5 files changed

+691
-161
lines changed

5 files changed

+691
-161
lines changed

doc/src/sgml/ref/vacuumdb.sgml

+24
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,30 @@ PostgreSQL documentation
203203
</listitem>
204204
</varlistentry>
205205

206+
<varlistentry>
207+
<term><option>-j <replaceable class="parameter">njobs</replaceable></option></term>
208+
<term><option>--jobs=<replaceable class="parameter">njobs</replaceable></option></term>
209+
<listitem>
210+
<para>
211+
Execute the vacuum or analyze commands in parallel by running
212+
<replaceable class="parameter">njobs</replaceable>
213+
commands simultaneously. This option reduces the time of the
214+
processing but it also increases the load on the database server.
215+
</para>
216+
<para>
217+
<application>vacuumdb</application> will open
218+
<replaceable class="parameter">njobs</replaceable> connections to the
219+
database, so make sure your <xref linkend="guc-max-connections">
220+
setting is high enough to accommodate all connections.
221+
</para>
222+
<para>
223+
Note that using this mode together with the <option>-f</option>
224+
(<literal>FULL</literal>) option might cause deadlock failures if
225+
certain system catalogs are processed in parallel.
226+
</para>
227+
</listitem>
228+
</varlistentry>
229+
206230
<varlistentry>
207231
<term><option>--analyze-in-stages</option></term>
208232
<listitem>

src/bin/pg_dump/parallel.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ select_loop(int maxFd, fd_set *workerset)
11601160
i = select(maxFd + 1, workerset, NULL, NULL, NULL);
11611161

11621162
/*
1163-
* If we Ctrl-C the master process , it's likely that we interrupt
1163+
* If we Ctrl-C the master process, it's likely that we interrupt
11641164
* select() here. The signal handler will set wantAbort == true and
11651165
* the shutdown journey starts from here. Note that we'll come back
11661166
* here later when we tell all workers to terminate and read their

src/bin/scripts/common.c

+16-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
#include "common.h"
2121

22-
static void SetCancelConn(PGconn *conn);
23-
static void ResetCancelConn(void);
2422

2523
static PGcancel *volatile cancelConn = NULL;
24+
bool CancelRequested = false;
2625

2726
#ifdef WIN32
2827
static CRITICAL_SECTION cancelConnLock;
@@ -291,7 +290,7 @@ yesno_prompt(const char *question)
291290
*
292291
* Set cancelConn to point to the current database connection.
293292
*/
294-
static void
293+
void
295294
SetCancelConn(PGconn *conn)
296295
{
297296
PGcancel *oldCancelConn;
@@ -321,7 +320,7 @@ SetCancelConn(PGconn *conn)
321320
*
322321
* Free the current cancel connection, if any, and set to NULL.
323322
*/
324-
static void
323+
void
325324
ResetCancelConn(void)
326325
{
327326
PGcancel *oldCancelConn;
@@ -345,9 +344,8 @@ ResetCancelConn(void)
345344

346345
#ifndef WIN32
347346
/*
348-
* Handle interrupt signals by canceling the current command,
349-
* if it's being executed through executeMaintenanceCommand(),
350-
* and thus has a cancelConn set.
347+
* Handle interrupt signals by canceling the current command, if a cancelConn
348+
* is set.
351349
*/
352350
static void
353351
handle_sigint(SIGNAL_ARGS)
@@ -359,10 +357,15 @@ handle_sigint(SIGNAL_ARGS)
359357
if (cancelConn != NULL)
360358
{
361359
if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
360+
{
361+
CancelRequested = true;
362362
fprintf(stderr, _("Cancel request sent\n"));
363+
}
363364
else
364365
fprintf(stderr, _("Could not send cancel request: %s"), errbuf);
365366
}
367+
else
368+
CancelRequested = true;
366369

367370
errno = save_errno; /* just in case the write changed it */
368371
}
@@ -392,10 +395,16 @@ consoleHandler(DWORD dwCtrlType)
392395
if (cancelConn != NULL)
393396
{
394397
if (PQcancel(cancelConn, errbuf, sizeof(errbuf)))
398+
{
395399
fprintf(stderr, _("Cancel request sent\n"));
400+
CancelRequested = true;
401+
}
396402
else
397403
fprintf(stderr, _("Could not send cancel request: %s"), errbuf);
398404
}
405+
else
406+
CancelRequested = true;
407+
399408
LeaveCriticalSection(&cancelConnLock);
400409

401410
return TRUE;

src/bin/scripts/common.h

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ enum trivalue
2121
TRI_YES
2222
};
2323

24+
extern bool CancelRequested;
25+
2426
typedef void (*help_handler) (const char *progname);
2527

2628
extern void handle_help_version_opts(int argc, char *argv[],
@@ -49,4 +51,8 @@ extern bool yesno_prompt(const char *question);
4951

5052
extern void setup_cancel_handler(void);
5153

54+
extern void SetCancelConn(PGconn *conn);
55+
extern void ResetCancelConn(void);
56+
57+
5258
#endif /* COMMON_H */

0 commit comments

Comments
 (0)