Skip to content

Commit d973747

Browse files
author
Amit Kapila
committed
Revert "Track statistics for spilling of changes from ReorderBuffer".
The stats with this commit was available only for WALSenders, however, users might want to see for backends doing logical decoding via SQL API. Then, users might want to reset and access these stats across server restart which was not possible with the current patch. List of commits reverted: caa3c42 Don't call elog() while holding spinlock. e641b2a Doc: Update the documentation for spilled transaction statistics. 5883f5f Fix unportable printf format introduced in commit 9290ad1. 9290ad1 Track statistics for spilling of changes from ReorderBuffer. Additionaly, remove the release notes entry for this feature. Backpatch-through: 13, where it was introduced Discussion: https://postgr.es/m/CA+fd4k5_pPAYRTDrO2PbtTOe0eHQpBvuqmCr8ic39uTNmR49Eg@mail.gmail.com
1 parent 5bfe6a3 commit d973747

File tree

9 files changed

+9
-120
lines changed

9 files changed

+9
-120
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,38 +2466,6 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
24662466
Send time of last reply message received from standby server
24672467
</para></entry>
24682468
</row>
2469-
2470-
<row>
2471-
<entry role="catalog_table_entry"><para role="column_definition">
2472-
<structfield>spill_txns</structfield> <type>bigint</type>
2473-
</para>
2474-
<para>
2475-
Number of transactions spilled to disk after the memory used by
2476-
logical decoding exceeds <literal>logical_decoding_work_mem</literal>. The
2477-
counter gets incremented both for top-level transactions and
2478-
subtransactions.
2479-
</para></entry>
2480-
</row>
2481-
2482-
<row>
2483-
<entry role="catalog_table_entry"><para role="column_definition">
2484-
<structfield>spill_count</structfield> <type>bigint</type>
2485-
</para>
2486-
<para>
2487-
Number of times transactions were spilled to disk. Transactions
2488-
may get spilled repeatedly, and this counter gets incremented on every
2489-
such invocation.
2490-
</para></entry>
2491-
</row>
2492-
2493-
<row>
2494-
<entry role="catalog_table_entry"><para role="column_definition">
2495-
<structfield>spill_bytes</structfield> <type>bigint</type>
2496-
</para>
2497-
<para>
2498-
Amount of decoded transaction data spilled to disk.
2499-
</para></entry>
2500-
</row>
25012469
</tbody>
25022470
</tgroup>
25032471
</table>
@@ -2522,12 +2490,6 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
25222490
mechanism will simply display NULL lag.
25232491
</para>
25242492

2525-
<para>
2526-
Tracking of spilled transactions works only for logical replication. In
2527-
physical replication, the tracking mechanism will display 0 for spilled
2528-
statistics.
2529-
</para>
2530-
25312493
<note>
25322494
<para>
25332495
The reported lag times are not predictions of how long it will take for

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,7 @@ CREATE VIEW pg_stat_replication AS
785785
W.replay_lag,
786786
W.sync_priority,
787787
W.sync_state,
788-
W.reply_time,
789-
W.spill_txns,
790-
W.spill_count,
791-
W.spill_bytes
788+
W.reply_time
792789
FROM pg_stat_get_activity(NULL) AS S
793790
JOIN pg_stat_get_wal_senders() AS W ON (S.pid = W.pid)
794791
LEFT JOIN pg_authid AS U ON (S.usesysid = U.oid);

src/backend/replication/logical/reorderbuffer.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,6 @@ ReorderBufferAllocate(void)
317317
buffer->outbufsize = 0;
318318
buffer->size = 0;
319319

320-
buffer->spillCount = 0;
321-
buffer->spillTxns = 0;
322-
buffer->spillBytes = 0;
323-
324320
buffer->current_restart_decoding_lsn = InvalidXLogRecPtr;
325321

326322
dlist_init(&buffer->toplevel_by_lsn);
@@ -2418,7 +2414,6 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
24182414
int fd = -1;
24192415
XLogSegNo curOpenSegNo = 0;
24202416
Size spilled = 0;
2421-
Size size = txn->size;
24222417

24232418
elog(DEBUG2, "spill %u changes in XID %u to disk",
24242419
(uint32) txn->nentries_mem, txn->xid);
@@ -2477,13 +2472,6 @@ ReorderBufferSerializeTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
24772472
spilled++;
24782473
}
24792474

2480-
/* update the statistics */
2481-
rb->spillCount += 1;
2482-
rb->spillBytes += size;
2483-
2484-
/* Don't consider already serialized transactions. */
2485-
rb->spillTxns += rbtxn_is_serialized(txn) ? 0 : 1;
2486-
24872475
Assert(spilled == txn->nentries_mem);
24882476
Assert(dlist_is_empty(&txn->changes));
24892477
txn->nentries_mem = 0;

src/backend/replication/walsender.c

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ static bool TransactionIdInRecentPast(TransactionId xid, uint32 epoch);
254254

255255
static void WalSndSegmentOpen(XLogReaderState *state, XLogSegNo nextSegNo,
256256
TimeLineID *tli_p);
257-
static void UpdateSpillStats(LogicalDecodingContext *ctx);
258257

259258

260259
/* Initialize walsender process before entering the main command loop */
@@ -1348,8 +1347,7 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
13481347
/*
13491348
* LogicalDecodingContext 'update_progress' callback.
13501349
*
1351-
* Write the current position to the lag tracker (see XLogSendPhysical),
1352-
* and update the spill statistics.
1350+
* Write the current position to the lag tracker (see XLogSendPhysical).
13531351
*/
13541352
static void
13551353
WalSndUpdateProgress(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid)
@@ -1368,11 +1366,6 @@ WalSndUpdateProgress(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId
13681366

13691367
LagTrackerWrite(lsn, now);
13701368
sendTime = now;
1371-
1372-
/*
1373-
* Update statistics about transactions that spilled to disk.
1374-
*/
1375-
UpdateSpillStats(ctx);
13761369
}
13771370

13781371
/*
@@ -2418,9 +2411,6 @@ InitWalSenderSlot(void)
24182411
walsnd->sync_standby_priority = 0;
24192412
walsnd->latch = &MyProc->procLatch;
24202413
walsnd->replyTime = 0;
2421-
walsnd->spillTxns = 0;
2422-
walsnd->spillCount = 0;
2423-
walsnd->spillBytes = 0;
24242414
SpinLockRelease(&walsnd->mutex);
24252415
/* don't need the lock anymore */
24262416
MyWalSnd = (WalSnd *) walsnd;
@@ -3256,7 +3246,7 @@ offset_to_interval(TimeOffset offset)
32563246
Datum
32573247
pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
32583248
{
3259-
#define PG_STAT_GET_WAL_SENDERS_COLS 15
3249+
#define PG_STAT_GET_WAL_SENDERS_COLS 12
32603250
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
32613251
TupleDesc tupdesc;
32623252
Tuplestorestate *tupstore;
@@ -3310,9 +3300,6 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
33103300
int pid;
33113301
WalSndState state;
33123302
TimestampTz replyTime;
3313-
int64 spillTxns;
3314-
int64 spillCount;
3315-
int64 spillBytes;
33163303
bool is_sync_standby;
33173304
Datum values[PG_STAT_GET_WAL_SENDERS_COLS];
33183305
bool nulls[PG_STAT_GET_WAL_SENDERS_COLS];
@@ -3336,9 +3323,6 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
33363323
applyLag = walsnd->applyLag;
33373324
priority = walsnd->sync_standby_priority;
33383325
replyTime = walsnd->replyTime;
3339-
spillTxns = walsnd->spillTxns;
3340-
spillCount = walsnd->spillCount;
3341-
spillBytes = walsnd->spillBytes;
33423326
SpinLockRelease(&walsnd->mutex);
33433327

33443328
/*
@@ -3436,11 +3420,6 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
34363420
nulls[11] = true;
34373421
else
34383422
values[11] = TimestampTzGetDatum(replyTime);
3439-
3440-
/* spill to disk */
3441-
values[12] = Int64GetDatum(spillTxns);
3442-
values[13] = Int64GetDatum(spillCount);
3443-
values[14] = Int64GetDatum(spillBytes);
34443423
}
34453424

34463425
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
@@ -3677,21 +3656,3 @@ LagTrackerRead(int head, XLogRecPtr lsn, TimestampTz now)
36773656
Assert(time != 0);
36783657
return now - time;
36793658
}
3680-
3681-
static void
3682-
UpdateSpillStats(LogicalDecodingContext *ctx)
3683-
{
3684-
ReorderBuffer *rb = ctx->reorder;
3685-
3686-
elog(DEBUG2, "UpdateSpillStats: updating stats %p %lld %lld %lld",
3687-
rb,
3688-
(long long) rb->spillTxns,
3689-
(long long) rb->spillCount,
3690-
(long long) rb->spillBytes);
3691-
3692-
SpinLockAcquire(&MyWalSnd->mutex);
3693-
MyWalSnd->spillTxns = rb->spillTxns;
3694-
MyWalSnd->spillCount = rb->spillCount;
3695-
MyWalSnd->spillBytes = rb->spillBytes;
3696-
SpinLockRelease(&MyWalSnd->mutex);
3697-
}

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202007121
56+
#define CATALOG_VERSION_NO 202007131
5757

5858
#endif

src/include/catalog/pg_proc.dat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5240,9 +5240,9 @@
52405240
proname => 'pg_stat_get_wal_senders', prorows => '10', proisstrict => 'f',
52415241
proretset => 't', provolatile => 's', proparallel => 'r',
52425242
prorettype => 'record', proargtypes => '',
5243-
proallargtypes => '{int4,text,pg_lsn,pg_lsn,pg_lsn,pg_lsn,interval,interval,interval,int4,text,timestamptz,int8,int8,int8}',
5244-
proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
5245-
proargnames => '{pid,state,sent_lsn,write_lsn,flush_lsn,replay_lsn,write_lag,flush_lag,replay_lag,sync_priority,sync_state,reply_time,spill_txns,spill_count,spill_bytes}',
5243+
proallargtypes => '{int4,text,pg_lsn,pg_lsn,pg_lsn,pg_lsn,interval,interval,interval,int4,text,timestamptz}',
5244+
proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o}',
5245+
proargnames => '{pid,state,sent_lsn,write_lsn,flush_lsn,replay_lsn,write_lag,flush_lag,replay_lag,sync_priority,sync_state,reply_time}',
52465246
prosrc => 'pg_stat_get_wal_senders' },
52475247
{ oid => '3317', descr => 'statistics: information about WAL receiver',
52485248
proname => 'pg_stat_get_wal_receiver', proisstrict => 'f', provolatile => 's',

src/include/replication/reorderbuffer.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,6 @@ struct ReorderBuffer
413413

414414
/* memory accounting */
415415
Size size;
416-
417-
/*
418-
* Statistics about transactions spilled to disk.
419-
*
420-
* A single transaction may be spilled repeatedly, which is why we keep
421-
* two different counters. For spilling, the transaction counter includes
422-
* both toplevel transactions and subtransactions.
423-
*/
424-
int64 spillCount; /* spill-to-disk invocation counter */
425-
int64 spillTxns; /* number of transactions spilled to disk */
426-
int64 spillBytes; /* amount of data spilled to disk */
427416
};
428417

429418

src/include/replication/walsender_private.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ typedef struct WalSnd
7878
* Timestamp of the last message received from standby.
7979
*/
8080
TimestampTz replyTime;
81-
82-
/* Statistics for transactions spilled to disk. */
83-
int64 spillTxns;
84-
int64 spillCount;
85-
int64 spillBytes;
8681
} WalSnd;
8782

8883
extern WalSnd *MyWalSnd;

src/test/regress/expected/rules.out

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,12 +2002,9 @@ pg_stat_replication| SELECT s.pid,
20022002
w.replay_lag,
20032003
w.sync_priority,
20042004
w.sync_state,
2005-
w.reply_time,
2006-
w.spill_txns,
2007-
w.spill_count,
2008-
w.spill_bytes
2005+
w.reply_time
20092006
FROM ((pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, sslcompression, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc, leader_pid)
2010-
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time, spill_txns, spill_count, spill_bytes) ON ((s.pid = w.pid)))
2007+
JOIN pg_stat_get_wal_senders() w(pid, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, write_lag, flush_lag, replay_lag, sync_priority, sync_state, reply_time) ON ((s.pid = w.pid)))
20112008
LEFT JOIN pg_authid u ON ((s.usesysid = u.oid)));
20122009
pg_stat_slru| SELECT s.name,
20132010
s.blks_zeroed,

0 commit comments

Comments
 (0)