postgresql/src/bin
Tom Lane e652273e07 Redesign handling of SIGTERM/control-C in parallel pg_dump/pg_restore.
Formerly, Unix builds of pg_dump/pg_restore would trap SIGINT and similar
signals and set a flag that was tested in various data-transfer loops.
This was prone to errors of omission (cf commit 3c8aa6654); and even if
the client-side response was prompt, we did nothing that would cause
long-running SQL commands (e.g. CREATE INDEX) to terminate early.
Also, the master process would effectively do nothing at all upon receipt
of SIGINT; the only reason it seemed to work was that in typical scenarios
the signal would also be delivered to the child processes.  We should
support termination when a signal is delivered only to the master process,
though.

Windows builds had no console interrupt handler, so they would just fall
over immediately at control-C, again leaving long-running SQL commands to
finish unmolested.

To fix, remove the flag-checking approach altogether.  Instead, allow the
Unix signal handler to send a cancel request directly and then exit(1).
In the master process, also have it forward the signal to the children.
On Windows, add a console interrupt handler that behaves approximately
the same.  The main difference is that a single execution of the Windows
handler can send all the cancel requests since all the info is available
in one process, whereas on Unix each process sends a cancel only for its
own database connection.

In passing, fix an old problem that DisconnectDatabase tends to send a
cancel request before exiting a parallel worker, even if nothing went
wrong.  This is at least a waste of cycles, and could lead to unexpected
log messages, or maybe even data loss if it happened in pg_restore (though
in the current code the problem seems to affect only pg_dump).  The cause
was that after a COPY step, pg_dump was leaving libpq in PGASYNC_BUSY
state, causing PQtransactionStatus() to report PQTRANS_ACTIVE.  That's
normally harmless because the next PQexec() will silently clear the
PGASYNC_BUSY state; but in a parallel worker we might exit without any
additional SQL commands after a COPY step.  So add an extra PQgetResult()
call after a COPY to allow libpq to return to PGASYNC_IDLE state.

This is a bug fix, IMO, so back-patch to 9.3 where parallel dump/restore
were introduced.

Thanks to Kyotaro Horiguchi for Windows testing and code suggestions.

Original-Patch: <7005.1464657274@sss.pgh.pa.us>
Discussion: <20160602.174941.256342236.horiguchi.kyotaro@lab.ntt.co.jp>
2016-06-02 13:28:17 -04:00
..
initdb Fix typo in TAP test identification string. 2016-05-23 20:04:27 -04:00
pg_archivecleanup Make WAL-related utilities handle .partial WAL files properly. 2015-07-03 11:53:58 +09:00
pg_basebackup Translation updates 2016-05-09 10:04:41 -04:00
pg_config Translation updates 2016-05-09 10:04:41 -04:00
pg_controldata Translation updates 2016-05-09 10:04:41 -04:00
pg_ctl Translation updates 2016-05-09 10:04:41 -04:00
pg_dump Redesign handling of SIGTERM/control-C in parallel pg_dump/pg_restore. 2016-06-02 13:28:17 -04:00
pg_resetxlog Translation updates 2016-05-09 10:04:41 -04:00
pg_rewind Translation updates 2016-05-09 10:04:41 -04:00
pg_test_fsync Move pg_test_fsync from contrib/ to src/bin/ 2015-04-19 22:20:49 -04:00
pg_test_timing Move pg_test_timing from contrib/ to src/bin/ 2015-04-20 21:30:12 -04:00
pg_upgrade Fix pg_upgrade to not fail when new-cluster TOAST rules differ from old. 2016-05-06 22:05:56 -04:00
pg_xlogdump Generic Messages for Logical Decoding 2016-04-06 10:05:41 +01:00
pgbench Fix pgbench's parsing of double values to notice trailing garbage. 2016-05-06 11:08:48 -04:00
pgevent Update copyright for 2016 2016-01-02 13:33:40 -05:00
psql psql: Message style improvements 2016-05-21 22:17:00 -04:00
scripts Translation updates 2016-05-09 10:04:41 -04:00
Makefile Update copyright for 2016 2016-01-02 13:33:40 -05:00