PostgreSQL Concurrency – Can CREATE OR REPLACE VIEW Block?

blockingconcurrencylockingpostgresqlview

I'm looking for a way for a table to be swapped while it's being used. Say we have a view

CREATE OR REPLACE VIEW my_data AS SELECT * FROM my_data_v1;

that is being used, e.g. lots of SELECT * FROM my_data. Then I ingest data into a new table, my_data_v2, and then run:

CREATE OR REPLACE VIEW my_data AS SELECT * FROM my_data_v2;

Would this block on any SELECT statements that are using the original view definition?

Best Answer

Yes, that would block, and there is no way around that.