On 2013-02-03 02:40:04 +0100, Andres Freund wrote: > On 2013-02-01 15:09:34 -0800, Jeff Janes wrote: > > As an aside, it does seem like log_autovacuum_min_duration=0 should > > log whether a scan_all was done, and if so what relfrozenxid got set > > to. But looking at where the log message is generated, I don't know > > where to retrieve that info. > > What about the following, very rough and quick, patch:
-EINTR -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index 5ec65ea..881d8d6 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -304,6 +304,11 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, TimestampDifferenceExceeds(starttime, endtime, Log_autovacuum_min_duration)) { + double scanned_percent; + txid freeze_txid; + txid relfrozen_txid; + char freeze_txid_buf[80]; + char relfrozen_txid_buf[80]; TimestampDifference(starttime, endtime, &secs, &usecs); read_rate = 0; @@ -315,10 +320,29 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, write_rate = (double) BLCKSZ *VacuumPageDirty / (1024 * 1024) / (secs + usecs / 1000000.0); } + + scanned_percent = ((double) vacrelstats->scanned_pages / + (vacrelstats->rel_pages + + vacrelstats->pages_removed)) * 100; + + freeze_txid = txid_from_xid(FreezeLimit); + relfrozen_txid = txid_from_xid(new_frozen_xid); + + /* + * print to buffer, so we don't have to include UINT64_FORMAT in a + * translatable string. + */ + snprintf(freeze_txid_buf, sizeof(freeze_txid_buf), + UINT64_FORMAT, freeze_txid); + + snprintf(relfrozen_txid_buf, sizeof(relfrozen_txid_buf), + UINT64_FORMAT, relfrozen_txid); + ereport(LOG, (errmsg("automatic vacuum of table \"%s.%s.%s\": index scans: %d\n" - "pages: %d removed, %d remain\n" + "pages: %d removed, %d remain, %d (%.02f%%) scanned\n" "tuples: %.0f removed, %.0f remain\n" + "full-scan: %d, freeze-limit: %s, new-frozen-xid: %s\n" "buffer usage: %d hits, %d misses, %d dirtied\n" "avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n" "system usage: %s", @@ -328,8 +352,13 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, vacrelstats->num_index_scans, vacrelstats->pages_removed, vacrelstats->rel_pages, + vacrelstats->scanned_pages, + scanned_percent, vacrelstats->tuples_deleted, vacrelstats->new_rel_tuples, + scan_all, + freeze_txid_buf, + scan_all ? relfrozen_txid_buf : "-", VacuumPageHit, VacuumPageMiss, VacuumPageDirty, diff --git a/src/backend/utils/adt/txid.c b/src/backend/utils/adt/txid.c index de86756..78edec5 100644 --- a/src/backend/utils/adt/txid.c +++ b/src/backend/utils/adt/txid.c @@ -33,9 +33,6 @@ /* txid will be signed int8 in database, so must limit to 63 bits */ #define MAX_TXID UINT64CONST(0x7FFFFFFFFFFFFFFF) -/* Use unsigned variant internally */ -typedef uint64 txid; - /* sprintf format code for uint64 */ #define TXID_FMT UINT64_FORMAT @@ -98,11 +95,17 @@ convert_xid(TransactionId xid, const TxidEpoch *state) if (!TransactionIdIsNormal(xid)) return (txid) xid; - /* xid can be on either side when near wrap-around */ epoch = (uint64) state->epoch; + /* xid is too old to be real */ if (xid > state->last_xid && + TransactionIdPrecedes(xid, state->last_xid) && + epoch == 0) + xid = InvalidTransactionId; + /* xid in last epoch */ + else if (xid > state->last_xid && TransactionIdPrecedes(xid, state->last_xid)) epoch--; + /* xid after wraparound */ else if (xid < state->last_xid && TransactionIdFollows(xid, state->last_xid)) epoch++; @@ -317,6 +320,16 @@ bad_format: * communicate with core xid machinery. All the others work on data * returned by them. */ +txid +txid_from_xid(TransactionId xid) +{ + txid val; + TxidEpoch state; + + load_xid_epoch(&state); + val = convert_xid(xid, &state); + return val; +} /* * txid_current() returns int8 @@ -327,9 +340,6 @@ bad_format: Datum txid_current(PG_FUNCTION_ARGS) { - txid val; - TxidEpoch state; - /* * Must prevent during recovery because if an xid is not assigned we try * to assign one, which would fail. Programs already rely on this function @@ -338,11 +348,7 @@ txid_current(PG_FUNCTION_ARGS) */ PreventCommandDuringRecovery("txid_current()"); - load_xid_epoch(&state); - - val = convert_xid(GetTopTransactionId(), &state); - - PG_RETURN_INT64(val); + return txid_from_xid(GetTopTransactionId()); } /* diff --git a/src/include/access/transam.h b/src/include/access/transam.h index 23a41fd..5d99f4d 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -127,6 +127,13 @@ typedef struct VariableCacheData typedef VariableCacheData *VariableCache; +/* + * 64bit representation of xids which include the epoch + */ +typedef uint64 txid; +txid txid_from_xid(TransactionId xid); + + /* ---------------- * extern declarations
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers