|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.148 2000/05/19 03:22:29 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.148.2.1 2000/09/19 21:01:04 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -645,6 +645,19 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
|
645 | 645 | if (vacuum_pages.vpl_num_pages > 0) /* Clean pages from
|
646 | 646 | * vacuum_pages list */
|
647 | 647 | vc_vacheap(vacrelstats, onerel, &vacuum_pages);
|
| 648 | + else |
| 649 | + { |
| 650 | + /* |
| 651 | + * Flush dirty pages out to disk. We must do this even if we |
| 652 | + * didn't do anything else, because we want to ensure that all |
| 653 | + * tuples have correct on-row commit status on disk (see |
| 654 | + * bufmgr.c's comments for FlushRelationBuffers()). |
| 655 | + */ |
| 656 | + i = FlushRelationBuffers(onerel, vacrelstats->num_pages); |
| 657 | + if (i < 0) |
| 658 | + elog(ERROR, "VACUUM (vc_vacone): FlushRelationBuffers returned %d", |
| 659 | + i); |
| 660 | + } |
648 | 661 | }
|
649 | 662 | if (reindex)
|
650 | 663 | activate_indexes_of_a_table(relid, true);
|
@@ -1968,12 +1981,19 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
|
1968 | 1981 | pfree(Nvpl.vpl_pagedesc);
|
1969 | 1982 | }
|
1970 | 1983 |
|
| 1984 | + /* |
| 1985 | + * Flush dirty pages out to disk. We do this unconditionally, even if |
| 1986 | + * we don't need to truncate, because we want to ensure that all tuples |
| 1987 | + * have correct on-row commit status on disk (see bufmgr.c's comments |
| 1988 | + * for FlushRelationBuffers()). |
| 1989 | + */ |
| 1990 | + i = FlushRelationBuffers(onerel, blkno); |
| 1991 | + if (i < 0) |
| 1992 | + elog(ERROR, "VACUUM (vc_repair_frag): FlushRelationBuffers returned %d", i); |
| 1993 | + |
1971 | 1994 | /* truncate relation, after flushing any dirty pages out to disk */
|
1972 | 1995 | if (blkno < nblocks)
|
1973 | 1996 | {
|
1974 |
| - i = FlushRelationBuffers(onerel, blkno); |
1975 |
| - if (i < 0) |
1976 |
| - elog(FATAL, "VACUUM (vc_repair_frag): FlushRelationBuffers returned %d", i); |
1977 | 1997 | blkno = smgrtruncate(DEFAULT_SMGR, onerel, blkno);
|
1978 | 1998 | Assert(blkno >= 0);
|
1979 | 1999 | vacrelstats->num_pages = blkno; /* set new number of blocks */
|
@@ -2023,27 +2043,25 @@ vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList vacuum_pages)
|
2023 | 2043 | }
|
2024 | 2044 | }
|
2025 | 2045 |
|
| 2046 | + /* |
| 2047 | + * Flush dirty pages out to disk. We do this unconditionally, even if |
| 2048 | + * we don't need to truncate, because we want to ensure that all tuples |
| 2049 | + * have correct on-row commit status on disk (see bufmgr.c's comments |
| 2050 | + * for FlushRelationBuffers()). |
| 2051 | + */ |
| 2052 | + Assert(vacrelstats->num_pages >= vacuum_pages->vpl_empty_end_pages); |
| 2053 | + nblocks = vacrelstats->num_pages - vacuum_pages->vpl_empty_end_pages; |
| 2054 | + |
| 2055 | + i = FlushRelationBuffers(onerel, nblocks); |
| 2056 | + if (i < 0) |
| 2057 | + elog(ERROR, "VACUUM (vc_vacheap): FlushRelationBuffers returned %d", i); |
| 2058 | + |
2026 | 2059 | /* truncate relation if there are some empty end-pages */
|
2027 | 2060 | if (vacuum_pages->vpl_empty_end_pages > 0)
|
2028 | 2061 | {
|
2029 |
| - Assert(vacrelstats->num_pages >= vacuum_pages->vpl_empty_end_pages); |
2030 |
| - nblocks = vacrelstats->num_pages - vacuum_pages->vpl_empty_end_pages; |
2031 | 2062 | elog(MESSAGE_LEVEL, "Rel %s: Pages: %u --> %u.",
|
2032 | 2063 | RelationGetRelationName(onerel),
|
2033 | 2064 | vacrelstats->num_pages, nblocks);
|
2034 |
| - |
2035 |
| - /* |
2036 |
| - * We have to flush "empty" end-pages (if changed, but who knows |
2037 |
| - * it) before truncation |
2038 |
| - * |
2039 |
| - * XXX is FlushBufferPool() still needed here? |
2040 |
| - */ |
2041 |
| - FlushBufferPool(); |
2042 |
| - |
2043 |
| - i = FlushRelationBuffers(onerel, nblocks); |
2044 |
| - if (i < 0) |
2045 |
| - elog(FATAL, "VACUUM (vc_vacheap): FlushRelationBuffers returned %d", i); |
2046 |
| - |
2047 | 2065 | nblocks = smgrtruncate(DEFAULT_SMGR, onerel, nblocks);
|
2048 | 2066 | Assert(nblocks >= 0);
|
2049 | 2067 | vacrelstats->num_pages = nblocks; /* set new number of
|
|
0 commit comments