public inbox for [email protected]help / color / mirror / Atom feed
[PATCH v10] Avoid creating archive status ".ready" files too early. 38+ messages / 15 participants [nested] [flat]
* [PATCH v10] Avoid creating archive status ".ready" files too early. @ 2021-08-17 03:52 Nathan Bossart <[email protected]> 0 siblings, 0 replies; 38+ messages in thread From: Nathan Bossart @ 2021-08-17 03:52 UTC (permalink / raw) WAL records may span multiple segments, but XLogWrite() does not wait for the entire record to be written out to disk before creating archive status files. Instead, as soon as the last WAL page of the segment is written, the archive status file will be created. If PostgreSQL crashes before it is able to write the rest of the record, it will end up reusing segments that have already been marked as ready-for-archival. However, the archiver process may have already processed the old version of the segment, so the wrong version of the segment may be backed-up. This backed-up segment will cause operations such as point-in-time restores to fail. To fix this, we keep track of records that span across segments and ensure that segments are only marked ready-for-archival once such records have been completely written to disk. --- src/backend/access/transam/timeline.c | 2 +- src/backend/access/transam/xlog.c | 291 ++++++++++++++++++++++- src/backend/access/transam/xlogarchive.c | 17 +- src/backend/postmaster/walwriter.c | 7 + src/backend/replication/walreceiver.c | 6 +- src/backend/storage/lmgr/lwlocknames.txt | 1 + src/include/access/xlog.h | 1 + src/include/access/xlogarchive.h | 4 +- src/include/access/xlogdefs.h | 1 + src/tools/pgindent/typedefs.list | 1 + 10 files changed, 309 insertions(+), 22 deletions(-) diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c index 8d0903c175..acd5c2431d 100644 --- a/src/backend/access/transam/timeline.c +++ b/src/backend/access/transam/timeline.c @@ -452,7 +452,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI, if (XLogArchivingActive()) { TLHistoryFileName(histfname, newTLI); - XLogArchiveNotify(histfname); + XLogArchiveNotify(histfname, true); } } diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index e51a7a749d..d2ccf2a7bb 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -512,6 +512,16 @@ typedef enum ExclusiveBackupState */ static SessionBackupState sessionBackupState = SESSION_BACKUP_NONE; +/* + * Entries for SegmentBoundaryMap. Each such entry represents a WAL + * record that ends in endpos and crosses a WAL segment boundary. + */ +typedef struct SegmentBoundaryEntry +{ + XLogSegNo seg; /* must be first */ + XLogRecPtr endpos; +} SegmentBoundaryEntry; + /* * Shared state data for WAL insertion. */ @@ -723,6 +733,12 @@ typedef struct XLogCtlData */ XLogRecPtr lastFpwDisableRecPtr; + /* + * The last segment we've marked ready for archival. Protected by + * info_lck. + */ + XLogSegNo lastNotifiedSeg; + slock_t info_lck; /* locks shared variables shown above */ } XLogCtlData; @@ -736,6 +752,12 @@ static WALInsertLockPadded *WALInsertLocks = NULL; */ static ControlFileData *ControlFile = NULL; +/* + * Segment boundary map, used for marking segments as ready for archival. + * Protected by SegmentBoundaryLock. + */ +static HTAB *SegmentBoundaryMap = NULL; + /* * Calculate the amount of space left on the page after 'endptr'. Beware * multiple evaluation! @@ -962,6 +984,13 @@ static XLogRecPtr XLogBytePosToRecPtr(uint64 bytepos); static XLogRecPtr XLogBytePosToEndRecPtr(uint64 bytepos); static uint64 XLogRecPtrToBytePos(XLogRecPtr ptr); static void checkXLogConsistency(XLogReaderState *record); +static void RegisterSegmentBoundaryEntry(XLogSegNo seg, XLogRecPtr pos); +static XLogSegNo GetLastNotifiedSegment(void); +static void SetLastNotifiedSegment(XLogSegNo seg); +static bool GetLatestSegmentBoundary(XLogSegNo last_notified, + XLogRecPtr flushed, + XLogSegNo *latest_boundary_seg); +static void RemoveSegmentBoundariesUpTo(XLogSegNo seg); static void WALInsertLockAcquire(void); static void WALInsertLockAcquireExclusive(void); @@ -1158,6 +1187,9 @@ XLogInsertRecord(XLogRecData *rdata, */ if (StartPos / XLOG_BLCKSZ != EndPos / XLOG_BLCKSZ) { + XLogSegNo StartSeg; + XLogSegNo EndSeg; + SpinLockAcquire(&XLogCtl->info_lck); /* advance global request to include new block(s) */ if (XLogCtl->LogwrtRqst.Write < EndPos) @@ -1165,12 +1197,38 @@ XLogInsertRecord(XLogRecData *rdata, /* update local result copy while I have the chance */ LogwrtResult = XLogCtl->LogwrtResult; SpinLockRelease(&XLogCtl->info_lck); + + /* + * If we crossed the segment boundary, record it. This is used to + * ensure that segments are not marked ready for archival before the + * entire record has been flushed to disk. + * + * Note that we do not use XLByteToPrevSeg() for determining the + * ending segment. This is done so that a record that fits perfectly + * into the end of the segment is marked ready for archival as soon as + * the flushed pointer jumps to the next segment. + */ + XLByteToSeg(StartPos, StartSeg, wal_segment_size); + XLByteToSeg(EndPos, EndSeg, wal_segment_size); + + if (StartSeg != EndSeg && XLogArchivingActive()) + { + RegisterSegmentBoundaryEntry(EndSeg, EndPos); + + /* + * There's a chance that the record was already flushed to disk + * and we missed marking segments as ready for archive. If this + * happens, we nudge the WALWriter, which will take care of + * notifying segments as needed. + */ + if (LogwrtResult.Flush > EndPos && ProcGlobal->walwriterLatch) + SetLatch(ProcGlobal->walwriterLatch); + } } /* * If this was an XLOG_SWITCH record, flush the record and the empty - * padding space that fills the rest of the segment, and perform - * end-of-segment actions (eg, notifying archiver). + * padding space that fills the rest of the segment. */ if (isLogSwitch) { @@ -1264,6 +1322,192 @@ XLogInsertRecord(XLogRecData *rdata, return EndPos; } +/* + * RegisterSegmentBoundaryEntry + * + * This enters a new entry into the segment boundary map, which is used for + * determing when it is safe to mark a segment as ready for archival. An entry + * with the given key (the segment number) must not already exist in the map. + * Also, the caller is responsible for ensuring that XLByteToSeg() would return + * the same segment number for the given record pointer. + */ +static void +RegisterSegmentBoundaryEntry(XLogSegNo seg, XLogRecPtr pos) +{ + SegmentBoundaryEntry *entry; + bool found; + + LWLockAcquire(SegmentBoundaryLock, LW_EXCLUSIVE); + + entry = (SegmentBoundaryEntry *) hash_search(SegmentBoundaryMap, + (void *) &seg, HASH_ENTER, + &found); + if (found) + elog(ERROR, "entry for segment already exists"); + + entry->endpos = pos; + + LWLockRelease(SegmentBoundaryLock); +} + +/* + * NotifySegmentsReadyForArchive + * + * This function marks segments as ready for archival, given that it is safe to + * do so. It is safe to call this function repeatedly, even if nothing has + * changed since the last time it was called. + */ +void +NotifySegmentsReadyForArchive(XLogRecPtr flushRecPtr) +{ + XLogSegNo flushed_seg; + XLogSegNo latest_boundary_seg; + XLogSegNo last_notified; + + /* + * We first do a quick sanity check to see if we can bail out without + * taking the SegmentBoundaryLock at all. It is expected that this + * function will run frequently and that it will need to do nothing the + * vast majority of the time. + * + * Specifically, we bail out if we've already marked the segment prior to + * the segment that contains flushRecPtr as ready for archival. We + * intentionally use XLByteToSeg() instead of XLByteToPrevSeg() so that we + * don't skip notifying when a record fits perfectly into the end of a + * segment. (flushRecPtr should point to the first byte of the record + * _after_ the one that is known to be flushed to disk.) + */ + last_notified = GetLastNotifiedSegment(); + XLByteToSeg(flushRecPtr, flushed_seg, wal_segment_size); + if (last_notified >= flushed_seg - 1) + return; + + LWLockAcquire(SegmentBoundaryLock, LW_EXCLUSIVE); + + /* Reobtain lastNotifiedSeg in case someone else changed it. */ + last_notified = GetLastNotifiedSegment(); + + /* Retrieve the latest segment boundary to use for notifying segments. */ + if (GetLatestSegmentBoundary(last_notified, flushRecPtr, &latest_boundary_seg)) + { + /* + * Update shared memory and discard segment boundaries that are no + * longer needed. + * + * It is safe to update shared memory before we attempt to create the + * .ready files. If our calls to XLogArchiveNotifySeg() fail, + * RemoveOldXlogFiles() will retry it as needed. + */ + SetLastNotifiedSegment(latest_boundary_seg - 1); + RemoveSegmentBoundariesUpTo(latest_boundary_seg); + + LWLockRelease(SegmentBoundaryLock); + + /* + * Notify archiver about segments that are ready for archival (by + * creating the corresponding .ready files). + */ + for (XLogSegNo seg = last_notified + 1; seg < latest_boundary_seg; seg++) + XLogArchiveNotifySeg(seg, false); + + PgArchWakeup(); + } + else + LWLockRelease(SegmentBoundaryLock); +} + +/* + * GetLatestSegmentBoundary + * + * This function finds the latest segment boundary in SegmentBoundaryMap that is + * less than or equal to the given "flushed" pointer and beyond the last + * notified segment. If such a segment is found, latest_boundary_seg is + * populated and true is returned. Otherwise, false is returned. + */ +static bool +GetLatestSegmentBoundary(XLogSegNo last_notified, XLogRecPtr flushed, + XLogSegNo *latest_boundary_seg) +{ + XLogSegNo flushed_seg; + XLogSegNo seg; + + Assert(LWLockHeldByMe(SegmentBoundaryLock)); + Assert(latest_boundary_seg != NULL); + + XLByteToSeg(flushed, flushed_seg, wal_segment_size); + + for (seg = flushed_seg; seg > last_notified; seg--) + { + SegmentBoundaryEntry *entry; + + entry = (SegmentBoundaryEntry *) hash_search(SegmentBoundaryMap, + (void *) &seg, HASH_FIND, + NULL); + + if (entry != NULL && flushed >= entry->endpos) + { + *latest_boundary_seg = entry->seg; + return true; + } + } + + return false; +} + +/* + * RemoveSegmentBoundariesUpTo + * + * This function removes all entries in the SegmentBoundaryMap with segment + * numbers up to and including seg. + */ +static void +RemoveSegmentBoundariesUpTo(XLogSegNo seg) +{ + SegmentBoundaryEntry *entry; + HASH_SEQ_STATUS status; + + Assert(LWLockHeldByMeInMode(SegmentBoundaryLock, LW_EXCLUSIVE)); + + hash_seq_init(&status, SegmentBoundaryMap); + + while ((entry = (SegmentBoundaryEntry *) hash_seq_search(&status)) != NULL) + { + if (entry->seg <= seg) + (void) hash_search(SegmentBoundaryMap, (void *) &entry->seg, + HASH_REMOVE, NULL); + } +} + +/* + * GetLastNotifiedSegment + * + * Retrieves last notified segment from shared memory. + */ +XLogSegNo +GetLastNotifiedSegment(void) +{ + XLogSegNo seg; + + SpinLockAcquire(&XLogCtl->info_lck); + seg = XLogCtl->lastNotifiedSeg; + SpinLockRelease(&XLogCtl->info_lck); + + return seg; +} + +/* + * SetLastNotifiedSegment + * + * Sets last notified segment in shared memory. + */ +static void +SetLastNotifiedSegment(XLogSegNo seg) +{ + SpinLockAcquire(&XLogCtl->info_lck); + XLogCtl->lastNotifiedSeg = seg; + SpinLockRelease(&XLogCtl->info_lck); +} + /* * Reserves the right amount of space for a record of given size from the WAL. * *StartPos is set to the beginning of the reserved section, *EndPos to @@ -2421,6 +2665,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) /* We should always be inside a critical section here */ Assert(CritSectionCount > 0); + Assert(LWLockHeldByMe(WALWriteLock)); /* * Update local LogwrtResult (caller probably did this already, but...) @@ -2586,11 +2831,13 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) * later. Doing it here ensures that one and only one backend will * perform this fsync. * - * This is also the right place to notify the Archiver that the - * segment is ready to copy to archival storage, and to update the - * timer for archive_timeout, and to signal for a checkpoint if - * too many logfile segments have been used since the last - * checkpoint. + * If WAL archiving is active, we attempt to notify the archiver + * of any segments that are now ready for archival. + * + * This is also the right place to update the timer for + * archive_timeout and to signal for a checkpoint if too many + * logfile segments have been used since the last checkpoint. + * */ if (finishing_seg) { @@ -2602,7 +2849,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) LogwrtResult.Flush = LogwrtResult.Write; /* end of page */ if (XLogArchivingActive()) - XLogArchiveNotifySeg(openLogSegNo); + NotifySegmentsReadyForArchive(LogwrtResult.Flush); XLogCtl->lastSegSwitchTime = (pg_time_t) time(NULL); XLogCtl->lastSegSwitchLSN = LogwrtResult.Flush; @@ -2690,6 +2937,9 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) XLogCtl->LogwrtRqst.Flush = LogwrtResult.Flush; SpinLockRelease(&XLogCtl->info_lck); } + + if (XLogArchivingActive()) + NotifySegmentsReadyForArchive(LogwrtResult.Flush); } /* @@ -5117,6 +5367,9 @@ XLOGShmemSize(void) /* and the buffers themselves */ size = add_size(size, mul_size(XLOG_BLCKSZ, XLOGbuffers)); + /* stuff for marking segments as ready for archival */ + size = add_size(size, hash_estimate_size(16, sizeof(SegmentBoundaryEntry))); + /* * Note: we don't count ControlFileData, it comes out of the "slop factor" * added by CreateSharedMemoryAndSemaphores. This lets us use this @@ -5134,6 +5387,7 @@ XLOGShmemInit(void) char *allocptr; int i; ControlFileData *localControlFile; + HASHCTL info; #ifdef WAL_DEBUG @@ -5227,12 +5481,20 @@ XLOGShmemInit(void) XLogCtl->InstallXLogFileSegmentActive = false; XLogCtl->SharedPromoteIsTriggered = false; XLogCtl->WalWriterSleeping = false; + XLogCtl->lastNotifiedSeg = MaxXLogSegNo; SpinLockInit(&XLogCtl->Insert.insertpos_lck); SpinLockInit(&XLogCtl->info_lck); SpinLockInit(&XLogCtl->ulsn_lck); InitSharedLatch(&XLogCtl->recoveryWakeupLatch); ConditionVariableInit(&XLogCtl->recoveryNotPausedCV); + + /* Initialize stuff for marking segments as ready for archival. */ + memset(&info, 0, sizeof(info)); + info.keysize = sizeof(XLogSegNo); + info.entrysize = sizeof(SegmentBoundaryEntry); + SegmentBoundaryMap = ShmemInitHash("Segment Boundary Table", 16, 16, &info, + HASH_ELEM | HASH_BLOBS); } /* @@ -7873,6 +8135,17 @@ StartupXLOG(void) XLogCtl->LogwrtRqst.Write = EndOfLog; XLogCtl->LogwrtRqst.Flush = EndOfLog; + /* + * Initialize XLogCtl->lastNotifiedSeg to the previous WAL file. + */ + if (XLogArchivingActive()) + { + XLogSegNo EndOfLogSeg; + + XLByteToSeg(EndOfLog, EndOfLogSeg, wal_segment_size); + SetLastNotifiedSegment(EndOfLogSeg - 1); + } + /* * Update full_page_writes in shared memory and write an XLOG_FPW_CHANGE * record before resource manager writes cleanup WAL records or checkpoint @@ -8000,7 +8273,7 @@ StartupXLOG(void) XLogArchiveCleanup(partialfname); durable_rename(origpath, partialpath, ERROR); - XLogArchiveNotify(partialfname); + XLogArchiveNotify(partialfname, true); } } } diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c index 26b023e754..b9c19b2085 100644 --- a/src/backend/access/transam/xlogarchive.c +++ b/src/backend/access/transam/xlogarchive.c @@ -433,7 +433,7 @@ KeepFileRestoredFromArchive(const char *path, const char *xlogfname) if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS) XLogArchiveForceDone(xlogfname); else - XLogArchiveNotify(xlogfname); + XLogArchiveNotify(xlogfname, true); /* * If the existing file was replaced, since walsenders might have it open, @@ -462,9 +462,12 @@ KeepFileRestoredFromArchive(const char *path, const char *xlogfname) * by the archiver, e.g. we write 0000000100000001000000C6.ready * and the archiver then knows to archive XLOGDIR/0000000100000001000000C6, * then when complete, rename it to 0000000100000001000000C6.done + * + * Optionally, nudge the archiver process so that it'll notice the file we + * create. */ void -XLogArchiveNotify(const char *xlog) +XLogArchiveNotify(const char *xlog, bool nudge) { char archiveStatusPath[MAXPGPATH]; FILE *fd; @@ -489,8 +492,8 @@ XLogArchiveNotify(const char *xlog) return; } - /* Notify archiver that it's got something to do */ - if (IsUnderPostmaster) + /* If caller requested, let archiver know it's got work to do */ + if (nudge) PgArchWakeup(); } @@ -498,12 +501,12 @@ XLogArchiveNotify(const char *xlog) * Convenience routine to notify using segment number representation of filename */ void -XLogArchiveNotifySeg(XLogSegNo segno) +XLogArchiveNotifySeg(XLogSegNo segno, bool nudge) { char xlog[MAXFNAMELEN]; XLogFileName(xlog, ThisTimeLineID, segno, wal_segment_size); - XLogArchiveNotify(xlog); + XLogArchiveNotify(xlog, nudge); } /* @@ -608,7 +611,7 @@ XLogArchiveCheckDone(const char *xlog) return true; /* Retry creation of the .ready file */ - XLogArchiveNotify(xlog); + XLogArchiveNotify(xlog, true); return false; } diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c index 626fae8454..6a1e16edc2 100644 --- a/src/backend/postmaster/walwriter.c +++ b/src/backend/postmaster/walwriter.c @@ -248,6 +248,13 @@ WalWriterMain(void) /* Process any signals received recently */ HandleWalWriterInterrupts(); + /* + * Notify the archiver of any WAL segments that are ready. We do this + * here to handle a race condition where WAL is flushed to disk prior + * to registering the segment boundary. + */ + NotifySegmentsReadyForArchive(GetFlushRecPtr()); + /* * Do what we're here for; then, if XLogBackgroundFlush() found useful * work to do, reset hibernation counter. diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 9a2bc37fd7..60de3be92c 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -622,7 +622,7 @@ WalReceiverMain(void) if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS) XLogArchiveForceDone(xlogfname); else - XLogArchiveNotify(xlogfname); + XLogArchiveNotify(xlogfname, true); } recvFile = -1; @@ -760,7 +760,7 @@ WalRcvFetchTimeLineHistoryFiles(TimeLineID first, TimeLineID last) if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS) XLogArchiveForceDone(fname); else - XLogArchiveNotify(fname); + XLogArchiveNotify(fname, true); pfree(fname); pfree(content); @@ -915,7 +915,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr) if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS) XLogArchiveForceDone(xlogfname); else - XLogArchiveNotify(xlogfname); + XLogArchiveNotify(xlogfname, true); } recvFile = -1; diff --git a/src/backend/storage/lmgr/lwlocknames.txt b/src/backend/storage/lmgr/lwlocknames.txt index 6c7cf6c295..14a742d655 100644 --- a/src/backend/storage/lmgr/lwlocknames.txt +++ b/src/backend/storage/lmgr/lwlocknames.txt @@ -53,3 +53,4 @@ XactTruncationLock 44 # 45 was XactTruncationLock until removal of BackendRandomLock WrapLimitsVacuumLock 46 NotifyQueueTailLock 47 +SegmentBoundaryLock 48 diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 0a8ede700d..6b6ae81c2d 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -315,6 +315,7 @@ extern XLogRecPtr GetInsertRecPtr(void); extern XLogRecPtr GetFlushRecPtr(void); extern XLogRecPtr GetLastImportantRecPtr(void); extern void RemovePromoteSignalFiles(void); +extern void NotifySegmentsReadyForArchive(XLogRecPtr flushRecPtr); extern bool PromoteIsTriggered(void); extern bool CheckPromoteSignal(void); diff --git a/src/include/access/xlogarchive.h b/src/include/access/xlogarchive.h index 3edd1a976c..935b4cb02d 100644 --- a/src/include/access/xlogarchive.h +++ b/src/include/access/xlogarchive.h @@ -23,8 +23,8 @@ extern bool RestoreArchivedFile(char *path, const char *xlogfname, extern void ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOnSignal); extern void KeepFileRestoredFromArchive(const char *path, const char *xlogfname); -extern void XLogArchiveNotify(const char *xlog); -extern void XLogArchiveNotifySeg(XLogSegNo segno); +extern void XLogArchiveNotify(const char *xlog, bool nudge); +extern void XLogArchiveNotifySeg(XLogSegNo segno, bool nudge); extern void XLogArchiveForceDone(const char *xlog); extern bool XLogArchiveCheckDone(const char *xlog); extern bool XLogArchiveIsBusy(const char *xlog); diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h index 60348d1850..9b455e88e3 100644 --- a/src/include/access/xlogdefs.h +++ b/src/include/access/xlogdefs.h @@ -46,6 +46,7 @@ typedef uint64 XLogRecPtr; * XLogSegNo - physical log file sequence number. */ typedef uint64 XLogSegNo; +#define MaxXLogSegNo ((XLogSegNo) 0xFFFFFFFFFFFFFFFF) /* * TimeLineID (TLI) - identifies different database histories to prevent diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 37cf4b2f76..79694b049e 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -2334,6 +2334,7 @@ SecBufferDesc SecLabelItem SecLabelStmt SeenRelsEntry +SegmentBoundaryEntry SelectLimit SelectStmt Selectivity -- 2.30.2 --aabamu5eazcf6rc5-- ^ permalink raw reply [nested|flat] 38+ messages in thread
* Built-in Raft replication @ 2025-04-14 17:15 Konstantin Osipov <[email protected]> 0 siblings, 3 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-14 17:15 UTC (permalink / raw) To: [email protected] Hi, I am considering starting work on implementing a built-in Raft replication for PostgreSQL. Raft's advantage is that it unifies log replication, cluster configuration/membership/topology management and initial state transfer into a single protocol. Currently the cluster configuration/topology is often managed by Patroni, or similar tools, however, it seems there are certain usability drawbacks with this approach: - it's a separate tool, requiring an external state provider like etcd; raft could store its configuration in system tables; this is also an observability improvement since everyone could look up cluster state the same way as everything else - same for watchdog; raft has a built-in failure detector that's configuration aware; - flexible quorums; currently quorum size is a configurable; with a built-in raft, extending the quorum could be a matter of starting a new node and pointing it to an existing cluster Going forward I can see PostgreSQL providing transparent bouncing on pg_wire level, given that Raft state is now part of the system, so drivers and all cluster nodes could easily see where the leader is. If anyone is working on Raft already I'd be happy to discuss the details. I am fairly new to the PostgreSQL hackers ecosystem so cautious of starting work in isolation/knowing there is no interest in accepting the feature into the trunk. Thanks, -- Konstantin Osipov ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-14 17:44 Kirill Reshke <[email protected]> parent: Konstantin Osipov <[email protected]> 2 siblings, 2 replies; 38+ messages in thread From: Kirill Reshke @ 2025-04-14 17:44 UTC (permalink / raw) To: Konstantin Osipov <[email protected]>; +Cc: [email protected] On Mon, 14 Apr 2025 at 22:15, Konstantin Osipov <[email protected]> wrote: > > Hi, Hi > I am considering starting work on implementing a built-in Raft > replication for PostgreSQL. > Just some thought on top of my mind, if you need my voice here: I have a hard time believing the community will be positive about this change in-core. It has more changes as contrib extension. In fact, if we want a built-in consensus algorithm, Paxos is a better option, because you can use postgresql as local crash-safe storage for single decree paxos, just store your state (ballot number, last voice) in a heap table. OTOH Raft needs to write its own log, and what's worse, it sometimes needs to remove already written parts of it (so, it is not appended only, unlike WAL). If you have a production system which maintains two kinds of logs with different semantics, it is a very hard system to maintain.. There is actually a prod-ready (non open source) implementation of RAFT as extension, called BiHA, by pgpro. Just some thought on top of my mind, if you need my voice here. -- Best regards, Kirill Reshke ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-14 19:00 Konstantin Osipov <[email protected]> parent: Kirill Reshke <[email protected]> 1 sibling, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-14 19:00 UTC (permalink / raw) To: Kirill Reshke <[email protected]>; +Cc: [email protected] * Kirill Reshke <[email protected]> [25/04/14 20:48]: > > I am considering starting work on implementing a built-in Raft > > replication for PostgreSQL. > > > > Just some thought on top of my mind, if you need my voice here: > > I have a hard time believing the community will be positive about this > change in-core. It has more changes as contrib extension. In fact, if > we want a built-in consensus algorithm, Paxos is a better option, > because you can use postgresql as local crash-safe storage for single > decree paxos, just store your state (ballot number, last voice) in a > heap table. But Raft is a log replication algorithm, not a consensus algorithm. It does use consensus, but that's for leader election. Paxos could be used for log replication, but that would be expensive. In fact etcd uses Raft, and etcd is used by Patroni. So I completely lost your line of thought here. > OTOH Raft needs to write its own log, and what's worse, it sometimes > needs to remove already written parts of it (so, it is not appended > only, unlike WAL). If you have a production system which maintains two > kinds of logs with different semantics, it is a very hard system to > maintain.. My proposal is exactly to replace (or rather, extend) the current synchronous log replication with Raft. Entry removal is possible to stack on top of append-only format, and production implementations exist which do that. So, no, it's a single log, and in fact the current WAL will do. > There is actually a prod-ready (non open source) implementation of > RAFT as extension, called BiHA, by pgpro. My guess biha is an extension since a proprietary code is easier to maintain that way. I'd rather say the fact that there is a proprietary implementation out in the field confirms it could be a good idea to have it in PostgreSQL trunk. In any case I'm interested in contributing to the trunk, not building a proprietary module/fork. -- Konstantin Osipov ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 10:20 Aleksander Alekseev <[email protected]> parent: Konstantin Osipov <[email protected]> 2 siblings, 3 replies; 38+ messages in thread From: Aleksander Alekseev @ 2025-04-15 10:20 UTC (permalink / raw) To: Konstantin Osipov <[email protected]>; +Cc: [email protected] Hi Konstantin, > I am considering starting work on implementing a built-in Raft > replication for PostgreSQL. Generally speaking I like the idea. The more important question IMO is whether we want to maintain Raft within the PostgreSQL core project. Building distributed systems on commodity hardware was a popular idea back in the 2000s. These days you can rent a server with 2 Tb of RAM for something like 2000 USD/month (numbers from my memory that were valid ~5 years ago) which will fit many of the existing businesses (!) in memory. And you can rent another one for a replica, just in order not to recover from a backup if something happens to your primary server. The common wisdom is if you can avoid building distributed systems, don't build one. Which brings the question if we want to maintain something like this (which will include logic for cases when a node joins or leaves the cluster, proxy server / service discovery for clients, test cases / infrastructure for all this and also upgrading the cluster, docs, ...) for a presumably view users which business doesn't fit in a single server *and* they want an automatic failover (not the manual one) *and* they don't use Patroni/Stolon/CockroachDB/Neon/... already. Although the idea is tempting personally I'm inclined to think that it's better to invest community resources into something else. -- Best regards, Aleksander Alekseev ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 11:14 Konstantin Osipov <[email protected]> parent: Kirill Reshke <[email protected]> 1 sibling, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-15 11:14 UTC (permalink / raw) To: Yura Sokolov <[email protected]>; +Cc: Kirill Reshke <[email protected]>; [email protected] * Yura Sokolov <[email protected]> [25/04/15 12:02]: > > OTOH Raft needs to write its own log, and what's worse, it sometimes > > needs to remove already written parts of it (so, it is not appended > > only, unlike WAL). If you have a production system which maintains two > > kinds of logs with different semantics, it is a very hard system to > > maintain.. > > Raft is log replication protocol which uses log position and term. > But... PostgreSQL already have log position and term in its WAL structure. > PostgreSQL's timeline is actually the Term. > Raft implementer needs just to correct rules for Term/Timeline switching: > - instead of "next TimeLine number is just increment of largest known > TimeLine number" it needs to be "next TimeLine number is the result of > Leader Election". > > And yes, "it sometimes needs to remove already written parts of it". > But... It is exactly what every PostgreSQL's cluster manager software have > to do to join previous leader as a follower to new leader - pg_rewind. > > So, PostgreSQL already have 70-90%% of Raft implementation details. > Raft doesn't have to be implemented in PostgreSQL. > Raft has to be finished!!! > > PS: One of the biggest issues is forced snapshot on replica promotion. It > really slows down leader switch time. It looks like it is not really > needed, or some small workaround should be enough. I'd say my pet peeve is storing the cluster topology (the so called raft configuration) inside the database, not in an external state provider. Agree on other points. -- Konstantin Osipov ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 11:15 Aleksander Alekseev <[email protected]> parent: Aleksander Alekseev <[email protected]> 2 siblings, 1 reply; 38+ messages in thread From: Aleksander Alekseev @ 2025-04-15 11:15 UTC (permalink / raw) To: [email protected]; +Cc: Yura Sokolov <[email protected]>; Konstantin Osipov <[email protected]> Hi Yura, > I've been working in a company which uses MongoDB (3.6 and up) as their > primary storage. And it seemed to me as "God Send". Everything just worked. > Replication was as reliable as one could imagine. It outlives several > hardware incidents without manual intervention. It allowed cluster > maintenance (software and hardware upgrades) without application downtime. > I really dream PostgreSQL will be as reliable as MongoDB without need of > external services. I completely understand. I had exactly the same experience with Stolon. Everything just worked. And the setup took like 5 minutes. It's a pity this project doesn't seem to get as much attention as Patroni. Probably because attention requires traveling and presenting the project at conferences which costs money. Or perhaps people are just happy with Patroni. I'm not sure in which state Stolon is today. -- Best regards, Aleksander Alekseev ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 11:20 Yura Sokolov <[email protected]> parent: Aleksander Alekseev <[email protected]> 0 siblings, 0 replies; 38+ messages in thread From: Yura Sokolov @ 2025-04-15 11:20 UTC (permalink / raw) To: Aleksander Alekseev <[email protected]>; [email protected]; +Cc: Konstantin Osipov <[email protected]> 15.04.2025 14:15, Aleksander Alekseev пишет: > Hi Yura, > >> I've been working in a company which uses MongoDB (3.6 and up) as their >> primary storage. And it seemed to me as "God Send". Everything just worked. >> Replication was as reliable as one could imagine. It outlives several >> hardware incidents without manual intervention. It allowed cluster >> maintenance (software and hardware upgrades) without application downtime. >> I really dream PostgreSQL will be as reliable as MongoDB without need of >> external services. > > I completely understand. I had exactly the same experience with > Stolon. Everything just worked. And the setup took like 5 minutes. > > It's a pity this project doesn't seem to get as much attention as > Patroni. Probably because attention requires traveling and presenting > the project at conferences which costs money. Or perhaps people are > just happy with Patroni. I'm not sure in which state Stolon is today. But the key point: if PostgreSQL will be improved a bit, there will be no need neither in Patroni, nor in Stolon. Isn't it great? -- regards Yura Sokolov aka funny-falcon ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 11:23 Konstantin Osipov <[email protected]> parent: Aleksander Alekseev <[email protected]> 2 siblings, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-15 11:23 UTC (permalink / raw) To: Aleksander Alekseev <[email protected]>; +Cc: [email protected] * Aleksander Alekseev <[email protected]> [25/04/15 13:20]: > > I am considering starting work on implementing a built-in Raft > > replication for PostgreSQL. > > Generally speaking I like the idea. The more important question IMO is > whether we want to maintain Raft within the PostgreSQL core project. > > Building distributed systems on commodity hardware was a popular idea > back in the 2000s. These days you can rent a server with 2 Tb of RAM > for something like 2000 USD/month (numbers from my memory that were > valid ~5 years ago) which will fit many of the existing businesses (!) > in memory. And you can rent another one for a replica, just in order > not to recover from a backup if something happens to your primary > server. The common wisdom is if you can avoid building distributed > systems, don't build one. > > Which brings the question if we want to maintain something like this > (which will include logic for cases when a node joins or leaves the > cluster, proxy server / service discovery for clients, test cases / > infrastructure for all this and also upgrading the cluster, docs, ...) > for a presumably view users which business doesn't fit in a single > server *and* they want an automatic failover (not the manual one) > *and* they don't use Patroni/Stolon/CockroachDB/Neon/... already. > > Although the idea is tempting personally I'm inclined to think that > it's better to invest community resources into something else. My personal take away from this as a community member would be seamless coordinator failover in Greenplum and all of its forks (CloudBerry, Greengage, synxdata, what not). I also imagine there is a number of PostgreSQL derivatives that could benefit from built-in transparent failover since it standardizes the solution space. -- Konstantin Osipov ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 11:24 Konstantin Osipov <[email protected]> parent: Aleksander Alekseev <[email protected]> 2 siblings, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-15 11:24 UTC (permalink / raw) To: Yura Sokolov <[email protected]>; +Cc: Aleksander Alekseev <[email protected]>; [email protected] * Yura Sokolov <[email protected]> [25/04/15 14:02]: > I've been working in a company which uses MongoDB (3.6 and up) as their > primary storage. And it seemed to me as "God Send". Everything just worked. > Replication was as reliable as one could imagine. It outlives several > hardware incidents without manual intervention. It allowed cluster > maintenance (software and hardware upgrades) without application downtime. > I really dream PostgreSQL will be as reliable as MongoDB without need of > external services. thanks for pointing out mongodb, so built-in raft would help ferretdb as well. -- Konstantin Osipov ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 15:07 Greg Sabino Mullane <[email protected]> parent: Konstantin Osipov <[email protected]> 2 siblings, 2 replies; 38+ messages in thread From: Greg Sabino Mullane @ 2025-04-15 15:07 UTC (permalink / raw) To: Konstantin Osipov <[email protected]>; +Cc: [email protected] On Mon, Apr 14, 2025 at 1:15 PM Konstantin Osipov <[email protected]> wrote: > If anyone is working on Raft already I'd be happy to discuss > the details. I am fairly new to the PostgreSQL hackers ecosystem > so cautious of starting work in isolation/knowing there is no > interest in accepting the feature into the trunk. > Putting aside the technical concerns about this specific idea, it's best to start by laying out a very detailed plan of what you would want to change, and what you see as the costs and benefits. It's also extremely helpful to think about developing this as an extension. If you get stuck due to extension limitations, propose additional hooks. If the hooks will not work, explain why. Getting this into core is going to be a long, multi-year effort, in which people are going to be pushing back the entire time, so prepare yourself for that. My immediate retort is going to be: why would we add this if there are existing tools that already do the job just fine? Postgres has lots of tasks that it is happy to let other programs/OS subsystems/extensions/etc. handle instead. Cheers, Greg -- Crunchy Data - https://www.crunchydata.com Enterprise Postgres Software Products & Tech Support ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 17:27 Konstantin Osipov <[email protected]> parent: Greg Sabino Mullane <[email protected]> 1 sibling, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-15 17:27 UTC (permalink / raw) To: Greg Sabino Mullane <[email protected]>; +Cc: [email protected] * Greg Sabino Mullane <[email protected]> [25/04/15 18:08]: > > If anyone is working on Raft already I'd be happy to discuss > > the details. I am fairly new to the PostgreSQL hackers ecosystem > > so cautious of starting work in isolation/knowing there is no > > interest in accepting the feature into the trunk. > > > > Putting aside the technical concerns about this specific idea, it's best to > start by laying out a very detailed plan of what you would want to change, > and what you see as the costs and benefits. It's also extremely helpful to > think about developing this as an extension. If you get stuck due to > extension limitations, propose additional hooks. If the hooks will not > work, explain why. > > Getting this into core is going to be a long, multi-year effort, in which > people are going to be pushing back the entire time, so prepare yourself > for that. My immediate retort is going to be: why would we add this if > there are existing tools that already do the job just fine? Postgres has > lots of tasks that it is happy to let other programs/OS > subsystems/extensions/etc. handle instead. I had hoped I explained why external state providers can not provide the same seamless UX as built-in ones. The key idea is to have a built-in configuration management, so that adding and removing replicas does not require changes in multiple disjoint parts of the installation (server configurations, proxies, clients). I understand and accept that it's a multi-year effort, but I do not accept the retort - my main point is that external tools are not a replacement, and I'd like to reach consensus on that. -- Konstantin Osipov, Moscow, Russia ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-15 22:27 Nikolay Samokhvalov <[email protected]> parent: Greg Sabino Mullane <[email protected]> 1 sibling, 7 replies; 38+ messages in thread From: Nikolay Samokhvalov @ 2025-04-15 22:27 UTC (permalink / raw) To: Greg Sabino Mullane <[email protected]>; +Cc: Konstantin Osipov <[email protected]>; [email protected] On Tue, Apr 15, 2025 at 8:08 AM Greg Sabino Mullane <[email protected]> wrote: > On Mon, Apr 14, 2025 at 1:15 PM Konstantin Osipov <[email protected]> > wrote: > >> If anyone is working on Raft already I'd be happy to discuss >> the details. I am fairly new to the PostgreSQL hackers ecosystem >> so cautious of starting work in isolation/knowing there is no >> interest in accepting the feature into the trunk. >> > > Putting aside the technical concerns about this specific idea, it's best > to start by laying out a very detailed plan of what you would want to > change, and what you see as the costs and benefits. It's also extremely > helpful to think about developing this as an extension. If you get stuck > due to extension limitations, propose additional hooks. If the hooks will > not work, explain why. > This is exactly what I wanted to write as well. The idea is great. At the same time, I think, consensus on many decisions will be extremely hard to reach, so this project has a high risk of being very long. Unless it's an extension, at least in the beginning. Nik ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 04:58 Andrey Borodin <[email protected]> parent: Nikolay Samokhvalov <[email protected]> 6 siblings, 1 reply; 38+ messages in thread From: Andrey Borodin @ 2025-04-16 04:58 UTC (permalink / raw) To: Ashutosh Bapat <[email protected]>; +Cc: Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> > On 16 Apr 2025, at 09:33, Ashutosh Bapat <[email protected]> wrote: > > In my experience, the load of managing hundreds of replicas which all > participate in RAFT protocol becomes more than regular transaction > load. So making every replica a RAFT participant will affect the > ability to deploy hundreds of replica. No need to make all standbys voting. And no need to make plain topology. pg_consul is using 2/3 or 3/5 HA groups, and cascades all others from HA group. Existing tools already solve the original problem, Konstantin is just proposing to solve it in some standard “official” way. > We may build an extension which > has a similar role in PostgreSQL world as zookeeper in Hadoop. Patroni, pg_consul and others already use zookeeper, etcd and similar systems for consensus. Is it any better as extension than as etcd? > It can > be then used for other distributed systems as well - like shared > nothing clusters based on FDW. I didn’t get FDW analogy. Why other distributed systems should choose Postgres extension over Zookeeper? > There's already a proposal to bring > CREATE SERVER to the world of logical replication - so I see these two > worlds uniting in future. Again, I’m lost here. Which two worlds? > The way I imagine it is some PostgreSQL > instances, which have this extension installed, will act as a RAFT > cluster (similar to Zookeeper ensemble or etcd cluster). That’s exactly what is proposed here. > The > distributed system based on logical replication or FDW or both will > use this ensemble to manage its shared state. The same ensemble can be > shared across multiple distributed clusters if it has scaling > capabilities. Yes, shared DCS are common these days. AFAIK, we use one Zookeeper instance per hundred Postgres clusters to coordinate pg_consuls. Actually, scalability is opposite to topic of this thread. Let me explain. Currently, Postgres automatic failover tools rely on databases with built-in automatic failover. Konstantin is proposing to shorten this loop and make Postgres use its build-in automatic failover. So, existing tooling allows you to have 3 hosts for DCS, with majority of 2 hosts able to elect new leader in case of failover. And you can have only 2 hosts for Postgres - Primary and Standby. You can have 2 big Postgres machines with 64 CPUs. And 3 one-CPU hosts for Zookeper\etcd. If you use build-in failover you have to resort to 3 big Postgres machines because you need 2/3 majority. Of course, you can install MySQL-stype arbiter - host that had no real PGDATA, only participates in voting. But this is a solution to problem induced by built-in autofailover. Best regards, Andrey Borodin. ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 05:39 Kirill Reshke <[email protected]> parent: Nikolay Samokhvalov <[email protected]> 6 siblings, 1 reply; 38+ messages in thread From: Kirill Reshke @ 2025-04-16 05:39 UTC (permalink / raw) To: Andrey Borodin <[email protected]>; +Cc: Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> On Wed, 16 Apr 2025 at 10:25, Andrey Borodin <[email protected]> wrote: > > I think I can provide some reasons why it cannot be neither extension, nor any part running within postmaster reign. > > 1. When joining cluster, there’s not PGDATA to run postmaster on top of it. You can join the cluster on pg_basebackup of its master; So I dont get why this is an anti-extension restriction. > 2. After failover, old Primary node must rejoin cluster by running pg_rewind and following timeline switch. You can run bash from extension, what's the point? > The system in hand must be able to manipulate with PGDATA without starting Postgres. -- Best regards, Kirill Reshke ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 05:44 Andrey Borodin <[email protected]> parent: Kirill Reshke <[email protected]> 0 siblings, 1 reply; 38+ messages in thread From: Andrey Borodin @ 2025-04-16 05:44 UTC (permalink / raw) To: Kirill Reshke <[email protected]>; +Cc: Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> > On 16 Apr 2025, at 10:39, Kirill Reshke <[email protected]> wrote: > > You can run bash from extension, what's the point? You cannot run bash that will stop backend running bash. Best regards, Andrey Borodin. ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 06:18 Ashutosh Bapat <[email protected]> parent: Andrey Borodin <[email protected]> 0 siblings, 3 replies; 38+ messages in thread From: Ashutosh Bapat @ 2025-04-16 06:18 UTC (permalink / raw) To: Andrey Borodin <[email protected]>; +Cc: Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> On Wed, Apr 16, 2025 at 10:29 AM Andrey Borodin <[email protected]> wrote: > > > We may build an extension which > > has a similar role in PostgreSQL world as zookeeper in Hadoop. > > Patroni, pg_consul and others already use zookeeper, etcd and similar systems for consensus. > Is it any better as extension than as etcd? I feel so. An extension runs from within a postgresql process, uses the same protocol as PostgreSQL whereas etcd is another process and another protocol. > > > It can > > be then used for other distributed systems as well - like shared > > nothing clusters based on FDW. > > I didn’t get FDW analogy. Why other distributed systems should choose Postgres extension over Zookeeper? By other distributed systems I mean PostgreSQL distributed systems - FDW based native sharding or native replication or a system which uses both. > > > There's already a proposal to bring > > CREATE SERVER to the world of logical replication - so I see these two > > worlds uniting in future. > > Again, I’m lost here. Which two worlds? Logical replication and FDW based native sharding. > > > The > > distributed system based on logical replication or FDW or both will > > use this ensemble to manage its shared state. The same ensemble can be > > shared across multiple distributed clusters if it has scaling > > capabilities. > > Yes, shared DCS are common these days. AFAIK, we use one Zookeeper instance per hundred Postgres clusters to coordinate pg_consuls. > > Actually, scalability is opposite to topic of this thread. Let me explain. > Currently, Postgres automatic failover tools rely on databases with built-in automatic failover. Konstantin is proposing to shorten this loop and make Postgres use its build-in automatic failover. > > So, existing tooling allows you to have 3 hosts for DCS, with majority of 2 hosts able to elect new leader in case of failover. > And you can have only 2 hosts for Postgres - Primary and Standby. You can have 2 big Postgres machines with 64 CPUs. And 3 one-CPU hosts for Zookeper\etcd. > > If you use build-in failover you have to resort to 3 big Postgres machines because you need 2/3 majority. Of course, you can install MySQL-stype arbiter - host that had no real PGDATA, only participates in voting. But this is a solution to problem induced by built-in autofailover. Users find it a waste of resources to deploy 3 big PostgreSQL instances just for HA where 2 suffice even if they deploy 3 lightweight DCS instances. Having only some of the nodes act as DCS and others purely PostgreSQL nodes will reduce waste of resources. -- Best Wishes, Ashutosh Bapat ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 06:27 Andrey Borodin <[email protected]> parent: Ashutosh Bapat <[email protected]> 2 siblings, 1 reply; 38+ messages in thread From: Andrey Borodin @ 2025-04-16 06:27 UTC (permalink / raw) To: Ashutosh Bapat <[email protected]>; +Cc: Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> > On 16 Apr 2025, at 11:18, Ashutosh Bapat <[email protected]> wrote: > > Having only some of the nodes act as DCS > and others purely PostgreSQL nodes will reduce waste of resources. But typically you need more DCS nodes than PostgreSQL nodes. Did you mean “Having only some of nodes act as PostgreSQL and others purely DCS nodes will reduce waste of resources”? Best regards, Andrey Borodin. ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 06:45 Ashutosh Bapat <[email protected]> parent: Andrey Borodin <[email protected]> 0 siblings, 0 replies; 38+ messages in thread From: Ashutosh Bapat @ 2025-04-16 06:45 UTC (permalink / raw) To: Andrey Borodin <[email protected]>; +Cc: Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> On Wed, Apr 16, 2025 at 11:57 AM Andrey Borodin <[email protected]> wrote: > > > > > On 16 Apr 2025, at 11:18, Ashutosh Bapat <[email protected]> wrote: > > > > Having only some of the nodes act as DCS > > and others purely PostgreSQL nodes will reduce waste of resources. > > But typically you need more DCS nodes than PostgreSQL nodes. Did you mean In a small HA setup this might be true. But not when there are many replicas. But ... > “Having only some nodes act as PostgreSQL and others purely DCS nodes will reduce waste of resources”? I mean, whatever the setup may be one shouldn't require to deploy a big PostgreSQL server just because DCS needs majority. -- Best Wishes, Ashutosh Bapat ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 09:47 Konstantin Osipov <[email protected]> parent: Nikolay Samokhvalov <[email protected]> 6 siblings, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-16 09:47 UTC (permalink / raw) To: Tom Lane <[email protected]>; +Cc: Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; [email protected] * Tom Lane <[email protected]> [25/04/16 11:05]: > Nikolay Samokhvalov <[email protected]> writes: > > This is exactly what I wanted to write as well. The idea is great. At the > > same time, I think, consensus on many decisions will be extremely hard to > > reach, so this project has a high risk of being very long. Unless it's an > > extension, at least in the beginning. > > Yeah. The two questions you'd have to get past to get this into PG > core are: > > 1. Why can't it be an extension? (You claimed it would work more > seamlessly in core, but I don't think you've made a proven case.) I think this can be best addressed when the discussion moves on to an architecture design record, where the UX and implementation details are outlined. I'm sure there can be a lot of bike-shedding on that part. For now I merely wanted to know if: - maybe there is a reason this will never be accepted - maybe someone is already working on this. ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 09:53 Konstantin Osipov <[email protected]> parent: Nikolay Samokhvalov <[email protected]> 6 siblings, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-16 09:53 UTC (permalink / raw) To: Ashutosh Bapat <[email protected]>; +Cc: Andrey Borodin <[email protected]>; Tom Lane <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; [email protected] * Ashutosh Bapat <[email protected]> [25/04/16 11:06]: > > My view is what Konstantin wants is automatic replication topology management. For some reason this technology is called HA, DCS, Raft, Paxos and many other scary words. But basically it manages primary_conn_info of some nodes to provide some fault-tolerance properties. I'd start to design from here, not from Raft paper. > > > In my experience, the load of managing hundreds of replicas which all > participate in RAFT protocol becomes more than regular transaction > load. So making every replica a RAFT participant will affect the > ability to deploy hundreds of replica. I think this experience needs to be detailed out. There are implementations in the field that are less efficient than others. Early etcd-raft didn't have pre-voting and had "bastardized" (their own definition) implementation of configuration changes which didn't use joint consensus. Then there is a liveness issue if leader election is implemented in a straightforward way in large clusters. But this is addressed: scaling up the randomized election timeout with the cluster size, converting most of participants to non-voters in large clusters. Raft replication, again, if implemented in a naive way, would require a O(outstanding transaction) * number of replicas amount of RAM. But that doesn't have to be naive. To sum up, I am not aware of any principal limitations in this area. -- Konstantin Osipov, Moscow, Russia ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 09:58 Konstantin Osipov <[email protected]> parent: Nikolay Samokhvalov <[email protected]> 6 siblings, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-16 09:58 UTC (permalink / raw) To: Andrey Borodin <[email protected]>; +Cc: Tom Lane <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> * Andrey Borodin <[email protected]> [25/04/16 11:06]: > > Andrey Borodin <[email protected]> writes: > >> I think it's what Konstantin is proposing. To have our own Raft implementation, without dependencies. > > > > Hmm, OK. I thought that the proposal involved relying on some existing > > code, but re-reading the thread that was said nowhere. Still, that > > moves it from a large project to a really large project :-( > > > > I continue to think that it'd be best to try to implement it as > > an extension, at least up till the point of finding show-stopping > > reasons why it cannot be that. > > I think I can provide some reasons why it cannot be neither extension, nor any part running within postmaster reign. > > 1. When joining cluster, there’s not PGDATA to run postmaster on top of it. > > 2. After failover, old Primary node must rejoin cluster by running pg_rewind and following timeline switch. > > The system in hand must be able to manipulate with PGDATA without starting Postgres. > > My question to Konstantin is Why wouldn’t you just add Raft to Patroni? Is there a reason why something like Patroni is not in core and noone rushes to get it in? > Everyone is using it, or system like it. Raft uses the same WAL to store configuration change records as is used for commit records. This is at the core of the correctness of the algorithm. This is also my biggest concern with correctness of Patroni - but to the best of my knowledge 's 90%+ of use cases of Patroni use a "fixed" quorum size, that's defined at start of the deployment and never/rarely changes. Contrast to that being able to a replica to the quorum at any time, and all it takes is just starting this replica and pointing it at the existing cluster. This greatly simplifies UX. -- Konstantin Osipov, Moscow, Russia ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 10:02 Konstantin Osipov <[email protected]> parent: Andrey Borodin <[email protected]> 0 siblings, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-16 10:02 UTC (permalink / raw) To: Andrey Borodin <[email protected]>; +Cc: Kirill Reshke <[email protected]>; Tom Lane <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> * Andrey Borodin <[email protected]> [25/04/16 11:06]: > > You can run bash from extension, what's the point? > > You cannot run bash that will stop backend running bash. You're right there is a chicken and egg problem when you add Raft to an existing project, and rebootstrap becomes a trick, but it's a plumbing trick. The new member needs to generate and persist a globally unique identifier as the first step. Later it can reintroduce itself to the cluster given this identifier can be preserved in the new incarnation (popen + fork). -- Konstantin Osipov, Moscow, Russia ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 12:53 Alastair Turner <[email protected]> parent: Ashutosh Bapat <[email protected]> 2 siblings, 1 reply; 38+ messages in thread From: Alastair Turner @ 2025-04-16 12:53 UTC (permalink / raw) To: Ashutosh Bapat <[email protected]>; +Cc: Andrey Borodin <[email protected]>; Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> On Wed, 16 Apr 2025 at 07:18, Ashutosh Bapat <[email protected]> wrote: > On Wed, Apr 16, 2025 at 10:29 AM Andrey Borodin <[email protected]> > wrote: > > > > If you use build-in failover you have to resort to 3 big Postgres > machines because you need 2/3 majority. Of course, you can install > MySQL-stype arbiter - host that had no real PGDATA, only participates in > voting. But this is a solution to problem induced by built-in autofailover. > > Users find it a waste of resources to deploy 3 big PostgreSQL > instances just for HA where 2 suffice even if they deploy 3 > lightweight DCS instances. Having only some of the nodes act as DCS > and others purely PostgreSQL nodes will reduce waste of resources. > > The experience of other projects/products with automated failover based on quorum shows that this is a critical issue for adoption. In the In-memory Data Grid space (Coherence, Geode/GemFire) the question of how to ensure that some nodes didn't carry any data comes up early in many architecture discussions. When RabbitMQ shipped their Quorum Queues feature, the first and hardest area of pushback was around all nodes hosting message content. It's not just about the requirement for compute resources, it's also about bandwidth and latency. Many large organisations have, for historical reasons, pairs of data centres with very good point-to-point connectivity. As the requirement for quorum witnesses has come up for all sorts of things, including storage arrays, they have built arbiter/witness sites at branches, colocation providers or even on the public cloud. More than not holding user data or processing queries, the arbiter can't even be sent the replication stream for the user data in the database, it just won't fit down the pipe. Which feels like a very difficult requirement to meet if the replication model for all data is being changed to a quorum model. Regards Alastair ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 14:07 Konstantin Osipov <[email protected]> parent: Alastair Turner <[email protected]> 0 siblings, 1 reply; 38+ messages in thread From: Konstantin Osipov @ 2025-04-16 14:07 UTC (permalink / raw) To: Alastair Turner <[email protected]>; +Cc: Ashutosh Bapat <[email protected]>; Andrey Borodin <[email protected]>; Tom Lane <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> * Alastair Turner <[email protected]> [25/04/16 15:58]: > > > If you use build-in failover you have to resort to 3 big Postgres > > machines because you need 2/3 majority. Of course, you can install > > MySQL-stype arbiter - host that had no real PGDATA, only participates in > > voting. But this is a solution to problem induced by built-in autofailover. > > > > Users find it a waste of resources to deploy 3 big PostgreSQL > > instances just for HA where 2 suffice even if they deploy 3 > > lightweight DCS instances. Having only some of the nodes act as DCS > > and others purely PostgreSQL nodes will reduce waste of resources. > > > > The experience of other projects/products with automated failover based on > quorum shows that this is a critical issue for adoption. In the In-memory > Data Grid space (Coherence, Geode/GemFire) the question of how to ensure > that some nodes didn't carry any data comes up early in many architecture > discussions. When RabbitMQ shipped their Quorum Queues feature, the first > and hardest area of pushback was around all nodes hosting message content. > > It's not just about the requirement for compute resources, it's also about > bandwidth and latency. Many large organisations have, for historical > reasons, pairs of data centres with very good point-to-point connectivity. > As the requirement for quorum witnesses has come up for all sorts of > things, including storage arrays, they have built arbiter/witness sites at > branches, colocation providers or even on the public cloud. More than not > holding user data or processing queries, the arbiter can't even be sent the > replication stream for the user data in the database, it just won't fit > down the pipe. > > Which feels like a very difficult requirement to meet if the replication > model for all data is being changed to a quorum model. I agree master/replica deployment layouts are very popular and are not going to directly benefit from raft. They'll still work, but no automation will be available, just like today with Patroni. However, if the storage cost is an argument, then the logical path is to disaggregate storage/compute altogether, i.e. use projects like neon. -- Konstantin Osipov, Moscow, Russia ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 14:29 Yura Sokolov <[email protected]> parent: Nikolay Samokhvalov <[email protected]> 6 siblings, 0 replies; 38+ messages in thread From: Yura Sokolov @ 2025-04-16 14:29 UTC (permalink / raw) To: Andrey Borodin <[email protected]>; Tom Lane <[email protected]>; +Cc: Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> 16.04.2025 08:24, Andrey Borodin пишет: > 2. After failover, old Primary node must rejoin cluster by running pg_rewind and following timeline switch. It is really do-able: BiHA already does it. And BiHA runs as a child process of postmaster, ie both postmaster and BiHA doesn't restart when PostgreSQL needs to rewind and restart. Yes, there are non-trivial amount of changes made into postmaster machinery. But it is doable. -- regards Yura Sokolov aka funny-falcon ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 19:29 Greg Sabino Mullane <[email protected]> parent: Ashutosh Bapat <[email protected]> 2 siblings, 2 replies; 38+ messages in thread From: Greg Sabino Mullane @ 2025-04-16 19:29 UTC (permalink / raw) To: Ashutosh Bapat <[email protected]>; +Cc: Andrey Borodin <[email protected]>; Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> On Wed, Apr 16, 2025 at 2:18 AM Ashutosh Bapat <[email protected]> wrote: > Users find it a waste of resources to deploy 3 big PostgreSQL instances > just for HA where 2 suffice even if they deploy 3 lightweight DCS > instances. Having only some of the nodes act as DCS and others purely > PostgreSQL nodes will reduce waste of resources. > A big problem is that putting your DCS into Postgres means your whole system is now super-sensitive to IO/WAL-streaming issues, and a busy database doing database stuff is going to start affecting the DCS stuff. With three lightweight DCS servers, you don't really need to worry about how stressed the database servers are. In that way, I feel etcd et al. are adhering to the unix philosophy of "do one thing, and do it well." Cheers, Greg -- Crunchy Data - https://www.crunchydata.com Enterprise Postgres Software Products & Tech Support ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 19:35 Konstantin Osipov <[email protected]> parent: Greg Sabino Mullane <[email protected]> 1 sibling, 0 replies; 38+ messages in thread From: Konstantin Osipov @ 2025-04-16 19:35 UTC (permalink / raw) To: Greg Sabino Mullane <[email protected]>; +Cc: Ashutosh Bapat <[email protected]>; Andrey Borodin <[email protected]>; Tom Lane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> * Greg Sabino Mullane <[email protected]> [25/04/16 22:33]: > > Users find it a waste of resources to deploy 3 big PostgreSQL instances > > just for HA where 2 suffice even if they deploy 3 lightweight DCS > > instances. Having only some of the nodes act as DCS and others purely > > PostgreSQL nodes will reduce waste of resources. > > > > A big problem is that putting your DCS into Postgres means your whole > system is now super-sensitive to IO/WAL-streaming issues, and a busy > database doing database stuff is going to start affecting the DCS stuff. Affecting in what way? Do you have a scenario in mind where an external state provider would act differently (better)? > With three lightweight DCS servers, you don't really need to worry about > how stressed the database servers are. In that way, I feel etcd et al. are > adhering to the unix philosophy of "do one thing, and do it well." -- Konstantin Osipov, Moscow, Russia ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 21:24 Hannu Krosing <[email protected]> parent: Nikolay Samokhvalov <[email protected]> 6 siblings, 0 replies; 38+ messages in thread From: Hannu Krosing @ 2025-04-16 21:24 UTC (permalink / raw) To: Tom Lane <[email protected]>; +Cc: Andrey Borodin <[email protected]>; Konstantin Osipov <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; [email protected] On Wed, Apr 16, 2025 at 6:27 AM Tom Lane <[email protected]> wrote: > > Andrey Borodin <[email protected]> writes: > > I think it's what Konstantin is proposing. To have our own Raft implementation, without dependencies. > > Hmm, OK. I thought that the proposal involved relying on some existing > code, but re-reading the thread that was said nowhere. Still, that > moves it from a large project to a really large project :-( My understanding is that RAFT is a fancy name for what PostgreSQL is largely already doing - "electing" a leader and then doing all the changes through that leader (a.k.a. WAL streaming) The thing that needs adding - and which makes it "RAFT" instead of just a streaming replication with a failover - is what happens when the leader goes away and one of the replicas needs to become a new leader. We have ways to do rollbacks and roll-forwards but the main tricky part is "how do you know that you have not lost some changes" and here we must have some place to store the info about at which LSN the failover happened, so that we know to run pg_rewind if any losts hosts come back and want to join. And of course we need to have a way to communicate this "who is the new leader" to clients which needs new libpgq functionality of "failover connection pools" which hide the failovers from old clients. The RAFT protocol could be a provider of "who is current leader info" and optionally cache the LSN the switch happened. > I continue to think that it'd be best to try to implement it as > an extension, at least up till the point of finding show-stopping > reasons why it cannot be that. The main thing I would like to see in core is ability to do clean *switchovers* (not failovers) by sending a magic WAL record with a message "hey node N, please take over the write node role" over WAL so that node N knows to self-promote and all other nodes know to start following N starting from the next WAL record either directly or Why WAL - because it is already is sent to all replicas, it guarantees continuity as it very clearly states at what LSN the write-head-switch happens. We also should be able to send this info to the client libraries currently connected to the writer. so that they can choose to switch to the new head. The rest could be easily an extension. Mainly we want more than one "coordinators" which can be running in some or all of the nodes.and who agree on - which node is current leader - at which LSN the switch happened (so if some node coming back discovers that it has magicall moved ahead it knows to rewind to that LSN and then re-stream it from commonly agreed place. It would also be nice to have some agreed, hopefully lightweight, notion of node identity, which we could then use for many things, including stamping it in WAL records to guarantee / verify that all the nodes have been on the same WAL stream all the time But regarding weather to use RAFT I would just define a "coordinator API" and leave it up to the specific coordinator/consensus extension to decide how the consensus is achieved So to summarize: # Core should provide - way tomove to new node, - for switchover a WAL-based switchover - for failover something similar which also writes the WAL record so all histories are synced - a libpq message informing clients about "new write head node" - node IDs and more general c;luster-awareness inside the PostgreSQL node (I had a shoutout about this in a recent pgconf.dev unconference talk) - a new write-node field in WAL to track write head movement - API for a joining node to find out which cluster it joins and the switchover history - in WAL it is always switchover, maybe with some info saying that it was a forces switchover because we lost old write head - if some lost node comes back it may need to rewind or re-initialize if it finds out it had been following a lost timeline that is not fully part of NOTE: switchovers in WAL would be very similar to timeline changes. I am not sure how much extra info is needed there. # Extension can provide - agreeing on new leader node in case of failover - protocol can be RAFT, PAXOS or "the DBA says so" :) - sharing fresh info about current leader and switch timelines (though this should more likely be in core) - anything else ??? # external apps is (likely?) needed for - setting up cluster, provisioning machines / VMs - setting up networking - starting PostgreSQL servers. - spinning up and down clients, - communicating current leader and replica set (could be done by DNS with agreed conventions) ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-16 21:45 Alastair Turner <[email protected]> parent: Konstantin Osipov <[email protected]> 0 siblings, 0 replies; 38+ messages in thread From: Alastair Turner @ 2025-04-16 21:45 UTC (permalink / raw) To: Konstantin Osipov <[email protected]>; +Cc: Ashutosh Bapat <[email protected]>; Andrey Borodin <[email protected]>; Tom Lane <[email protected]>; Greg Sabino Mullane <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> Hi Konstantin On Wed, 16 Apr 2025 at 15:07, Konstantin Osipov <[email protected]> wrote: > * Alastair Turner <[email protected]> [25/04/16 15:58]: > > > > > If you use build-in failover you have to resort to 3 big Postgres > > > machines because you need 2/3 majority. Of course, you can install > > > MySQL-stype arbiter - host that had no real PGDATA, only participates > in > > > voting. But this is a solution to problem induced by built-in > autofailover. > > > > > > Users find it a waste of resources to deploy 3 big PostgreSQL > > > instances just for HA where 2 suffice even if they deploy 3 > > > lightweight DCS instances. Having only some of the nodes act as DCS > > > and others purely PostgreSQL nodes will reduce waste of resources. > > > > > > The experience of other projects/products with automated failover > based on > > quorum shows that this is a critical issue for adoption. In the In-memory > > Data Grid space (Coherence, Geode/GemFire) the question of how to ensure > > that some nodes didn't carry any data comes up early in many architecture > > discussions. When RabbitMQ shipped their Quorum Queues feature, the first > > and hardest area of pushback was around all nodes hosting message > content. > > > > It's not just about the requirement for compute resources, it's also > about > > bandwidth and latency. Many large organisations have, for historical > > reasons, pairs of data centres with very good point-to-point > connectivity. > > As the requirement for quorum witnesses has come up for all sorts of > > things, including storage arrays, they have built arbiter/witness sites > at > > branches, colocation providers or even on the public cloud. More than not > > holding user data or processing queries, the arbiter can't even be sent > the > > replication stream for the user data in the database, it just won't fit > > down the pipe. > > > > Which feels like a very difficult requirement to meet if the replication > > model for all data is being changed to a quorum model. > > I agree master/replica deployment layouts are very popular and are > not going to directly benefit from raft. They'll still work, but no > automation will be available, just like today with Patroni. > > Users of Patroni and etcd setups can get automation for two-site primary/replica pairs by putting a third etcd node on a third site. Which only requires moving the membership/leadership data to the arbiter site, not all database activity. > However, if the storage cost is an argument, then the logical path is to > disaggregate storage/compute altogether, i.e. use projects like > neon. > > The issue is not generally storage, but network. There may simply not be enough bandwidth available to transmit the whole WAL to the arbiter site. Many on-premises IT setups have this limitation in some form. If your proposal would leave these large, traditional user organisations (which account for thousands of Postgres HA pairs or DR pairs) doing what they currently do with wraparound tooling like Patroni, and create a new, in core, option for balanced 3, 5, 7... member groups, then I don't think it's worth doing. Regards, Alastair ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: Built-in Raft replication @ 2025-04-29 20:16 Jim Nasby <[email protected]> parent: Greg Sabino Mullane <[email protected]> 1 sibling, 0 replies; 38+ messages in thread From: Jim Nasby @ 2025-04-29 20:16 UTC (permalink / raw) To: Devrim Gündüz <[email protected]>; +Cc: Greg Sabino Mullane <[email protected]>; Ashutosh Bapat <[email protected]>; Andrey Borodin <[email protected]>; Tom Lane <[email protected]>; Konstantin Osipov <[email protected]>; Nikolay Samokhvalov <[email protected]>; PostgreSQL Hackers <[email protected]> I've always assumed there'd have to be at least one global stream, if for no other purpose than to be the source of truth about transaction commit ordering (though, I was thinking of supporting multiple streams for one database). Presumably the same could be used for shared objects. Or perhaps shared objects just get their own stream. Either way, having a master commit record that points at LSNs of various other streams is what I'd been thinking. On Wed, Apr 23, 2025 at 12:01 PM Devrim Gündüz <[email protected]> wrote: > Hi, > > On Wed, 2025-04-23 at 11:48 -0500, Jim Nasby wrote: > > unless we added multiple WAL streams. That would allow for splitting > > WAL traffic across multiple devices as well as providing better > > support for configurations that don’t replicate the entire cluster. > > The current situation where delayed replication of a single table > > mandates retention of all the WAL for the entire cluster is less than > > ideal. > > I think the problem is handling the stream of global objects. Having > separate stream for each database would be awesome as long as it can > deal with the "global stream". > > Regards, > -- > Devrim Gündüz > Open Source Solution Architect, PostgreSQL Major Contributor > BlueSky: @devrim.gunduz.org , @gunduz.org > ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: use of SPI by postgresImportForeignStatistics @ 2026-07-10 05:03 Etsuro Fujita <[email protected]> 0 siblings, 1 reply; 38+ messages in thread From: Etsuro Fujita @ 2026-07-10 05:03 UTC (permalink / raw) To: Corey Huinker <[email protected]>; +Cc: Robert Haas <[email protected]>; pgsql-hackers On Wed, Jul 8, 2026 at 9:04 PM Etsuro Fujita <[email protected]> wrote: > Attached is a new version > of the patch. I'm planning to push and back-patch it, if no > objections. Committed and back-patched. Best regards, Etsuro Fujita ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: use of SPI by postgresImportForeignStatistics @ 2026-07-10 05:36 Fujii Masao <[email protected]> parent: Etsuro Fujita <[email protected]> 0 siblings, 1 reply; 38+ messages in thread From: Fujii Masao @ 2026-07-10 05:36 UTC (permalink / raw) To: Etsuro Fujita <[email protected]>; +Cc: Corey Huinker <[email protected]>; Robert Haas <[email protected]>; pgsql-hackers On Fri, Jul 10, 2026 at 2:03 PM Etsuro Fujita <[email protected]> wrote: > > On Wed, Jul 8, 2026 at 9:04 PM Etsuro Fujita <[email protected]> wrote: > > Attached is a new version > > of the patch. I'm planning to push and back-patch it, if no > > objections. > > Committed and back-patched. In the committed patch, I found that the set_*_arg() helper functions in postgres_fdw.c are declared static in their prototypes, but their definitions omit the static keyword. This looks like an oversight. Attached patch adds static to the definitions for consistency and to make their intended file-local scope explicit. It also fixes a few nearby comment typos. Regards, -- Fujii Masao Attachments: [application/octet-stream] v1-0001-postgres_fdw-Mark-statistics-import-helpers-as-st.patch (3.4K, ../../CAHGQGwGjcQ4SwHMUQ9P8UYQ7iLKL1QE3uLSdONToQ1MrzpUUoQ@mail.gmail.com/2-v1-0001-postgres_fdw-Mark-statistics-import-helpers-as-st.patch) download | inline diff: From f9793e5fe924b49e1cad93f7d33ed313283c51f7 Mon Sep 17 00:00:00 2001 From: Fujii Masao <[email protected]> Date: Fri, 10 Jul 2026 14:22:54 +0900 Subject: [PATCH v1] postgres_fdw: Mark statistics import helpers as static The set_*_arg helper functions in postgres_fdw.c are declared static, but their definitions omitted the static keyword. Add it to make their file-local scope explicit and keep the declarations and definitions consistent. Also fix a couple of nearby comment typos. --- contrib/postgres_fdw/postgres_fdw.c | 12 ++++++------ src/backend/statistics/attribute_stats.c | 2 +- src/backend/statistics/relation_stats.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index e6e0a4ab9b5..70de942de12 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -6134,7 +6134,7 @@ import_fetched_statistics(Relation relation, } /* - * Conenience routine to fetch the value for the row/column of the PGresult + * Convenience routine to fetch the value for the row/column of the PGresult */ static char * get_opt_value(PGresult *res, int row, int col) @@ -6147,7 +6147,7 @@ get_opt_value(PGresult *res, int row, int col) /* * Convenience routine for setting optional text arguments */ -void +static void set_text_arg(NullableDatum *arg, const char *s) { if (s) @@ -6165,7 +6165,7 @@ set_text_arg(NullableDatum *arg, const char *s) /* * Convenience routine for setting optional int32 arguments */ -void +static void set_int32_arg(NullableDatum *arg, const char *s) { if (s) @@ -6185,7 +6185,7 @@ set_int32_arg(NullableDatum *arg, const char *s) /* * Convenience routine for setting optional uint32 arguments */ -void +static void set_uint32_arg(NullableDatum *arg, const char *s) { if (s) @@ -6205,7 +6205,7 @@ set_uint32_arg(NullableDatum *arg, const char *s) /* * Convenience routine for setting optional float arguments */ -void +static void set_float_arg(NullableDatum *arg, const char *s) { if (s) @@ -6225,7 +6225,7 @@ set_float_arg(NullableDatum *arg, const char *s) /* * Convenience routine for setting optional float[] arguments */ -void +static void set_floatarr_arg(NullableDatum *arg, const char *s) { if (s) diff --git a/src/backend/statistics/attribute_stats.c b/src/backend/statistics/attribute_stats.c index 2efb74b95a6..48e0df391e2 100644 --- a/src/backend/statistics/attribute_stats.c +++ b/src/backend/statistics/attribute_stats.c @@ -708,7 +708,7 @@ pg_restore_attribute_stats(PG_FUNCTION_ARGS) } /* - * Import attribute statistics from NullableDatum inputs for all statitical + * Import attribute statistics from NullableDatum inputs for all statistical * values. * * For now, the 'version' argument is ignored. In the future it can be used diff --git a/src/backend/statistics/relation_stats.c b/src/backend/statistics/relation_stats.c index 990a7511d04..fbaab92284f 100644 --- a/src/backend/statistics/relation_stats.c +++ b/src/backend/statistics/relation_stats.c @@ -256,7 +256,7 @@ pg_restore_relation_stats(PG_FUNCTION_ARGS) } /* - * Import relation statistics from NullableDatum inputs for all statitical + * Import relation statistics from NullableDatum inputs for all statistical * values. * * For now, the 'version' argument is ignored. In the future it can be used -- 2.55.0 ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: use of SPI by postgresImportForeignStatistics @ 2026-07-10 07:40 Etsuro Fujita <[email protected]> parent: Fujii Masao <[email protected]> 0 siblings, 1 reply; 38+ messages in thread From: Etsuro Fujita @ 2026-07-10 07:40 UTC (permalink / raw) To: Fujii Masao <[email protected]>; +Cc: Corey Huinker <[email protected]>; Robert Haas <[email protected]>; pgsql-hackers Fujii-san, On Fri, Jul 10, 2026 at 2:37 PM Fujii Masao <[email protected]> wrote: > In the committed patch, I found that the set_*_arg() helper functions > in postgres_fdw.c are declared static in their prototypes, but their > definitions omit the static keyword. This looks like an oversight. > > Attached patch adds static to the definitions for consistency and > to make their intended file-local scope explicit. It also fixes a few > nearby comment typos. Good catch! Thanks for the patch! LGTM. Best regards, Etsuro Fujita ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: use of SPI by postgresImportForeignStatistics @ 2026-07-10 11:36 Etsuro Fujita <[email protected]> parent: Etsuro Fujita <[email protected]> 0 siblings, 2 replies; 38+ messages in thread From: Etsuro Fujita @ 2026-07-10 11:36 UTC (permalink / raw) To: Fujii Masao <[email protected]>; +Cc: Corey Huinker <[email protected]>; Robert Haas <[email protected]>; pgsql-hackers On Fri, Jul 10, 2026 at 4:40 PM Etsuro Fujita <[email protected]> wrote: > On Fri, Jul 10, 2026 at 2:37 PM Fujii Masao <[email protected]> wrote: > > In the committed patch, I found that the set_*_arg() helper functions > > in postgres_fdw.c are declared static in their prototypes, but their > > definitions omit the static keyword. This looks like an oversight. > > > > Attached patch adds static to the definitions for consistency and > > to make their intended file-local scope explicit. It also fixes a few > > nearby comment typos. > > Good catch! Thanks for the patch! LGTM. My compiler (Apple clang version 17.0.0 (clang-1700.4.4.1)) doesn't output any error/warning about that declaration. Actually, it's allowed? Anyway, +1 for adding it for consistency. Best regards, Etsuro Fujita ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: use of SPI by postgresImportForeignStatistics @ 2026-07-10 12:09 Fujii Masao <[email protected]> parent: Etsuro Fujita <[email protected]> 1 sibling, 0 replies; 38+ messages in thread From: Fujii Masao @ 2026-07-10 12:09 UTC (permalink / raw) To: Etsuro Fujita <[email protected]>; +Cc: Corey Huinker <[email protected]>; Robert Haas <[email protected]>; pgsql-hackers On Fri, Jul 10, 2026 at 8:37 PM Etsuro Fujita <[email protected]> wrote: > > On Fri, Jul 10, 2026 at 4:40 PM Etsuro Fujita <[email protected]> wrote: > > On Fri, Jul 10, 2026 at 2:37 PM Fujii Masao <[email protected]> wrote: > > > In the committed patch, I found that the set_*_arg() helper functions > > > in postgres_fdw.c are declared static in their prototypes, but their > > > definitions omit the static keyword. This looks like an oversight. > > > > > > Attached patch adds static to the definitions for consistency and > > > to make their intended file-local scope explicit. It also fixes a few > > > nearby comment typos. > > > > Good catch! Thanks for the patch! LGTM. > > My compiler (Apple clang version 17.0.0 (clang-1700.4.4.1)) doesn't > output any error/warning about that declaration. Actually, it's > allowed? Anyway, +1 for adding it for consistency. Maybe that's allowed. I wonder adding static to both the declaration and the definition seems mainly a matter of consistency, readability, and coding style. Thanks for the review! I've pushed the patch. Regards, -- Fujii Masao ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: use of SPI by postgresImportForeignStatistics @ 2026-07-10 14:08 Tom Lane <[email protected]> parent: Etsuro Fujita <[email protected]> 1 sibling, 1 reply; 38+ messages in thread From: Tom Lane @ 2026-07-10 14:08 UTC (permalink / raw) To: Etsuro Fujita <[email protected]>; +Cc: Fujii Masao <[email protected]>; Corey Huinker <[email protected]>; Robert Haas <[email protected]>; pgsql-hackers Etsuro Fujita <[email protected]> writes: > On Fri, Jul 10, 2026 at 4:40 PM Etsuro Fujita <[email protected]> wrote: >> On Fri, Jul 10, 2026 at 2:37 PM Fujii Masao <[email protected]> wrote: >>> Attached patch adds static to the definitions for consistency and >>> to make their intended file-local scope explicit. It also fixes a few >>> nearby comment typos. > My compiler (Apple clang version 17.0.0 (clang-1700.4.4.1)) doesn't > output any error/warning about that declaration. Actually, it's > allowed? Anyway, +1 for adding it for consistency. The back story here is that that coding pattern is allowed by standard C but traditionally (pre-ANSI C or so) wasn't. We used to have some buildfarm animals that would warn about it, but none do today. I think it's a good idea to include "static" in the definitions for clarity, and so that you don't have to go looking for the declaration to know if a function is file-local or not. But the standard doesn't require that. Rummaging in the gcc manual, it looks like you can turn on a warning for this with '-Wtraditional', but that also enables a boatload of warnings we don't want, so I can't see using it on a regular basis. regards, tom lane ^ permalink raw reply [nested|flat] 38+ messages in thread
* Re: use of SPI by postgresImportForeignStatistics @ 2026-07-10 14:41 Tom Lane <[email protected]> parent: Tom Lane <[email protected]> 0 siblings, 0 replies; 38+ messages in thread From: Tom Lane @ 2026-07-10 14:41 UTC (permalink / raw) To: Etsuro Fujita <[email protected]>; +Cc: Fujii Masao <[email protected]>; Corey Huinker <[email protected]>; Robert Haas <[email protected]>; pgsql-hackers I wrote: > Rummaging in the gcc manual, it looks like you can turn on a warning > for this with '-Wtraditional', but that also enables a boatload of > warnings we don't want, so I can't see using it on a regular basis. I experimented with that for fun. On current HEAD, it produces 347111 warnings, mostly "traditional C rejects ISO C style function definitions". But amongst the dross there's dbcommands.c:395:1: warning: non-static declaration of 'ScanSourceDatabasePgClassTuple' follows static declaration [-Wtraditional] event_trigger.c:392:1: warning: non-static declaration of 'SetDatabaseHasLoginEventTriggers' follows static declaration [-Wtraditional] tablecmds.c:20846:1: warning: non-static declaration of 'ConstraintImpliedByRelConstraint' follows static declaration [-Wtraditional] nodeModifyTable.c:4154:1: warning: non-static declaration of 'ExecInitMerge' follows static declaration [-Wtraditional] postmaster.c:4056:1: warning: non-static declaration of 'StartSysLogger' follows static declaration [-Wtraditional] buf_table.c:48:1: warning: non-static declaration of 'BufTableShmemRequest' follows static declaration [-Wtraditional] oracle_compat.c:555:1: warning: non-static declaration of 'dobyteatrim' follows static declaration [-Wtraditional] pg_locale_icu.c:746:1: warning: non-static declaration of 'strncoll_icu_utf8' follows static declaration [-Wtraditional] pg_locale_icu.c:767:1: warning: non-static declaration of 'strcoll_icu_utf8' follows static declaration [-Wtraditional] pg_walsummary.c:230:1: warning: non-static declaration of 'walsummary_error_callback' follows static declaration [-Wtraditional] pg_walsummary.c:245:1: warning: non-static declaration of 'walsummary_read_callback' follows static declaration [-Wtraditional] vacuumdb.c:327:1: warning: non-static declaration of 'check_objfilter' follows static declaration [-Wtraditional] if anyone cares to follow that up. regards, tom lane ^ permalink raw reply [nested|flat] 38+ messages in thread
end of thread, other threads:[~2026-07-10 14:41 UTC | newest] Thread overview: 38+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-08-17 03:52 [PATCH v10] Avoid creating archive status ".ready" files too early. Nathan Bossart <[email protected]> 2025-04-14 17:15 Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-14 17:44 ` Re: Built-in Raft replication Kirill Reshke <[email protected]> 2025-04-14 19:00 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-15 11:14 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-15 10:20 ` Re: Built-in Raft replication Aleksander Alekseev <[email protected]> 2025-04-15 11:15 ` Re: Built-in Raft replication Aleksander Alekseev <[email protected]> 2025-04-15 11:20 ` Re: Built-in Raft replication Yura Sokolov <[email protected]> 2025-04-15 11:23 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-15 11:24 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-15 15:07 ` Re: Built-in Raft replication Greg Sabino Mullane <[email protected]> 2025-04-15 17:27 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-15 22:27 ` Re: Built-in Raft replication Nikolay Samokhvalov <[email protected]> 2025-04-16 04:58 ` Re: Built-in Raft replication Andrey Borodin <[email protected]> 2025-04-16 06:18 ` Re: Built-in Raft replication Ashutosh Bapat <[email protected]> 2025-04-16 06:27 ` Re: Built-in Raft replication Andrey Borodin <[email protected]> 2025-04-16 06:45 ` Re: Built-in Raft replication Ashutosh Bapat <[email protected]> 2025-04-16 12:53 ` Re: Built-in Raft replication Alastair Turner <[email protected]> 2025-04-16 14:07 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-16 21:45 ` Re: Built-in Raft replication Alastair Turner <[email protected]> 2025-04-16 19:29 ` Re: Built-in Raft replication Greg Sabino Mullane <[email protected]> 2025-04-16 19:35 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-29 20:16 ` Re: Built-in Raft replication Jim Nasby <[email protected]> 2025-04-16 05:39 ` Re: Built-in Raft replication Kirill Reshke <[email protected]> 2025-04-16 05:44 ` Re: Built-in Raft replication Andrey Borodin <[email protected]> 2025-04-16 10:02 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-16 09:47 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-16 09:53 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-16 09:58 ` Re: Built-in Raft replication Konstantin Osipov <[email protected]> 2025-04-16 14:29 ` Re: Built-in Raft replication Yura Sokolov <[email protected]> 2025-04-16 21:24 ` Re: Built-in Raft replication Hannu Krosing <[email protected]> 2026-07-10 05:03 Re: use of SPI by postgresImportForeignStatistics Etsuro Fujita <[email protected]> 2026-07-10 05:36 ` Re: use of SPI by postgresImportForeignStatistics Fujii Masao <[email protected]> 2026-07-10 07:40 ` Re: use of SPI by postgresImportForeignStatistics Etsuro Fujita <[email protected]> 2026-07-10 11:36 ` Re: use of SPI by postgresImportForeignStatistics Etsuro Fujita <[email protected]> 2026-07-10 12:09 ` Re: use of SPI by postgresImportForeignStatistics Fujii Masao <[email protected]> 2026-07-10 14:08 ` Re: use of SPI by postgresImportForeignStatistics Tom Lane <[email protected]> 2026-07-10 14:41 ` Re: use of SPI by postgresImportForeignStatistics Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox