@@ -346,6 +346,9 @@ On Windows, we use SSPI authentication to ensure the same (by pg_regress
346346pg_hba.conf is configured to allow replication connections. Pass the keyword
347347parameter hba_permit_replication => 0 to disable this.
348348
349+ WAL archiving can be enabled on this node by passing the keyword parameter
350+ has_archiving => 1. This is disabled by default.
351+
349352postgresql.conf can be set up for replication by passing the keyword
350353parameter allows_streaming => 1. This is disabled by default.
351354
@@ -364,6 +367,7 @@ sub init
364367 $params {hba_permit_replication } = 1
365368 unless defined $params {hba_permit_replication };
366369 $params {allows_streaming } = 0 unless defined $params {allows_streaming };
370+ $params {has_archiving } = 0 unless defined $params {has_archiving };
367371
368372 mkdir $self -> backup_dir;
369373 mkdir $self -> archive_dir;
@@ -401,6 +405,7 @@ sub init
401405 close $conf ;
402406
403407 $self -> set_replication_conf if $params {hba_permit_replication };
408+ $self -> enable_archiving if $params {has_archiving };
404409}
405410
406411=pod
@@ -458,13 +463,20 @@ Initialize a node from a backup, which may come from this node or a different
458463node. root_node must be a PostgresNode reference, backup_name the string name
459464of a backup previously created on that node with $node->backup.
460465
461- Does not start the node after init .
466+ Does not start the node after initializing it .
462467
463468A recovery.conf is not created.
464469
470+ pg_hba.conf is configured to allow replication connections. Pass the keyword
471+ parameter hba_permit_replication => 0 to disable this.
472+
465473Streaming replication can be enabled on this node by passing the keyword
466474parameter has_streaming => 1. This is disabled by default.
467475
476+ Restoring WAL segments from archives using restore_command can be enabled
477+ by passiong the keyword parameter has_restoring => 1. This is disabled by
478+ default.
479+
468480The backup is copied, leaving the original unmodified. pg_hba.conf is
469481unconditionally set to enable replication connections.
470482
@@ -479,6 +491,10 @@ sub init_from_backup
479491 my $root_name = $root_node -> name;
480492
481493 $params {has_streaming } = 0 unless defined $params {has_streaming };
494+ $params {hba_permit_replication } = 1
495+ unless defined $params {hba_permit_replication };
496+ $params {has_restoring } = 0 unless defined $params {has_restoring };
497+
482498 print
483499" # Initializing node \" $node_name \" from backup \" $backup_name \" of node \" $root_name \"\n " ;
484500 die " Backup \" $backup_name \" does not exist at $backup_path "
@@ -498,8 +514,9 @@ sub init_from_backup
498514 qq(
499515port = $port
500516) );
501- $self -> set_replication_conf;
517+ $self -> set_replication_conf if $params { hba_permit_replication } ;
502518 $self -> enable_streaming($root_node ) if $params {has_streaming };
519+ $self -> enable_restoring($root_node ) if $params {has_restoring };
503520}
504521
505522=pod
@@ -608,6 +625,59 @@ standby_mode=on
608625) );
609626}
610627
628+ # Internal routine to enable archive recovery command on a standby node
629+ sub enable_restoring
630+ {
631+ my ($self , $root_node ) = @_ ;
632+ my $path = $root_node -> archive_dir;
633+ my $name = $self -> name;
634+
635+ print " ### Enabling WAL restore for node \" $name \"\n " ;
636+
637+ # On Windows, the path specified in the restore command needs to use
638+ # double back-slashes to work properly and to be able to detect properly
639+ # the file targeted by the copy command, so the directory value used
640+ # in this routine, using only one back-slash, need to be properly changed
641+ # first. Paths also need to be double-quoted to prevent failures where
642+ # the path contains spaces.
643+ $path =~ s {\\ } { \\\\ } g if ($TestLib::windows_os );
644+ my $copy_command = $TestLib::windows_os ?
645+ qq{ copy "$path \\\\ %f " "%p "} :
646+ qq{ cp $path /%f %p } ;
647+
648+ $self -> append_conf(' recovery.conf' , qq(
649+ restore_command = '$copy_command '
650+ standby_mode = on
651+ ) );
652+ }
653+
654+ # Internal routine to enable archiving
655+ sub enable_archiving
656+ {
657+ my ($self ) = @_ ;
658+ my $path = $self -> archive_dir;
659+ my $name = $self -> name;
660+
661+ print " ### Enabling WAL archiving for node \" $name \"\n " ;
662+
663+ # On Windows, the path specified in the restore command needs to use
664+ # double back-slashes to work properly and to be able to detect properly
665+ # the file targeted by the copy command, so the directory value used
666+ # in this routine, using only one back-slash, need to be properly changed
667+ # first. Paths also need to be double-quoted to prevent failures where
668+ # the path contains spaces.
669+ $path =~ s {\\ } { \\\\ } g if ($TestLib::windows_os );
670+ my $copy_command = $TestLib::windows_os ?
671+ qq{ copy "%p " "$path \\\\ %f "} :
672+ qq{ cp %p $path /%f } ;
673+
674+ # Enable archive_mode and archive_command on node
675+ $self -> append_conf(' postgresql.conf' , qq(
676+ archive_mode = on
677+ archive_command = '$copy_command '
678+ ) );
679+ }
680+
611681# Internal method
612682sub _update_pid
613683{
0 commit comments