diff -Ncar postgresql-8.2.1.org/src/backend/access/transam/xlog.c postgresql-8.2.1/src/backend/access/transam/xlog.c *** postgresql-8.2.1.org/src/backend/access/transam/xlog.c 2006-12-01 03:29:11.000000000 +0900 --- postgresql-8.2.1/src/backend/access/transam/xlog.c 2007-04-06 16:54:23.000000000 +0900 *************** *** 137,142 **** --- 137,143 ---- char *XLOG_sync_method = NULL; const char XLOG_sync_method_default[] = DEFAULT_SYNC_METHOD_STR; bool fullPageWrites = true; + bool walAddOptimizationInfo = false; #ifdef WAL_DEBUG bool XLOG_DEBUG = false; *************** *** 626,632 **** { /* Buffer already referenced by earlier chain item */ if (dtbuf_bkp[i]) ! rdt->data = NULL; else if (rdt->data) { len += rdt->len; --- 627,641 ---- { /* Buffer already referenced by earlier chain item */ if (dtbuf_bkp[i]) ! { ! if (fullPageWrites && walAddOptimizationInfo && rdt->data) ! { ! len += rdt->len; ! COMP_CRC32(rdata_crc, rdt->data, rdt->len); ! } ! else ! rdt->data = NULL; ! } else if (rdt->data) { len += rdt->len; *************** *** 642,648 **** &(dtbuf_lsn[i]), &(dtbuf_xlg[i]))) { dtbuf_bkp[i] = true; ! rdt->data = NULL; } else if (rdt->data) { --- 651,663 ---- &(dtbuf_lsn[i]), &(dtbuf_xlg[i]))) { dtbuf_bkp[i] = true; ! if (fullPageWrites && walAddOptimizationInfo && rdt->data) ! { ! len += rdt->len; ! COMP_CRC32(rdata_crc, rdt->data, rdt->len); ! } ! else ! rdt->data = NULL; } else if (rdt->data) { *************** *** 908,913 **** --- 923,941 ---- return RecPtr; } + /* + * If online backup is not in progress and wal_add_optimization_info is on, + * mark backup blocks removable if any. + * This mark will be referenced during archiving to remove needless backup + * blocks in the record and compress WAL segment files. + * NOTE: wal_add_optimization_info is ignored when full_page_writes is off. + */ + if (fullPageWrites && walAddOptimizationInfo && (info & XLR_BKP_BLOCK_MASK) && + !Insert->forcePageWrites) + { + info |= XLR_BKP_REMOVABLE; + } + /* Insert record header */ record = (XLogRecord *) Insert->currpos; *************** *** 2820,2832 **** blk += blen; } ! /* Check that xl_tot_len agrees with our calculation */ ! if (blk != (char *) record + record->xl_tot_len) { ! ereport(emode, ! (errmsg("incorrect total length in record at %X/%X", ! recptr.xlogid, recptr.xrecoff))); ! return false; } /* Finally include the record header */ --- 2848,2876 ---- blk += blen; } ! /* ! * If physical log has not been removed, check the length to see ! * the following. ! * - No physical log existed originally, ! * - WAL record was not removable because it is generated during ! * the online backup, ! * - Cannot be removed because the physical log spanned in ! * two segments. ! * The reason why we skip the length check on the physical log removal is ! * that the flag XLR_SET_BKB_BLOCK(0..2) is reset to zero and it prevents ! * the above loop to proceed blk to the end of the record. ! */ ! if (!(record->xl_info & XLR_BKP_REMOVABLE) || ! record->xl_info & XLR_BKP_BLOCK_MASK) { ! /* Check that xl_tot_len agrees with our calculation */ ! if (blk != (char *) record + record->xl_tot_len) ! { ! ereport(emode, ! (errmsg("incorrect total length in record at %X/%X", ! recptr.xlogid, recptr.xrecoff))); ! return false; ! } } /* Finally include the record header */ diff -Ncar postgresql-8.2.1.org/src/backend/utils/misc/guc.c postgresql-8.2.1/src/backend/utils/misc/guc.c *** postgresql-8.2.1.org/src/backend/utils/misc/guc.c 2006-11-29 23:50:07.000000000 +0900 --- postgresql-8.2.1/src/backend/utils/misc/guc.c 2007-04-06 16:54:23.000000000 +0900 *************** *** 97,102 **** --- 97,103 ---- extern int CommitSiblings; extern char *default_tablespace; extern bool fullPageWrites; + extern bool walAddOptimizationInfo; #ifdef TRACE_SORT extern bool trace_sort; *************** *** 546,551 **** --- 547,560 ---- true, NULL, NULL }, { + {"wal_add_optimization_info", PGC_SIGHUP, WAL_SETTINGS, + gettext_noop("Writes logical log corresponding to full pages in WAL record."), + gettext_noop("") + }, + &walAddOptimizationInfo, + false, NULL, NULL + }, + { {"silent_mode", PGC_POSTMASTER, LOGGING_WHEN, gettext_noop("Runs the server silently."), gettext_noop("If this parameter is set, the server will automatically run in the " diff -Ncar postgresql-8.2.1.org/src/backend/utils/misc/postgresql.conf.sample postgresql-8.2.1/src/backend/utils/misc/postgresql.conf.sample *** postgresql-8.2.1.org/src/backend/utils/misc/postgresql.conf.sample 2006-11-21 10:23:37.000000000 +0900 --- postgresql-8.2.1/src/backend/utils/misc/postgresql.conf.sample 2007-04-06 16:54:23.000000000 +0900 *************** *** 154,159 **** --- 154,161 ---- # fsync_writethrough # open_sync #full_page_writes = on # recover from partial page writes + #wal_add_optimization_info = off # write logical log correspond to full + # page. #wal_buffers = 64kB # min 32kB # (change requires restart) #commit_delay = 0 # range 0-100000, in microseconds diff -Ncar postgresql-8.2.1.org/src/include/access/xlog.h postgresql-8.2.1/src/include/access/xlog.h *** postgresql-8.2.1.org/src/include/access/xlog.h 2006-11-06 07:42:10.000000000 +0900 --- postgresql-8.2.1/src/include/access/xlog.h 2007-04-06 16:54:23.000000000 +0900 *************** *** 66,73 **** /* * If we backed up any disk blocks with the XLOG record, we use flag bits in * xl_info to signal it. We support backup of up to 3 disk blocks per XLOG ! * record. (Could support 4 if we cared to dedicate all the xl_info bits for ! * this purpose; currently bit 0 of xl_info is unused and available.) */ #define XLR_BKP_BLOCK_MASK 0x0E /* all info bits used for bkp blocks */ #define XLR_MAX_BKP_BLOCKS 3 --- 66,74 ---- /* * If we backed up any disk blocks with the XLOG record, we use flag bits in * xl_info to signal it. We support backup of up to 3 disk blocks per XLOG ! * record. ! * Bit 0 of xl_info is used to represent that backup blocks are not necessary ! * in archive-log. */ #define XLR_BKP_BLOCK_MASK 0x0E /* all info bits used for bkp blocks */ #define XLR_MAX_BKP_BLOCKS 3 *************** *** 75,80 **** --- 76,82 ---- #define XLR_BKP_BLOCK_1 XLR_SET_BKP_BLOCK(0) /* 0x08 */ #define XLR_BKP_BLOCK_2 XLR_SET_BKP_BLOCK(1) /* 0x04 */ #define XLR_BKP_BLOCK_3 XLR_SET_BKP_BLOCK(2) /* 0x02 */ + #define XLR_BKP_REMOVABLE XLR_SET_BKP_BLOCK(3) /* 0x01 */ /* * Sometimes we log records which are out of transaction control.