diff options
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index e9be0f09fb2..88a804d5250 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -357,6 +357,8 @@ ReceiveCopyBegin(CopyState cstate) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("COPY BINARY is not supported to stdout or from stdin"))); pq_putemptymessage('G'); + /* any error in old protocol will make us lose sync */ + pq_startmsgread(); cstate->copy_dest = COPY_OLD_FE; } else @@ -367,6 +369,8 @@ ReceiveCopyBegin(CopyState cstate) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("COPY BINARY is not supported to stdout or from stdin"))); pq_putemptymessage('D'); + /* any error in old protocol will make us lose sync */ + pq_startmsgread(); cstate->copy_dest = COPY_OLD_FE; } /* We *must* flush here to ensure FE knows it can send. */ @@ -527,6 +531,8 @@ CopyGetData(CopyState cstate, void *databuf, int minread, int maxread) int mtype; readmessage: + HOLD_CANCEL_INTERRUPTS(); + pq_startmsgread(); mtype = pq_getbyte(); if (mtype == EOF) ereport(ERROR, @@ -536,6 +542,7 @@ CopyGetData(CopyState cstate, void *databuf, int minread, int maxread) ereport(ERROR, (errcode(ERRCODE_CONNECTION_FAILURE), errmsg("unexpected EOF on client connection"))); + RESUME_CANCEL_INTERRUPTS(); switch (mtype) { case 'd': /* CopyData */ @@ -2196,6 +2203,13 @@ CopyFrom(CopyState cstate) MemoryContextSwitchTo(oldcontext); + /* + * In the old protocol, tell pqcomm that we can process normal protocol + * messages again. + */ + if (cstate->copy_dest == COPY_OLD_FE) + pq_endmsgread(); + /* Execute AFTER STATEMENT insertion triggers */ ExecASInsertTriggers(estate, resultRelInfo); |