@@ -47,7 +47,7 @@ allowing to start, stop, backup and initialize it with various options.
47
47
The set of nodes managed by a given test is also managed by this module.
48
48
49
49
In addition to node management, PostgresNode instances have some wrappers
50
- around Test::More functions to run commands with an envronment set up to
50
+ around Test::More functions to run commands with an environment set up to
51
51
point to the instance.
52
52
53
53
The IPC::Run module is required.
@@ -66,7 +66,6 @@ use File::Basename;
66
66
use File::Spec;
67
67
use File::Temp ();
68
68
use IPC::Run;
69
- use PostgresNode;
70
69
use RecursiveCopy;
71
70
use Test::More;
72
71
use TestLib ();
@@ -347,6 +346,9 @@ On Windows, we use SSPI authentication to ensure the same (by pg_regress
347
346
pg_hba.conf is configured to allow replication connections. Pass the keyword
348
347
parameter hba_permit_replication => 0 to disable this.
349
348
349
+ postgresql.conf can be set up for replication by passing the keyword
350
+ parameter allows_streaming => 1. This is disabled by default.
351
+
350
352
The new node is set up in a fast but unsafe configuration where fsync is
351
353
disabled.
352
354
@@ -360,7 +362,8 @@ sub init
360
362
my $host = $self -> host;
361
363
362
364
$params {hba_permit_replication } = 1
363
- if (!defined ($params {hba_permit_replication }));
365
+ unless defined $params {hba_permit_replication };
366
+ $params {allows_streaming } = 0 unless defined $params {allows_streaming };
364
367
365
368
mkdir $self -> backup_dir;
366
369
mkdir $self -> archive_dir;
@@ -373,6 +376,19 @@ sub init
373
376
print $conf " fsync = off\n " ;
374
377
print $conf " log_statement = all\n " ;
375
378
print $conf " port = $port \n " ;
379
+
380
+ if ($params {allows_streaming })
381
+ {
382
+ print $conf " wal_level = hot_standby\n " ;
383
+ print $conf " max_wal_senders = 5\n " ;
384
+ print $conf " wal_keep_segments = 20\n " ;
385
+ print $conf " max_wal_size = 128MB\n " ;
386
+ print $conf " shared_buffers = 1MB\n " ;
387
+ print $conf " wal_log_hints = on\n " ;
388
+ print $conf " hot_standby = on\n " ;
389
+ print $conf " max_connections = 10\n " ;
390
+ }
391
+
376
392
if ($TestLib::windows_os )
377
393
{
378
394
print $conf " listen_addresses = '$host '\n " ;
@@ -384,7 +400,7 @@ sub init
384
400
}
385
401
close $conf ;
386
402
387
- $self -> set_replication_conf if ( $params {hba_permit_replication }) ;
403
+ $self -> set_replication_conf if $params {hba_permit_replication };
388
404
}
389
405
390
406
=pod
@@ -446,19 +462,23 @@ Does not start the node after init.
446
462
447
463
A recovery.conf is not created.
448
464
465
+ Streaming replication can be enabled on this node by passing the keyword
466
+ parameter has_streaming => 1. This is disabled by default.
467
+
449
468
The backup is copied, leaving the original unmodified. pg_hba.conf is
450
469
unconditionally set to enable replication connections.
451
470
452
471
=cut
453
472
454
473
sub init_from_backup
455
474
{
456
- my ($self , $root_node , $backup_name ) = @_ ;
475
+ my ($self , $root_node , $backup_name , %params ) = @_ ;
457
476
my $backup_path = $root_node -> backup_dir . ' /' . $backup_name ;
458
477
my $port = $self -> port;
459
478
my $node_name = $self -> name;
460
479
my $root_name = $root_node -> name;
461
480
481
+ $params {has_streaming } = 0 unless defined $params {has_streaming };
462
482
print
463
483
" # Initializing node \" $node_name \" from backup \" $backup_name \" of node \" $root_name \"\n " ;
464
484
die " Backup \" $backup_name \" does not exist at $backup_path "
@@ -479,6 +499,7 @@ sub init_from_backup
479
499
port = $port
480
500
) );
481
501
$self -> set_replication_conf;
502
+ $self -> enable_streaming($root_node ) if $params {has_streaming };
482
503
}
483
504
484
505
=pod
@@ -525,7 +546,7 @@ sub stop
525
546
my $port = $self -> port;
526
547
my $pgdata = $self -> data_dir;
527
548
my $name = $self -> name;
528
- $mode = ' fast' if (! defined ( $mode )) ;
549
+ $mode = ' fast' unless defined $mode ;
529
550
print " ### Stopping node \" $name \" using mode $mode \n " ;
530
551
TestLib::system_log(' pg_ctl' , ' -D' , $pgdata , ' -m' , $mode , ' stop' );
531
552
$self -> {_pid } = undef ;
@@ -536,7 +557,7 @@ sub stop
536
557
537
558
=item $node->restart()
538
559
539
- wrapper for pg_ctl -w restart
560
+ Wrapper for pg_ctl -w restart
540
561
541
562
=cut
542
563
@@ -553,6 +574,39 @@ sub restart
553
574
$self -> _update_pid;
554
575
}
555
576
577
+ =pod
578
+
579
+ =item $node->promote()
580
+
581
+ Wrapper for pg_ctl promote
582
+
583
+ =cut
584
+
585
+ sub promote
586
+ {
587
+ my ($self ) = @_ ;
588
+ my $port = $self -> port;
589
+ my $pgdata = $self -> data_dir;
590
+ my $logfile = $self -> logfile;
591
+ my $name = $self -> name;
592
+ print " ### Promoting node \" $name \"\n " ;
593
+ TestLib::system_log(' pg_ctl' , ' -D' , $pgdata , ' -l' , $logfile ,
594
+ ' promote' );
595
+ }
596
+
597
+ # Internal routine to enable streaming replication on a standby node.
598
+ sub enable_streaming
599
+ {
600
+ my ($self , $root_node ) = @_ ;
601
+ my $root_connstr = $root_node -> connstr;
602
+ my $name = $self -> name;
603
+
604
+ print " ### Enabling streaming replication for node \" $name \"\n " ;
605
+ $self -> append_conf(' recovery.conf' , qq(
606
+ primary_conninfo='$root_connstr application_name=$name '
607
+ standby_mode=on
608
+ ) );
609
+ }
556
610
557
611
# Internal method
558
612
sub _update_pid
@@ -632,7 +686,7 @@ sub DESTROY
632
686
{
633
687
my $self = shift ;
634
688
my $name = $self -> name;
635
- return if not defined $self -> {_pid };
689
+ return unless defined $self -> {_pid };
636
690
print " ### Signalling QUIT to $self ->{_pid} for node \" $name \"\n " ;
637
691
TestLib::system_log(' pg_ctl' , ' kill' , ' QUIT' , $self -> {_pid });
638
692
}
@@ -789,6 +843,7 @@ Run a command on the node, then verify that $expected_sql appears in the
789
843
server log file.
790
844
791
845
Reads the whole log file so be careful when working with large log outputs.
846
+ The log file is truncated prior to running the command, however.
792
847
793
848
=cut
794
849
0 commit comments