aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2018-12-23 16:43:47 +0900
committerMichael Paquier <michael@paquier.xyz>2018-12-23 16:43:47 +0900
commitff9c222669063d7a17b179bc19617caf9c1f67ea (patch)
treefd4dbb8f8c81811b21dc0297372e9eb02bb06955 /src/backend
parent018923ccc1a68eeac852edeac2ba3bc91dcbd494 (diff)
downloadpostgresql-ff9c222669063d7a17b179bc19617caf9c1f67ea.tar.gz
postgresql-ff9c222669063d7a17b179bc19617caf9c1f67ea.zip
Disable WAL-skipping optimization for COPY on views and foreign tables
COPY can skip writing WAL when loading data on a table which has been created in the same transaction as the one loading the data, however this cannot work on views or foreign table as this would result in trying to flush relation files which do not exist. So disable the optimization so as commands are able to work the same way with any configuration of wal_level. Tests are added to cover the different cases, which need to have wal_level set to minimal to allow the problem to show up, and that is not the default configuration. Reported-by: Luis M. Carril, Etsuro Fujita Author: Amit Langote, Michael Paquier Reviewed-by: Etsuro Fujita Discussion: https://postgr.es/m/15552-c64aa14c5c22f63c@postgresql.org Backpatch-through: 10, where support for COPY on views has been added, while v11 has added support for COPY on foreign tables.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/commands/copy.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 25d19a51182..f4653485e2b 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2423,10 +2423,17 @@ CopyFrom(CopyState cstate)
* possible to improve on this, but it does mean maintaining heap insert
* option flags per partition and setting them when we first open the
* partition.
+ *
+ * This optimization is not supported for relation types which do not
+ * have any physical storage, with foreign tables and views using
+ * INSTEAD OF triggers entering in this category. Partitioned tables
+ * are not supported as per the description above.
*----------
*/
/* createSubid is creation check, newRelfilenodeSubid is truncation check */
- if (cstate->rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE &&
+ if (cstate->rel->rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
+ cstate->rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE &&
+ cstate->rel->rd_rel->relkind != RELKIND_VIEW &&
(cstate->rel->rd_createSubid != InvalidSubTransactionId ||
cstate->rel->rd_newRelfilenodeSubid != InvalidSubTransactionId))
{