mirror of https://github.com/postgres/postgres
When multiple relations are reindexed, a scan of pg_class is done first to build the list of relations to work on. However the REINDEX logic has never checked if a relation listed still exists when beginning the work on it, causing for example sudden cache lookup failures. This commit adds safeguards against dropped relations for REINDEX, similarly to VACUUM or CLUSTER where we try to open the relation, ignoring it if it is missing. A new option is added to the REINDEX routines to control if a missed relation is OK to ignore or not. An isolation test, based on REINDEX SCHEMA, is added for the concurrent and non-concurrent cases. Author: Michael Paquier Reviewed-by: Anastasia Lubennikova Discussion: https://postgr.es/m/20200813043805.GE11663@paquier.xyzpull/57/head
parent
4c51a2d1e4
commit
1d65416661
@ -0,0 +1,17 @@ |
||||
Parsed test spec with 3 sessions |
||||
|
||||
starting permutation: begin1 lock1 reindex2 drop3 end1 |
||||
step begin1: BEGIN; |
||||
step lock1: LOCK reindex_schema.tab_locked IN SHARE UPDATE EXCLUSIVE MODE; |
||||
step reindex2: REINDEX SCHEMA reindex_schema; <waiting ...> |
||||
step drop3: DROP TABLE reindex_schema.tab_dropped; |
||||
step end1: COMMIT; |
||||
step reindex2: <... completed> |
||||
|
||||
starting permutation: begin1 lock1 reindex_conc2 drop3 end1 |
||||
step begin1: BEGIN; |
||||
step lock1: LOCK reindex_schema.tab_locked IN SHARE UPDATE EXCLUSIVE MODE; |
||||
step reindex_conc2: REINDEX SCHEMA CONCURRENTLY reindex_schema; <waiting ...> |
||||
step drop3: DROP TABLE reindex_schema.tab_dropped; |
||||
step end1: COMMIT; |
||||
step reindex_conc2: <... completed> |
@ -0,0 +1,32 @@ |
||||
# REINDEX with schemas |
||||
# |
||||
# Check that concurrent drop of relations while doing a REINDEX |
||||
# SCHEMA allows the command to work. |
||||
|
||||
setup |
||||
{ |
||||
CREATE SCHEMA reindex_schema; |
||||
CREATE TABLE reindex_schema.tab_locked (a int PRIMARY KEY); |
||||
CREATE TABLE reindex_schema.tab_dropped (a int PRIMARY KEY); |
||||
} |
||||
|
||||
teardown |
||||
{ |
||||
DROP SCHEMA reindex_schema CASCADE; |
||||
} |
||||
|
||||
session "s1" |
||||
step "begin1" { BEGIN; } |
||||
step "lock1" { LOCK reindex_schema.tab_locked IN SHARE UPDATE EXCLUSIVE MODE; } |
||||
step "end1" { COMMIT; } |
||||
|
||||
session "s2" |
||||
step "reindex2" { REINDEX SCHEMA reindex_schema; } |
||||
step "reindex_conc2" { REINDEX SCHEMA CONCURRENTLY reindex_schema; } |
||||
|
||||
session "s3" |
||||
step "drop3" { DROP TABLE reindex_schema.tab_dropped; } |
||||
|
||||
# The table can be dropped while reindex is waiting. |
||||
permutation "begin1" "lock1" "reindex2" "drop3" "end1" |
||||
permutation "begin1" "lock1" "reindex_conc2" "drop3" "end1" |
Loading…
Reference in new issue