mirror of
https://github.com/postgres/postgres.git
synced 2026-03-04 06:10:57 -05:00
Previously, we'd compress only when the active range of array entries reached Max(4 * PROCARRAY_MAXPROCS, 2 * pArray->numKnownAssignedXids). If max_connections is large, the first term could result in not compressing for a long time, resulting in much wastage of cycles in hot-standby backends scanning the array to take snapshots. Get rid of that term, and just bound it to 2 * pArray->numKnownAssignedXids. That however creates the opposite risk, that we might spend too much effort compressing. Hence, consider compressing only once every 128 commit records. (This frequency was chosen by benchmarking. While we only tried one benchmark scenario, the results seem stable over a fairly wide range of frequencies.) Also, force compression when processing RecoveryInfo WAL records (which should be infrequent); the old code could perform compression then, but would do so only after the same array-range check as for the transaction-commit path. Also, opportunistically run compression if the startup process is about to wait for WAL, though not oftener than once a second. This should prevent cases where we waste lots of time by leaving the array not-compressed for long intervals due to low WAL traffic. Lastly, add a simple check to keep us from uselessly compressing when the array storage is already compact. Back-patch, as the performance problem is worse in pre-v14 branches than in HEAD. Simon Riggs and Michail Nikolaev, with help from Tom Lane and Andres Freund. Discussion: https://postgr.es/m/CALdSSPgahNUD_=pB_j=1zSnDBaiOtqVfzo8Ejt5J_k7qZiU1Tw@mail.gmail.com
99 lines
4 KiB
C
99 lines
4 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* procarray.h
|
|
* POSTGRES process array definitions.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/storage/procarray.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef PROCARRAY_H
|
|
#define PROCARRAY_H
|
|
|
|
#include "storage/lock.h"
|
|
#include "storage/standby.h"
|
|
#include "utils/relcache.h"
|
|
#include "utils/snapshot.h"
|
|
|
|
|
|
extern Size ProcArrayShmemSize(void);
|
|
extern void CreateSharedProcArray(void);
|
|
extern void ProcArrayAdd(PGPROC *proc);
|
|
extern void ProcArrayRemove(PGPROC *proc, TransactionId latestXid);
|
|
|
|
extern void ProcArrayEndTransaction(PGPROC *proc, TransactionId latestXid);
|
|
extern void ProcArrayClearTransaction(PGPROC *proc);
|
|
|
|
extern void ProcArrayInitRecovery(TransactionId initializedUptoXID);
|
|
extern void ProcArrayApplyRecoveryInfo(RunningTransactions running);
|
|
extern void ProcArrayApplyXidAssignment(TransactionId topxid,
|
|
int nsubxids, TransactionId *subxids);
|
|
|
|
extern void RecordKnownAssignedTransactionIds(TransactionId xid);
|
|
extern void ExpireTreeKnownAssignedTransactionIds(TransactionId xid,
|
|
int nsubxids, TransactionId *subxids,
|
|
TransactionId max_xid);
|
|
extern void ExpireAllKnownAssignedTransactionIds(void);
|
|
extern void ExpireOldKnownAssignedTransactionIds(TransactionId xid);
|
|
extern void KnownAssignedTransactionIdsIdleMaintenance(void);
|
|
|
|
extern int GetMaxSnapshotXidCount(void);
|
|
extern int GetMaxSnapshotSubxidCount(void);
|
|
|
|
extern Snapshot GetSnapshotData(Snapshot snapshot);
|
|
|
|
extern bool ProcArrayInstallImportedXmin(TransactionId xmin,
|
|
VirtualTransactionId *sourcevxid);
|
|
extern bool ProcArrayInstallRestoredXmin(TransactionId xmin, PGPROC *proc);
|
|
|
|
extern RunningTransactions GetRunningTransactionData(void);
|
|
|
|
extern bool TransactionIdIsInProgress(TransactionId xid);
|
|
extern bool TransactionIdIsActive(TransactionId xid);
|
|
extern TransactionId GetOldestNonRemovableTransactionId(Relation rel);
|
|
extern TransactionId GetOldestTransactionIdConsideredRunning(void);
|
|
extern TransactionId GetOldestActiveTransactionId(void);
|
|
extern TransactionId GetOldestSafeDecodingTransactionId(bool catalogOnly);
|
|
extern void GetReplicationHorizons(TransactionId *slot_xmin, TransactionId *catalog_xmin);
|
|
|
|
extern VirtualTransactionId *GetVirtualXIDsDelayingChkpt(int *nvxids, int type);
|
|
extern bool HaveVirtualXIDsDelayingChkpt(VirtualTransactionId *vxids,
|
|
int nvxids, int type);
|
|
|
|
extern PGPROC *BackendPidGetProc(int pid);
|
|
extern PGPROC *BackendPidGetProcWithLock(int pid);
|
|
extern int BackendXidGetPid(TransactionId xid);
|
|
extern bool IsBackendPid(int pid);
|
|
|
|
extern VirtualTransactionId *GetCurrentVirtualXIDs(TransactionId limitXmin,
|
|
bool excludeXmin0, bool allDbs, int excludeVacuum,
|
|
int *nvxids);
|
|
extern VirtualTransactionId *GetConflictingVirtualXIDs(TransactionId limitXmin, Oid dbOid);
|
|
extern pid_t CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode);
|
|
extern pid_t SignalVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode,
|
|
bool conflictPending);
|
|
|
|
extern bool MinimumActiveBackends(int min);
|
|
extern int CountDBBackends(Oid databaseid);
|
|
extern int CountDBConnections(Oid databaseid);
|
|
extern void CancelDBBackends(Oid databaseid, ProcSignalReason sigmode, bool conflictPending);
|
|
extern int CountUserBackends(Oid roleid);
|
|
extern bool CountOtherDBBackends(Oid databaseId,
|
|
int *nbackends, int *nprepared);
|
|
extern void TerminateOtherDBBackends(Oid databaseId);
|
|
|
|
extern void XidCacheRemoveRunningXids(TransactionId xid,
|
|
int nxids, const TransactionId *xids,
|
|
TransactionId latestXid);
|
|
|
|
extern void ProcArraySetReplicationSlotXmin(TransactionId xmin,
|
|
TransactionId catalog_xmin, bool already_locked);
|
|
|
|
extern void ProcArrayGetReplicationSlotXmin(TransactionId *xmin,
|
|
TransactionId *catalog_xmin);
|
|
|
|
#endif /* PROCARRAY_H */
|