mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-04 01:47:21 +02:00
Avoid possible crash while finishing up a heap rewrite.
end_heap_rewrite was not careful to ensure that the target relation
is open at the smgr level before performing its final smgrimmedsync.
In ordinary cases this is no problem, because it would have been
opened earlier during the rewrite. However a crash can be reproduced
by re-clustering an empty table with CLOBBER_CACHE_ALWAYS enabled.
Although that exact scenario does not crash in v13, I think that's
a chance result of unrelated planner changes, and the problem is
likely still reachable with other test cases. The true proximate
cause of this failure is commit c6b92041d
, which replaced a call to
heap_sync (which was careful about opening smgr) with a direct call
to smgrimmedsync. Hence, back-patch to v13.
Amul Sul, per report from Neha Sharma; cosmetic changes
and test case by me.
Discussion: https://postgr.es/m/CANiYTQsU7yMFpQYnv=BrcRVqK_3U3mtAzAsJCaqtzsDHfsUbdQ@mail.gmail.com
This commit is contained in:
parent
1faaad260d
commit
d4791ac35c
@ -324,10 +324,10 @@ end_heap_rewrite(RewriteState state)
|
|||||||
state->rs_blockno,
|
state->rs_blockno,
|
||||||
state->rs_buffer,
|
state->rs_buffer,
|
||||||
true);
|
true);
|
||||||
RelationOpenSmgr(state->rs_new_rel);
|
|
||||||
|
|
||||||
PageSetChecksumInplace(state->rs_buffer, state->rs_blockno);
|
PageSetChecksumInplace(state->rs_buffer, state->rs_blockno);
|
||||||
|
|
||||||
|
RelationOpenSmgr(state->rs_new_rel);
|
||||||
smgrextend(state->rs_new_rel->rd_smgr, MAIN_FORKNUM, state->rs_blockno,
|
smgrextend(state->rs_new_rel->rd_smgr, MAIN_FORKNUM, state->rs_blockno,
|
||||||
(char *) state->rs_buffer, true);
|
(char *) state->rs_buffer, true);
|
||||||
}
|
}
|
||||||
@ -340,7 +340,11 @@ end_heap_rewrite(RewriteState state)
|
|||||||
* wrote before the checkpoint.
|
* wrote before the checkpoint.
|
||||||
*/
|
*/
|
||||||
if (RelationNeedsWAL(state->rs_new_rel))
|
if (RelationNeedsWAL(state->rs_new_rel))
|
||||||
|
{
|
||||||
|
/* for an empty table, this could be first smgr access */
|
||||||
|
RelationOpenSmgr(state->rs_new_rel);
|
||||||
smgrimmedsync(state->rs_new_rel->rd_smgr, MAIN_FORKNUM);
|
smgrimmedsync(state->rs_new_rel->rd_smgr, MAIN_FORKNUM);
|
||||||
|
}
|
||||||
|
|
||||||
logical_end_heap_rewrite(state);
|
logical_end_heap_rewrite(state);
|
||||||
|
|
||||||
|
@ -439,6 +439,11 @@ select * from clstr_temp;
|
|||||||
|
|
||||||
drop table clstr_temp;
|
drop table clstr_temp;
|
||||||
RESET SESSION AUTHORIZATION;
|
RESET SESSION AUTHORIZATION;
|
||||||
|
-- check clustering an empty table
|
||||||
|
DROP TABLE clustertest;
|
||||||
|
CREATE TABLE clustertest (f1 int PRIMARY KEY);
|
||||||
|
CLUSTER clustertest USING clustertest_pkey;
|
||||||
|
CLUSTER clustertest;
|
||||||
-- Check that partitioned tables cannot be clustered
|
-- Check that partitioned tables cannot be clustered
|
||||||
CREATE TABLE clstrpart (a int) PARTITION BY RANGE (a);
|
CREATE TABLE clstrpart (a int) PARTITION BY RANGE (a);
|
||||||
CREATE INDEX clstrpart_idx ON clstrpart (a);
|
CREATE INDEX clstrpart_idx ON clstrpart (a);
|
||||||
|
@ -196,6 +196,12 @@ drop table clstr_temp;
|
|||||||
|
|
||||||
RESET SESSION AUTHORIZATION;
|
RESET SESSION AUTHORIZATION;
|
||||||
|
|
||||||
|
-- check clustering an empty table
|
||||||
|
DROP TABLE clustertest;
|
||||||
|
CREATE TABLE clustertest (f1 int PRIMARY KEY);
|
||||||
|
CLUSTER clustertest USING clustertest_pkey;
|
||||||
|
CLUSTER clustertest;
|
||||||
|
|
||||||
-- Check that partitioned tables cannot be clustered
|
-- Check that partitioned tables cannot be clustered
|
||||||
CREATE TABLE clstrpart (a int) PARTITION BY RANGE (a);
|
CREATE TABLE clstrpart (a int) PARTITION BY RANGE (a);
|
||||||
CREATE INDEX clstrpart_idx ON clstrpart (a);
|
CREATE INDEX clstrpart_idx ON clstrpart (a);
|
||||||
|
Loading…
Reference in New Issue
Block a user