diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c index 6a203b7853a..790e893e4dc 100644 --- a/src/backend/commands/copyto.c +++ b/src/backend/commands/copyto.c @@ -399,6 +399,11 @@ BeginCopyTo(ParseState *pstate, RelationGetRelationName(rel)))); } + /* Temporary and unlogged relations are inaccessible during recovery. */ + if (rel != NULL && !RelationIsPermanent(rel) && RecoveryInProgress()) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot access temporary or unlogged relations during recovery"))); /* Allocate workspace and zero all fields */ cstate = (CopyToStateData *) palloc0(sizeof(CopyToStateData)); diff --git a/src/test/recovery/t/001_stream_rep.pl b/src/test/recovery/t/001_stream_rep.pl index 54c3d3bdf51..0ccc31cadfc 100644 --- a/src/test/recovery/t/001_stream_rep.pl +++ b/src/test/recovery/t/001_stream_rep.pl @@ -87,6 +87,20 @@ is($node_standby_1->safe_psql('postgres', "SELECT pg_sequence_last_value('ulseq'::regclass) IS NULL"), 't', 'pg_sequence_last_value() on unlogged sequence on standby 1'); +# Check that COPY TO rejects unlogged tables on standby +$node_primary->safe_psql( + 'postgres', q{ +CREATE UNLOGGED TABLE ultab (a int); +}); +$node_primary->wait_for_catchup($node_standby_1, 'replay', + $node_primary->lsn('flush')); +my ($copy_ret, $copy_stdout, $copy_stderr) = + $node_standby_1->psql('postgres', 'COPY ultab TO STDOUT'); +like( + $copy_stderr, + qr/cannot access temporary or unlogged relations during recovery/, + 'COPY TO of unlogged table on standby 1'); + # Check that only READ-only queries can run on standbys is($node_standby_1->psql('postgres', 'INSERT INTO tab_int VALUES (1)'), 3, 'read-only queries on standby 1');