Reject COPY TO of unlogged tables during recovery.

Unlogged tables have no data on a standby, so reading one there must
fail. SELECT and COPY (SELECT ...) TO already report a clear error,
but COPY with a table name read the table directly and failed with a
low-level error instead:

ERROR:  could not open file "base/5/16384": No such file or directory

Check for this case in COPY TO and report the same error as SELECT. On
v19 and later, also check each partition when copying from a
partitioned table, so that an unlogged partition is reported too.

Backpatch to all supported versions, since the low-level error looks
like data corruption.

Author: Jim Jones <[email protected]>
Reviewed-by: Zsolt Parragi <[email protected]>
Reviewed-by: Masahiko Sawada <[email protected]>
Discussion: 
https://postgr.es/m/[email protected]
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1e707d32564497ed2478f4186b90d0821719957b

Modified Files
--------------
src/backend/commands/copyto.c         | 19 +++++++++++++++++++
src/test/recovery/t/001_stream_rep.pl | 27 +++++++++++++++++++++++++++
2 files changed, 46 insertions(+)

Reply via email to