Skip to content

enable replication support slot management via hiera - #1693

Closed
ikonia wants to merge 1614 commits into
puppetlabs:mainfrom
ikonia:be-pg12-standby
Closed

enable replication support slot management via hiera#1693
ikonia wants to merge 1614 commits into
puppetlabs:mainfrom
ikonia:be-pg12-standby

Conversation

@ikonia

@ikonia ikonia commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

the branch is rebased from master as of 12/08/2026 and includes a few outstanding PR's to get the functionality needed.
enables replication support for Postgres r

Adds primary-side named replication slot management to postgresql::server closing the last gap in this branch's physical streaming replication support: a standby configured via postgresql::server::recovery

postgresql::server::recovery primary_slot_name had nothing on the primary side to actually create the slot it connects to.
Previously this required hand-declaring the native postgresql_replication_slot resource directly in a manifest; it's now Hiera-drivable the same way databases/roles/grant_roles/extensions already are.

Validated end-to-end against a real PostgreSQL 18 master/replica pair

postgresql::server::replication_slots (new hash parameter)

  • Mirrors the existing grant_roles pattern: a single-level hash, splatted straight onto the native postgresql_replication_slot resource.
  • Example: postgresql::server::replication_slots: { standby1_slot: { ensure: present } }
  • Known, deliberate limitation: the underlying native type has no port/psql_path/connect_settings parameters, unlike every sibling resource in this module. This only matters for multi-instance-per-host deployments, this can be expanded on if desired in later MR's but is out of scope for this initial enhancement

Testing

  • Full base-backup + streaming replication cycle between a real PG18 master and replica, using a named slot created via this new parameter.
  • Validated under real load, not just synthetic test data: a ~170-table Foreman database, restored via pg_dump/pg_restore into the master, replicated correctly to the replica — confirmed via LSN comparison and slot health (wal_status, active) on both sides.
  • Spec coverage added/fixed at both the wrapper level (spec/classes/server_spec.rb) and the type level (spec/unit/puppet/type/postgresql_replication_slot_spec.rb).

Additional Context

Add any additional context about the problem here.

  • Root cause and the steps to reproduce. (If applicable)
  • Thought process behind the implementation.

Related Issues (if any)

this branch and merge contains open PR's already merged in
#1661
#1674

Checklist

  • [ x] 🟢 Spec tests.
  • [x ] 🟢 Acceptance tests.
  • [ x] Manually verified. (For example puppet apply)

Ramesh7 and others added 30 commits September 5, 2023 16:17
Prefer $connect_settings over explicit parameters
…e_title

service name should be unique to allow instances
…ce_titles

unique resource titles to allow multiple instances
server::schema: Drop unused $version variable
…parameters

variables to parameters for tablespace/schema/reassign_owned_by
server::instance::initdb: simplify if condition
…ters

add port and psql_path parameter to initdb define
…encryption_in_pg_hba_conf

Flexible password encryption in pg hba conf
…encryption

Fix password_encryption for DBVERSION in server::role
…x_parameter

add $manage_selinux as a parameter, keep default, simpler condition
Only EL6 used sysvinit, but that's no longer supported by the module.
Drop code compatibility for non-systemd Red Hat
Cherry-picked from
puppetlabs#1514

both FreeBSD versions are EoL since a long time and not listed in
metadata.json anymore. We can drop them.
Drop EoL FreeBSD 9.4/9.5 specific code
SugatD and others added 14 commits June 24, 2026 17:32
add EL10 basic support - align EL10 PGSQL 16 default package version
Co-authored-by: GitHub Actions <puppetlabs@users.noreply.github.com>
10.6.2 (PR puppetlabs#1646, "CAT-2385 Puppetcore update") bumped .rubocop.yml
TargetRubyVersion to 3.1, so `rubocop -A` rewrote hash literals to Ruby
3.1 shorthand (`salt:` instead of `salt: salt`) in three custom
functions/providers. That shorthand is a hard syntax error on Ruby <
3.1, and Puppet 7 ships Ruby 2.7 -- so any Puppet 7 catalog using
postgresql::postgresql_password, postgresql_conf or
postgresql_replication_slot failed to compile with "syntax error,
unexpected ','" (issue puppetlabs#1685).

Fix the Ruby side so existing Puppet 7 installations keep working:

  - .rubocop.yml: TargetRubyVersion back to '2.6' so autocorrect can't
    reintroduce the shorthand.
  - Revert the Ruby 3.1 shorthand hash syntax in the three lib files
    (keeping the unrelated postgresql_conf entry_regex bugfix from
    puppetlabs#1657).
  - Revert the same shorthand autocorrection in four spec files so they
    parse under the 2.6 target.

Verified with `pdk validate`, the full unit suite (685 examples, 0
failures), and Litmus end-to-end applies on both Puppet 7.34/Ruby 2.7
and Puppet 8.10/Ruby 3.2 (install, idempotency, and a SCRAM-SHA-256
password hash stored in the live database).

Fixes puppetlabs#1685

Co-Authored-By: Claude <noreply@anthropic.com>
…ore-puppet7

(MODULES-11858) Restore Puppet 7 support broken by 10.6.2
Generate postgresql::server::database resources from a $databases
hash, mirroring the existing $roles/$grants pattern. Carried forward
from be (3940f30/a30df35) during resync onto upstream/main.
Generate postgresql::server::grant_role resources from a $grant_roles
hash. Declaring grant_role from inside class postgresql::server means
its own Class['postgresql::server'] -> Postgresql_psql[...] ordering
edge (used when connect_settings is empty) now cycles back on itself,
so drop that edge here; the Postgresql::Server::Role ordering below is
unaffected and still applies when the role is known.

Carried forward from be (payload of 3a24f48 + 9527c31) during resync
onto upstream/main.
Generate postgresql::server::extension resources from an $extensions
hash keyed by database name, auto-creating the database first if it
isn't already declared. Resources are titled "${database}:${extension}"
to keep titles unique across databases, so extension.pp's $extension
default now parses the extension name back out of that title instead
of assuming $name is the bare extension name.

Carried forward from be (payload of c55d2fc + 9bd9595 + 1b16edc)
during resync onto upstream/main.
The unless clause's SQL query didn't quote the role name, causing
server-side errors when the role name contains a character like a
hyphen (e.g. "monitoring-user").

Carried forward from be (70edc1b, originally from
antaflos/fix_default_privileges_quoting) during resync onto
upstream/main. Not yet present in upstream/main.
PostgreSQL has ignored recovery.conf since v12, but this module has
never accounted for that: postgresql::server::recovery always wrote a
recovery.conf-style file regardless of PostgreSQL version. Gate the
define on versioncmp($postgresql::server::_version, '12'):

- < 12 keeps the existing concat + recovery.conf.epp behavior,
  byte-for-byte unchanged, so existing hand-declared usages on older
  hosts are unaffected.
- >= 12 instead creates an empty standby.signal marker file and writes
  primary_conninfo/primary_slot_name/restore_command/etc. as ordinary
  postgresql.conf GUCs via postgresql::server::config_entry, ordered to
  land before the instance's first service start (these are startup-only
  settings a reload cannot apply). Adds promote_trigger_file and
  recovery_target_action (their PG12+ replacements for trigger_file and
  pause_at_recovery_target); the legacy-only params are still accepted
  with a warning for a softer migration path.

Also adds a new $standby hash parameter on postgresql::server (with a
Postgresql::Standby type alias) so standby/recovery configuration is
finally reachable from a single Hiera key, the same way roles,
pg_hba_rules and config_entries already are -- previously
postgresql::server::recovery had no hash-of-resources wrapper at all
and could only be hand-declared in a manifest.

Replication slot creation on the primary (postgresql_replication_slot)
is a separate, still-unreachable-from-Hiera gap and is intentionally
out of scope here.
postgresql::server::recovery still notified the pre-multi-instance
Class['postgresql::server::reload'] token. Every sibling resource
(pg_hba, pg_ident, config_entry) was migrated to the instance-scoped
Postgresql::Server::Instance::Reload['main'] during the 2023
multi-instance refactor; this define was missed. Unrelated to the
PG12+ standby-config work in the preceding commit.
The describe block named postgresql_replication_slot, but its subject
instantiated Puppet::Type.type(:postgresql_psql) instead, so it never
actually exercised this type. Point subject at the right type and add
coverage for name validation and ensurable.
Generates postgresql_replication_slot resources from a $replication_slots
hash, so a primary can Hiera-drive the named physical replication slots
that a standby's primary_slot_name (postgresql::server::recovery/$standby)
connects through. Mirrors the existing $grant_roles pattern: a single-level
hash splatted straight onto the resource, since the native type has nothing
beyond name/ensure to wrap.

Deliberately not extending the native postgresql_replication_slot type or
provider here: it has no port/psql_path/connect_settings, unlike every
sibling resource, so this only supports the default instance. That only
matters for multi-instance-per-host deployments; fixing it also requires
redesigning self.instances/prefetch, which currently lists slots via a
single connection-oblivious psql call. Left as a documented limitation
rather than scope for this change.
@CLAassistant

CLAassistant commented Aug 12, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
8 out of 11 committers have signed the CLA.

✅ ikonia
✅ shubhamshinde360
✅ gavindidrichsen
✅ imaqsood
✅ elfranne
✅ SugatD
✅ bastelfreak
✅ skyamgarp
❌ mend-for-github-com[bot]
❌ GitHub Actions
❌ github-actions[bot]


GitHub Actions seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment thread manifests/server.pp Outdated
Co-authored-by: Corporate Gadfly <corporate-gadfly@users.noreply.github.com>
@ikonia

ikonia commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

messed up the repo trying to fix a commit error will re-submit from a correctly formatted repo,

@ikonia ikonia closed this Aug 13, 2026
@ikonia
ikonia deleted the be-pg12-standby branch August 13, 2026 09:30
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.