Skip to content

Commit 7951d67

Browse files
committed
Merge branch 'REL9_5_STABLE' into PGPRO9_5
2 parents 28ed493 + 47e5969 commit 7951d67

File tree

11 files changed

+196
-187
lines changed

11 files changed

+196
-187
lines changed

doc/src/sgml/release-9.5.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ Add GUC and storage parameter to set the maximum size of GIN pending list.
22712271
-->
22722272
<para>
22732273
Add per-table autovacuum logging control via new
2274-
<varname>log_min_autovacuum_duration</> storage parameter
2274+
<varname>log_autovacuum_min_duration</> storage parameter
22752275
(Michael Paquier)
22762276
</para>
22772277
</listitem>

src/backend/commands/vacuum.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ vac_truncate_clog(TransactionId frozenXID,
10501050
TransactionId lastSaneFrozenXid,
10511051
MultiXactId lastSaneMinMulti)
10521052
{
1053-
TransactionId myXID = GetCurrentTransactionId();
1053+
TransactionId nextXID = ReadNewTransactionId();
10541054
Relation relation;
10551055
HeapScanDesc scan;
10561056
HeapTuple tuple;
@@ -1066,6 +1066,12 @@ vac_truncate_clog(TransactionId frozenXID,
10661066
/*
10671067
* Scan pg_database to compute the minimum datfrozenxid/datminmxid
10681068
*
1069+
* Since vac_update_datfrozenxid updates datfrozenxid/datminmxid in-place,
1070+
* the values could change while we look at them. Fetch each one just
1071+
* once to ensure sane behavior of the comparison logic. (Here, as in
1072+
* many other places, we assume that fetching or updating an XID in shared
1073+
* storage is atomic.)
1074+
*
10691075
* Note: we need not worry about a race condition with new entries being
10701076
* inserted by CREATE DATABASE. Any such entry will have a copy of some
10711077
* existing DB's datfrozenxid, and that source DB cannot be ours because
@@ -1081,10 +1087,12 @@ vac_truncate_clog(TransactionId frozenXID,
10811087

10821088
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
10831089
{
1084-
Form_pg_database dbform = (Form_pg_database) GETSTRUCT(tuple);
1090+
volatile FormData_pg_database *dbform = (Form_pg_database) GETSTRUCT(tuple);
1091+
TransactionId datfrozenxid = dbform->datfrozenxid;
1092+
TransactionId datminmxid = dbform->datminmxid;
10851093

1086-
Assert(TransactionIdIsNormal(dbform->datfrozenxid));
1087-
Assert(MultiXactIdIsValid(dbform->datminmxid));
1094+
Assert(TransactionIdIsNormal(datfrozenxid));
1095+
Assert(MultiXactIdIsValid(datminmxid));
10881096

10891097
/*
10901098
* If things are working properly, no database should have a
@@ -1095,21 +1103,21 @@ vac_truncate_clog(TransactionId frozenXID,
10951103
* databases have been scanned and cleaned up. (We will issue the
10961104
* "already wrapped" warning if appropriate, though.)
10971105
*/
1098-
if (TransactionIdPrecedes(lastSaneFrozenXid, dbform->datfrozenxid) ||
1099-
MultiXactIdPrecedes(lastSaneMinMulti, dbform->datminmxid))
1106+
if (TransactionIdPrecedes(lastSaneFrozenXid, datfrozenxid) ||
1107+
MultiXactIdPrecedes(lastSaneMinMulti, datminmxid))
11001108
bogus = true;
11011109

1102-
if (TransactionIdPrecedes(myXID, dbform->datfrozenxid))
1110+
if (TransactionIdPrecedes(nextXID, datfrozenxid))
11031111
frozenAlreadyWrapped = true;
1104-
else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID))
1112+
else if (TransactionIdPrecedes(datfrozenxid, frozenXID))
11051113
{
1106-
frozenXID = dbform->datfrozenxid;
1114+
frozenXID = datfrozenxid;
11071115
oldestxid_datoid = HeapTupleGetOid(tuple);
11081116
}
11091117

1110-
if (MultiXactIdPrecedes(dbform->datminmxid, minMulti))
1118+
if (MultiXactIdPrecedes(datminmxid, minMulti))
11111119
{
1112-
minMulti = dbform->datminmxid;
1120+
minMulti = datminmxid;
11131121
minmulti_datoid = HeapTupleGetOid(tuple);
11141122
}
11151123
}

src/backend/postmaster/pgstat.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5351,7 +5351,16 @@ pgstat_db_requested(Oid databaseid)
53515351
{
53525352
slist_iter iter;
53535353

5354-
/* Check the databases if they need to refresh the stats. */
5354+
/*
5355+
* If any requests are outstanding at all, we should write the stats for
5356+
* shared catalogs (the "database" with OID 0). This ensures that
5357+
* backends will see up-to-date stats for shared catalogs, even though
5358+
* they send inquiry messages mentioning only their own DB.
5359+
*/
5360+
if (databaseid == InvalidOid && !slist_is_empty(&last_statrequests))
5361+
return true;
5362+
5363+
/* Search to see if there's an open request to write this database. */
53555364
slist_foreach(iter, &last_statrequests)
53565365
{
53575366
DBWriteRequest *req = slist_container(DBWriteRequest, next, iter.cur);

0 commit comments

Comments
 (0)