@@ -19,10 +19,13 @@ PostgresNode - class representing PostgreSQL server instance
19
19
# Start the PostgreSQL server
20
20
$node->start();
21
21
22
- # Change a setting and restart
22
+ # Add a setting and restart
23
23
$node->append_conf('postgresql.conf', 'hot_standby = on');
24
24
$node->restart();
25
25
26
+ # Modify or delete an existing setting
27
+ $node->adjust_conf('postgresql.conf', 'max_wal_senders', '10');
28
+
26
29
# run a query with psql, like:
27
30
# echo 'SELECT 1' | psql -qAXt postgres -v ON_ERROR_STOP=1
28
31
$psql_stdout = $node->safe_psql('postgres', 'SELECT 1');
@@ -544,6 +547,50 @@ sub append_conf
544
547
545
548
=pod
546
549
550
+ =item $node->adjust_conf(filename, setting, value, skip_equals)
551
+
552
+ Modify the named config file setting with the value. If the value is undefined,
553
+ instead delete the setting. If the setting is not present no action is taken.
554
+
555
+ This will write "$setting = $value\n" in place of the existing line,
556
+ unless skip_equals is true, in which case it will write
557
+ "$setting $value\n". If the value needs to be quoted it is the caller's
558
+ responsibility to do that.
559
+
560
+ =cut
561
+
562
+ sub adjust_conf
563
+ {
564
+ my ($self , $filename , $setting , $value , $skip_equals ) = @_ ;
565
+
566
+ my $conffile = $self -> data_dir . ' /' . $filename ;
567
+
568
+ my $contents = TestLib::slurp_file($conffile );
569
+ my @lines = split (/ \n / , $contents );
570
+ my @result ;
571
+ my $eq = $skip_equals ? ' ' : ' = ' ;
572
+ foreach my $line (@lines )
573
+ {
574
+ if ($line !~ / ^$setting \W / )
575
+ {
576
+ push (@result , " $line \n " );
577
+ }
578
+ elsif (defined $value )
579
+ {
580
+ push (@result , " $setting $eq$value \n " );
581
+ }
582
+ }
583
+ open my $fh , " >" , $conffile
584
+ or croak " could not write \" $conffile \" : $! " ;
585
+ print $fh @result ;
586
+ close $fh ;
587
+
588
+ chmod ($self -> group_access() ? 0640 : 0600, $conffile )
589
+ or die (" unable to set permissions for $conffile " );
590
+ }
591
+
592
+ =pod
593
+
547
594
=item $node->backup(backup_name)
548
595
549
596
Create a hot backup with B<pg_basebackup > in subdirectory B<backup_name > of
0 commit comments