Skip to content

Support separate execution contexts for spawned nodes - #447

Open
AndrewBille wants to merge 11 commits into
postgrespro:masterfrom
AndrewBille:target-execution-context
Open

AndrewBille wants to merge 11 commits into
postgrespro:masterfrom
AndrewBille:target-execution-context

Conversation

@AndrewBille

Copy link
Copy Markdown
Contributor

PostgresNode clones currently inherit the source node's OsOperations,
host and port-management context. This prevents a replica created through
replicate()/spawn_replica() from running in another execution context.

This change adds optional target_os_ops, target_host and target_port
parameters and propagates them through the node cloning and backup
spawning path.

Existing behavior is preserved when these parameters are omitted.

The target and source execution contexts are expected to have access to
the backup directory at the same path.

The new tests cover:

  • cloning into a different OsOperations context;
  • automatic selection of a target-specific PortManager;
  • explicit target host and port;
  • physical replication and catchup across distinct execution contexts.

Comment thread tests/test_testgres_common.py Outdated
res = node.execute('select * from test')
assert (res == [])

def test_replicate__target_context(self):

@dmitry-lipetsk dmitry-lipetsk Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Привет.

А чего с node_svc: PostgresNodeService тест не сделал? Оно бы проверило работу как с локальной так и с удаленной системой.

PostgresNode cloning currently always reuses the source node's
OsOperations and PortManager. NodeBackup propagates that behavior to
spawn_primary(), spawn_replica(), and PostgresNode.replicate(), which
prevents a spawned node from running in another execution context.

Add optional target_os_ops, target_host and target_port arguments and
propagate them through the cloning and backup/replication path. When the
target OsOperations differs, let PostgresNode select a PortManager for
that context. Preserve the existing behavior when the new arguments are
not specified.

A physical backup contains the source node's listen_addresses setting,
so override listen_addresses and port with the spawned node's values.
Also remove the same-host assertion from source_walsender: master process
inspection is already performed through the master's own OsOperations.

Different source and target OsOperations are supported when both
execution contexts can access the backup directory using the same path.
@AndrewBille
AndrewBille force-pushed the target-execution-context branch from 18e83f7 to cb0a4a0 Compare October 13, 2026 08:12
AndrewBille and others added 10 commits October 13, 2026 16:29
The target OsOperations was previously applied only when constructing
the spawned PostgresNode. The backup itself was still created using the
source node's OsOperations.

This worked when source and target execution contexts shared a
filesystem, such as Linux network namespaces, but did not support
different filesystems or remote hosts.

Allow NodeBackup to use an explicit OsOperations and make
PostgresNode.replicate() create the backup directly in target_os_ops.
This makes pg_basebackup, temporary directory creation, copytree and
backup cleanup operate in the target execution context.

Spawned nodes now inherit the backup's OsOperations. When cloning into
a different OsOperations, do not inherit source bin_dir or host; let the
target PostgresNode resolve them from its own execution context.

Add tests for backup copying across execution contexts and physical
replication from a remote source to a local target.
PgLab keeps PostgreSQL lifecycle, backup and replication in Testgres while placing nodes into separate Linux network namespaces and cgroups.

This provides a concrete consumer for the target execution-context replication API: replicas can use their own OsOperations, address and port while pg_basebackup runs in the target context.
Add the PgLab regression suite to Testgres tests and run the privileged Linux scenarios in a dedicated Ubuntu job.

The normal test matrix only runs the API compatibility checks. Destructive netns/cgroup tests are opt-in through TESTGRES_PGLAB_TESTS and are enabled by the dedicated CI job.

This branch has not been deployed

No deployments
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