|
96 | 96 | * Portions Copyright (c) 1994-5, Regents of the University of California |
97 | 97 | * |
98 | 98 | * IDENTIFICATION |
99 | | - * $PostgreSQL: pgsql/src/backend/access/heap/rewriteheap.c,v 1.2 2007/04/1720:49:39 tgl Exp $ |
| 99 | + * $PostgreSQL: pgsql/src/backend/access/heap/rewriteheap.c,v 1.3 2007/04/1721:29:31 tgl Exp $ |
100 | 100 | * |
101 | 101 | *------------------------------------------------------------------------- |
102 | 102 | */ |
@@ -272,10 +272,17 @@ end_heap_rewrite(RewriteState state) |
272 | 272 | } |
273 | 273 |
|
274 | 274 | /* |
275 | | - * Ifnot WAL-logging, must fsync before commit. We use heap_sync |
| 275 | + * Ifthe rel isn't temp, must fsync before commit. We use heap_sync |
276 | 276 | * to ensure that the toast table gets fsync'd too. |
| 277 | + * |
| 278 | + * It's obvious that we must do this when not WAL-logging. It's less |
| 279 | + * obvious that we have to do it even if we did WAL-log the pages. |
| 280 | + * The reason is the same as in tablecmds.c's copy_relation_data(): |
| 281 | + * we're writing data that's not in shared buffers, and so a CHECKPOINT |
| 282 | + * occurring during the rewriteheap operation won't have fsync'd data |
| 283 | + * we wrote before the checkpoint. |
277 | 284 | */ |
278 | | -if (!state->rs_use_wal) |
| 285 | +if (!state->rs_new_rel->rd_istemp) |
279 | 286 | heap_sync(state->rs_new_rel); |
280 | 287 |
|
281 | 288 | /* Deleting the context frees everything */ |
@@ -584,7 +591,7 @@ raw_heap_insert(RewriteState state, HeapTuple tup) |
584 | 591 | /* |
585 | 592 | * Now write the page. We say isTemp = true even if it's not a |
586 | 593 | * temp table, because there's no need for smgr to schedule an |
587 | | - * fsync for this write; we'll do it ourselvesbefore committing. |
| 594 | + * fsync for this write; we'll do it ourselvesin end_heap_rewrite. |
588 | 595 | */ |
589 | 596 | RelationOpenSmgr(state->rs_new_rel); |
590 | 597 | smgrextend(state->rs_new_rel->rd_smgr,state->rs_blockno, |
|