mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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.
This commit is contained in:
@ -545,6 +545,23 @@ SELECT * FROM instead_of_insert_tbl;
|
||||
1 | test1
|
||||
(1 row)
|
||||
|
||||
-- Test of COPY optimization with view using INSTEAD OF INSERT
|
||||
-- trigger when relation is created in the same transaction as
|
||||
-- when COPY is executed.
|
||||
BEGIN;
|
||||
CREATE VIEW instead_of_insert_tbl_view_2 as select ''::text as str;
|
||||
CREATE TRIGGER trig_instead_of_insert_tbl_view_2
|
||||
INSTEAD OF INSERT ON instead_of_insert_tbl_view_2
|
||||
FOR EACH ROW EXECUTE PROCEDURE fun_instead_of_insert_tbl();
|
||||
COPY instead_of_insert_tbl_view_2 FROM stdin;
|
||||
SELECT * FROM instead_of_insert_tbl;
|
||||
id | name
|
||||
----+-------
|
||||
1 | test1
|
||||
2 | test1
|
||||
(2 rows)
|
||||
|
||||
COMMIT;
|
||||
-- clean up
|
||||
DROP TABLE forcetest;
|
||||
DROP TABLE vistest;
|
||||
@ -557,4 +574,5 @@ DROP FUNCTION fn_x_before();
|
||||
DROP FUNCTION fn_x_after();
|
||||
DROP TABLE instead_of_insert_tbl;
|
||||
DROP VIEW instead_of_insert_tbl_view;
|
||||
DROP VIEW instead_of_insert_tbl_view_2;
|
||||
DROP FUNCTION fun_instead_of_insert_tbl();
|
||||
|
@ -398,6 +398,21 @@ test1
|
||||
|
||||
SELECT * FROM instead_of_insert_tbl;
|
||||
|
||||
-- Test of COPY optimization with view using INSTEAD OF INSERT
|
||||
-- trigger when relation is created in the same transaction as
|
||||
-- when COPY is executed.
|
||||
BEGIN;
|
||||
CREATE VIEW instead_of_insert_tbl_view_2 as select ''::text as str;
|
||||
CREATE TRIGGER trig_instead_of_insert_tbl_view_2
|
||||
INSTEAD OF INSERT ON instead_of_insert_tbl_view_2
|
||||
FOR EACH ROW EXECUTE PROCEDURE fun_instead_of_insert_tbl();
|
||||
|
||||
COPY instead_of_insert_tbl_view_2 FROM stdin;
|
||||
test1
|
||||
\.
|
||||
|
||||
SELECT * FROM instead_of_insert_tbl;
|
||||
COMMIT;
|
||||
|
||||
-- clean up
|
||||
DROP TABLE forcetest;
|
||||
@ -411,4 +426,5 @@ DROP FUNCTION fn_x_before();
|
||||
DROP FUNCTION fn_x_after();
|
||||
DROP TABLE instead_of_insert_tbl;
|
||||
DROP VIEW instead_of_insert_tbl_view;
|
||||
DROP VIEW instead_of_insert_tbl_view_2;
|
||||
DROP FUNCTION fun_instead_of_insert_tbl();
|
||||
|
Reference in New Issue
Block a user