Skip to content

feat: add images and settings to create primary-replica PostgreSQL - #405

Open
NingZhou-NZ wants to merge 1 commit into
totara:masterfrom
NingZhou-NZ:feat-primary-replica-postgres
Open

NingZhou-NZ wants to merge 1 commit into
totara:masterfrom
NingZhou-NZ:feat-primary-replica-postgres

Conversation

@NingZhou-NZ

Copy link
Copy Markdown

Description

Describe what this pull request is about

Testing Instructions

  1. Check out this pull request
  2. Run the script tup pgsql-primary pgsql-replica-1
  3. Make sure totara_pgsql_primary and totara_pgsql_replica_1 is running (easy way to check is open the UI of Rancher Desktop, in Containers tab)
  4. change db setting in config.php
$CFG->dbhost = 'pgsql-primary'; 
$CFG->dbtype = 'pgsql';
$CFG->dbuser = 'postgres';
$CFG->dbpass = '';

And extra setting at the end of config.php

$CFG->dboptions['readonly'] = [
    'instance' => ['pgsql-replica-1'],   // replica HOST(s);
    'connecttimeout' => 2,              // optional, seconds, default 2
    'latency' => 0.5,                   // optional, seconds, DEFAULT 1 when omitted
    // 'exclude_tables' => ['config'], // optional, emergency use
];

Checklist

  • Does what the author says it will do
  • Testing instructions are provided
  • Commit messages make sense and follow the conventional commit standard
  • No identified security issues
  • No identified maintenance issues
  • Any third-party libraries/dependencies use the MIT or Apache 2.0 license
  • Changes made are backwards compatible and will not break existing setups
  • Changes to scripts in the bin/ directory run correctly on both MacOS and WSL
  • Changes to containers can be built locally sucessfully (e.g. via tbuild container && tup container)
  • Containers/images are compatible with both AMD64 (Windows) and ARM64 (MacOS)
  • Changes made to config.php are compatible with our oldest supported Totara version, our newest Totara version, and Moodle

@NingZhou-NZ
NingZhou-NZ force-pushed the feat-primary-replica-postgres branch from 730ad3b to 878e2e1 Compare August 18, 2026 11:46
@codyfinegan
codyfinegan force-pushed the feat-primary-replica-postgres branch from 878e2e1 to 4454fc8 Compare October 8, 2026 20:16

@codyfinegan codyfinegan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. No replication slot, so the replica breaks for good after a gap. I stopped the replica, wrote about 1.2M rows on the primary with WAL switches and checkpoints, then started it again. It loops on requested WAL segment 000000010000000000000003 has already been removed. Settings are wal_keep_size = 0 and no slots. A Totara install or upgrade writes far more WAL than my test. The only way to recover is to delete the replica volume.
    • Fix: add -C -S replica_1 to pg_basebackup and set max_slot_wal_keep_size on the primary. Setting wal_keep_size = 1GB would also work.
  2. The primary does not get the Totara lock settings. my-postgres-master.conf does not include max_locks_per_transaction = 1024 / max_pred_locks_per_transaction = 1024 from my-postgres.conf. The primary shows 64, the replica 1024. The primary is where Totara writes.
    • Fix: add them to the master conf, or include the base conf.
  3. Partial pg_basebackup is treated as a valid data directory. If the backup dies after PG_VERSION is written, the next start skips init and boots a broken data dir. Low risk for dev.
    • Fix: back up into a temp dir and move it into place, or write a marker file when the backup finishes.

Minor

  • The filename is misspelled: pgsql/init/creare-replicator.sql should be create-replicator.sql.
  • pg_isready -U replicator with no -d logs FATAL: database "replicator" does not exist on the primary on every poll. Add -d postgres.
  • hot_standby = on in the primary conf does nothing on a primary.
  • The two new services do not follow compose/pgsql.yml: no <<: *postgres-healthcheck and no restart: ${RESTART_POLICY:-no}.
  • Naming mixes "master" and "primary": my-postgres-master.conf and pgsql16-master-data vs service pgsql-primary. The ports 54320/54321 also don't follow the 54XX version scheme.
  • replica_password is hardcoded in both the SQL file and the entrypoint. One env var would keep them in sync.
  • No docs. A short note with the Totara config.php snippet would help: dbhost = 'pgsql-primary' and $CFG->dboptions['readonly'] pointing at pgsql-replica-1.
  • None of the new files end with a newline.

Fix items 1 and 2 before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants