Conversation
NingZhou-NZ
reviewed
Aug 10, 2026
O1eq
force-pushed
the
feat-add-treplica
branch
from
August 17, 2026 03:33
d1b7036 to
2acbb24
Compare
…ics, not Mimir Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
O1eq
force-pushed
the
feat-add-treplica
branch
from
August 27, 2026 23:15
2acbb24 to
5eb79fb
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new
bin/treplicacommand that creates and manages a PostgreSQL streaming read replica of any totara pgsql container. Its purpose is testing Totara's database read/write splitting feature ($CFG->dboptions['readonly']), which routes read queries to a read-only replica.treplica up [pgsqlNN]- clones the running primary withpg_basebackupinto a new volume and starts it as a hot standby (default service: pgsql16). Image,PGDATAand resource settings (max_connections,max_locks_per_transaction, ...) are derived from the running primary, so it works with any pgsql version/config without hardcoded values. Idempotent: re-running shows status, a stopped replica is restarted, a stale volume is refused with a hint. Ends by printing the ready-to-pasteconfig.phpblock (including a warning that it must be placed after theconfig-after.phpinclude, which reassigns$CFG->dboptions).treplica status- recovery check,pg_stat_replication, replication lag.treplica logs- follows the standby's statement log.treplica down- removes container + volume after confirmation and drop the replication slot if one was created.--port(publish on a host port),--slot(physical replication slot for bulk-load safety),--quiet-logs.Testing Instructions
pgsql16)treplica up- it should finish withstate: streaming/Replica lag: in syncand print a config.php snippettreplica status- same healthy output; runtreplica upagain - it should no-op politelyreadonlyblock at the end of your config.php, set$CFG->perfdebug = 15;, reload any page and check the footer shows "DB reads from replica" counting up, whiletreplica logsshows only SELECT statementstreplica down, confirm - container, volume (and slot, if--slotwas used) are removed;treplica statusnow reports there is no replicaChecklist
bin/directory run correctly on both MacOS and WSLtbuild container && tup container)config.phpare compatible with our oldest supported Totara version, our newest Totara version, and Moodle