pgsql: Improve connection-failure error handling in contrib/postgres_fd

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Improve connection-failure error handling in contrib/postgres_fd
Date: 2014-02-04 02:30:39
Message-ID: E1WAVmZ-0002P7-P5@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve connection-failure error handling in contrib/postgres_fdw.

postgres_fdw tended to say "unknown error" if it tried to execute a command
on an already-dead connection, because some paths in libpq just return a
null PGresult for such cases. Out-of-memory might result in that, too.
To fix, pass the PGconn to pgfdw_report_error, and look at its
PQerrorMessage() string if we can't get anything out of the PGresult.

Also, fix the transaction-exit logic to reliably drop a dead connection.
It was attempting to do that already, but it assumed that only connection
cache entries with xact_depth > 0 needed to be examined. The folly in that
is that if we fail while issuing START TRANSACTION, we'll not have bumped
xact_depth. (At least for the case I was testing, this fix masks the
other problem; but it still seems like a good idea to have the PGconn
fallback logic.)

Per investigation of bug #9087 from Craig Lucas. Backpatch to 9.3 where
this code was introduced.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/00d4f2af8bd6a1b9db2f676cc76b64d98ace99fb

Modified Files
--------------
contrib/postgres_fdw/connection.c | 155 +++++++++++++++++++----------------
contrib/postgres_fdw/postgres_fdw.c | 26 +++---
contrib/postgres_fdw/postgres_fdw.h | 4 +-
3 files changed, 100 insertions(+), 85 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2014-02-04 05:08:09 Re: Viability of text HISTORY/INSTALL/regression README files (was Re: [COMMITTERS] pgsql: Document a few more regression test hazards.)
Previous Message Fujii Masao 2014-02-04 02:05:32 Re: pgsql: Add pg_stat_archiver statistics view.