| 1 | package DBIx::QuickDB::Driver::PostgreSQL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 15 | our $VERSION = '0.000066'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use DBIx::QuickDB::Util qw/strip_hash_defaults env_timeout find_bin/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Time::HiRes qw/sleep time/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use parent 'DBIx::QuickDB::Driver'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use DBIx::QuickDB::Util::HashBase qw{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | -data_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | -initdb -createdb -postgres -psql | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | -config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | -socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | -port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 | my ($INITDB, $CREATEDB, $POSTGRES, $PSQL, $DBDPG); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 15 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 15 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 15 | $INITDB = find_bin('initdb'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 15 | $CREATEDB = find_bin('createdb'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 15 | $POSTGRES = find_bin('postgres'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 15 | $PSQL = find_bin('psql'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $DBDPG = eval { require DBD::Pg; 'DBD::Pg'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub version_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version_string: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $binary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Go in reverse order assuming the last param hash provided is most important | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | for my $arg (reverse @_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $type = reftype($arg) or next; # skip if not a ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | next unless $type eq 'HASH'; # We have a hashref, possibly blessed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # If we find a launcher we are done looping, we want to use this binary. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $binary = $arg->{+POSTGRES} and last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # If no args provided one to use we fallback to the default from $PATH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $binary ||= $POSTGRES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$binary ||= $POSTGRES
MC/DC0%0/2
$binary ||= $POSTGRES
$binary
$POSTGRES
Truth table0%0/3
A ||= B
A= $binaryB= $POSTGRES
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # Call the binary with '-V', capturing and returning the output using backticks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | return `$binary -V`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub list_env_vars { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_env_vars: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $self->SUPER::list_env_vars(), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | qw{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | PGAPPNAME PGCLIENTENCODING PGCONNECT_TIMEOUT PGDATABASE PGDATESTYLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | PGGEQO PGGSSLIB PGHOST PGHOSTADDR PGKRBSRVNAME PGLOCALEDIR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | PGOPTIONS PGPASSFILE PGPASSWORD PGPORT PGREQUIREPEER PGREQUIRESSL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | PGSERVICE PGSERVICEFILE PGSSLCERT PGSSLCOMPRESSION PGSSLCRL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | PGSSLKEY PGSSLMODE PGSSLROOTCERT PGSYSCONFDIR PGTARGETSESSIONATTRS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | PGTZ PGUSER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub error_log { "$_[0]->{+DIR}/error.log" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_log: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # Stop the postmaster with SIGTERM ("Smart Shutdown"): it lets in-progress | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # transactions finish and shuts down cleanly. Smart Shutdown waits for every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # client to disconnect first, which previously risked hanging until the watcher | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # escalated to SIGKILL. That risk is now handled elsewhere: stop() disconnects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # our own lingering handles (via DBI->visit_handles) before signalling the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # server, forces a CHECKPOINT so a hard kill cannot corrupt a later clone, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # the watcher's grace period before SIGKILL is generous and tunable. A proper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # shutdown is preferred whenever it is possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub stop_sig { 'TERM' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop_sig: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Fast/disposable teardown uses SIGQUIT ("Immediate Shutdown") rather than the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # base-class SIGKILL. Immediate Shutdown aborts all backends without a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # checkpoint -- so it is nearly as fast as SIGKILL -- but the postmaster still | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # runs its exit cleanup and RELEASES its SysV semaphores (and shared memory). A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # SIGKILLed postmaster cannot clean up, and because a disposable clone's data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # dir is then deleted no future postmaster will ever reuse that IPC key, so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # semaphores leak permanently. On hosts where PostgreSQL uses SysV semaphores | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # (FreeBSD, OpenBSD, macOS) a suite that hard-kills many disposable clones can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # exhaust the kernel SEMMNI/SEMMNS limits; SIGQUIT avoids that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | sub fast_stop_sig { 'QUIT' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fast_stop_sig: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 18 | ▶ | sub _default_paths { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_paths: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 18 | initdb => $INITDB, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | createdb => $CREATEDB, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | postgres => $POSTGRES, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | psql => $PSQL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub _default_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_config: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # QuickDB databases are short-lived test instances: autovacuum buys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # nothing, and on PostgreSQL <= 14 its launcher can stall shutdown for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # PGSTAT_MAX_WAIT_TIME (10s) waiting on the stats collector ("using | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # stale statistics instead of current ones because stats collector is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # not responding"), which made stop() blow the whole stop grace and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # get escalated. Consumers who need it can override. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | autovacuum => "off", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | datestyle => "'iso, mdy'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | default_text_search_config => "'pg_catalog.english'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | lc_messages => "'en_US.UTF-8'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | lc_monetary => "'en_US.UTF-8'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | lc_numeric => "'en_US.UTF-8'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | lc_time => "'en_US.UTF-8'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | listen_addresses => "''", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | log_destination => "'stderr'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | logging_collector => "'on'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | log_directory => "'$self->{+DIR}'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | log_filename => "'error.log'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | max_connections => "100", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | shared_buffers => "128MB", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | unix_socket_directories => "'$self->{+DIR}'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | port => $self->{+PORT}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | #dynamic_shared_memory_type => "posix", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | #log_timezone => "'US/Pacific'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | #timezone => "'US/Pacific'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 18 | ▶ | sub viable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
viable: called CC=24 SCAR=35.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 18 | my $this = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 18 | my ($spec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 18 | ▶ | my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 18 | my @bad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 18 | ▶ | push @bad => "'DBD::Pg' module could not be loaded, needed for everything" unless $DBDPG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 18 | ▶ | if ($spec->{bootstrap}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 17 | ▶ | push @bad => "'initdb' command is missing, needed for bootstrap" unless $check{initdb} && -x $check{initdb}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$check{"initdb"} and -x $check{"initdb"}
MC/DC0%0/2
$check{"initdb"} and -x $check{"initdb"}
$check{"initdb"}
-x $check{"initdb"}
Truth table33%1/3
A and B
A= $check{"initdb"}B= -x $check{"initdb"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 17 | ▶ | push @bad => "'createdb' command is missing, needed for bootstrap" unless $check{createdb} && -x $check{createdb}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$check{"createdb"} and -x $check{"createdb"}
MC/DC0%0/2
$check{"createdb"} and -x $check{"createdb"}
$check{"createdb"}
-x $check{"createdb"}
Truth table33%1/3
A and B
A= $check{"createdb"}B= -x $check{"createdb"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 18 | ▶ | if ($spec->{autostart}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 14 | ▶ | push @bad => "'postgres' command is missing, needed for autostart" unless $check{postgres} && -x $check{postgres}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$check{"postgres"} and -x $check{"postgres"}
MC/DC0%0/2
$check{"postgres"} and -x $check{"postgres"}
$check{"postgres"}
-x $check{"postgres"}
Truth table33%1/3
A and B
A= $check{"postgres"}B= -x $check{"postgres"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # PostgreSQL's initdb and postgres flatly refuse to run as root (geteuid() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # == 0), and there is no override flag; running as root manifests as a start | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # timeout otherwise. This check is Unix-only, mirroring initdb's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # #ifndef WIN32 guard. Only bootstrap/autostart spawn those binaries. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 18 | ▶ | if (($spec->{bootstrap} || $spec->{autostart}) && $^O ne 'MSWin32' && $> == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$spec->{"bootstrap"} || $spec->{"autostart"} and $^O ne "MSWin32" and $> == 0
$spec->{"bootstrap"} || $spec->{"autostart"} and $^O ne "MSWin32"
$spec->{"bootstrap"} or $spec->{"autostart"}
MC/DC0%0/4
$spec->{"bootstrap"} || $spec->{"autostart"} and $^O ne "MSWin32" and $> == 0
$spec->{"bootstrap"}
$spec->{"autostart"}
$^O ne "MSWin32"
$> == 0
Truth table42%3/7
A or B and C and D
A= $spec->{"bootstrap"}B= $spec->{"autostart"}C= $^O ne "MSWin32"D= $> == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | push @bad => "PostgreSQL's initdb and postgres refuse to run as root (EUID 0); run as an unprivileged user"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 18 | ▶ | push @bad => $this->_watcher_unsupported_reason($spec) // (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$this->_watcher_unsupported_reason($spec) // ()
MC/DC50%1/2
$this->_watcher_unsupported_reason($spec) // ()
$this->_watcher_unsupported_reason($spec)
()
Truth table66%2/3
A // B
A= $this->_watcher_unsupported_reason($spec)B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 18 | ▶ | if (($spec->{bootstrap} || $spec->{autostart}) && $^O eq 'cygwin' && !$this->_cygwin_has_shm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$spec->{"bootstrap"} || $spec->{"autostart"} and $^O eq "cygwin" and not $this->_cygwin_has_shm
$spec->{"bootstrap"} || $spec->{"autostart"} and $^O eq "cygwin"
$spec->{"bootstrap"} or $spec->{"autostart"}
MC/DC75%3/4
$spec->{"bootstrap"} || $spec->{"autostart"} and $^O eq "cygwin" and not $this->_cygwin_has_shm
$spec->{"bootstrap"}
$spec->{"autostart"}
$^O eq "cygwin"
not $this->_cygwin_has_shm
Truth table57%4/7
A or B and C and not(D)
A= $spec->{"bootstrap"}B= $spec->{"autostart"}C= $^O eq "cygwin"D= not $this->_cygwin_has_shm
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | push @bad => "PostgreSQL needs System V shared memory, which Cygwin provides only while cygserver runs (set it up with cygserver-config, start it with cygrunsrv -S cygserver)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 18 | ▶ | if ($spec->{load_sql}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 12 | ▶ | push @bad => "'psql' command is missing, needed for load_sql" unless $check{psql} && -x $check{psql}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$check{"psql"} and -x $check{"psql"}
MC/DC0%0/2
$check{"psql"} and -x $check{"psql"}
$check{"psql"}
-x $check{"psql"}
Truth table33%1/3
A and B
A= $check{"psql"}B= -x $check{"psql"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 18 | ▶ | return (1, undef) unless @bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 18 | return (0, join "\n" => @bad); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->SUPER::init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my $port = $self->{+PORT} ||= '5432'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"port"} ||= 5432
MC/DC0%0/1
$self->{"port"} ||= 5432
$self->{"port"}
Truth table0%0/2
A
A= $self->{"port"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->{+DATA_DIR} = "$dir/data"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | $self->{+SOCKET} ||= "$dir/.s.PGSQL.$port"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"socket"} ||= "$dir/.s.PGSQL.$port"
MC/DC0%0/1
$self->{"socket"} ||= "$dir/.s.PGSQL.$port"
$self->{"socket"}
Truth table0%0/2
A
A= $self->{"socket"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $self->{+ENV_VARS} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"env_vars"} ||= {}
MC/DC0%0/1
$self->{"env_vars"} ||= {}
$self->{"env_vars"}
Truth table0%0/2
A
A= $self->{"env_vars"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $self->{+ENV_VARS}->{PGPORT} = $port unless defined $self->{+ENV_VARS}->{PGPORT}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my %defaults = $self->_default_paths; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $self->{$_} ||= $defaults{$_} for keys %defaults; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{$_} ||= $defaults{$_}
MC/DC0%0/2
$self->{$_} ||= $defaults{$_}
$self->{$_}
$defaults{$_}
Truth table0%0/3
A ||= B
A= $self->{$_}B= $defaults{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my %cfg_defs = $self->_default_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | my $cfg = $self->{+CONFIG} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"config"} ||= {}
MC/DC0%0/1
$self->{"config"} ||= {}
$self->{"config"}
Truth table0%0/2
A
A= $self->{"config"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | for my $key (keys %cfg_defs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | next if defined $cfg->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $cfg->{$key} = $cfg_defs{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub clone_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone_data: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my $vars = $self->env_vars || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->env_vars || {}
MC/DC0%0/1
$self->env_vars || {}
$self->env_vars
Truth table0%0/2
A
A= $self->env_vars
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | delete $vars->{PGPORT} if $vars->{PGPORT} && $vars->{PGPORT} eq $self->port; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$vars->{"PGPORT"} and $vars->{"PGPORT"} eq $self->port
MC/DC0%0/2
$vars->{"PGPORT"} and $vars->{"PGPORT"} eq $self->port
$vars->{"PGPORT"}
$vars->{"PGPORT"} eq $self->port
Truth table0%0/3
A and B
A= $vars->{"PGPORT"}B= $vars->{"PGPORT"} eq $self->port
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | my $config = strip_hash_defaults( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $self->{+CONFIG}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | { $self->_default_config }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $self->SUPER::clone_data(), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ENV_VARS() => $vars, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | CONFIG() => $config, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub write_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_config: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $db_dir = $self->{+DATA_DIR}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | open(my $cf, '>', "$db_dir/postgresql.conf") or die "Could not open config file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | for my $key (sort keys %{$self->{+CONFIG}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $val = $self->{+CONFIG}->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | next unless length($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | print $cf "$key = $val\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | close($cf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # PostgreSQL 9.3 creates its Unix-domain listening socket before it allocates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # shared memory and semaphores. (Modern releases use a different order.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # Waiting for the socket alone therefore has a small false-ready window on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # affected old releases: the postmaster can create the socket, fail during the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # remaining startup work (notably semget() on SysV-IPC platforms), and remove | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # it again after the base start() has returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # Readiness is therefore confirmed with a real connection to the always-present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # postgres database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 4 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | ▶ | return if $self->started; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | $self->SUPER::start(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | $self->_wait_for_connect('postgres'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | sub bootstrap { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bootstrap: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $db_dir = $self->{+DATA_DIR}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | mkdir($db_dir) or die "Could not create data dir: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $self->run_command([$self->{+INITDB}, '-E', 'UTF8', '--no-locale', '-A', 'trust', '-D', $db_dir]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $self->write_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $self->start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | for my $try (1 .. 10) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my ($ok, $err); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | $self->catch_startup(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $self->run_command([$self->{+CREATEDB}, '-T', 'template0', '-E', 'UTF8', '-h', $dir, 'quickdb']); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | last if $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | die $err if $try == 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | sleep 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | $self->stop unless $self->{+AUTOSTART}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | sub connect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my ($db_name, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my $dbh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | $self->catch_startup(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $dbh = $self->SUPER::connect($db_name, %params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return $dbh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # Force a CHECKPOINT so the on-disk state is durable before shutdown. Without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # this, a shutdown that gets SIGKILLed (slow host blowing the watcher's grace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # period) leaves the cluster needing crash recovery; cloning that data dir and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # starting it replays WAL, which advances SERIAL sequences by SEQ_LOG_VALS (32) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # -- e.g. the next inserted row gets id 34 instead of 2. Best effort: any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # failure here must not prevent the server from stopping. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub checkpoint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkpoint: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | return unless $self->started; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $dbh = $self->connect('postgres', AutoCommit => 1, RaiseError => 1, PrintError => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $dbh->do('CHECKPOINT'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $dbh->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub connect_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my ($db_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | $db_name = 'quickdb' unless defined $db_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | require DBD::Pg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return "dbi:Pg:dbname=$db_name;host=$dir" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub load_sql { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_sql: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my ($dbname, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | $self->catch_startup(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | $self->run_command([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $self->{+PSQL}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | '-h' => $dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | '-v' => 'ON_ERROR_STOP=1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | '-f' => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $dbname, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | sub shell_command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shell_command: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my ($db_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | return ($self->{+PSQL}, '-h' => $self->{+DIR}, $db_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | sub start_command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_command: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return ($self->{+POSTGRES}, '-D' => $self->{+DATA_DIR}, '-p' => $self->{+PORT}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | sub catch_startup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
catch_startup: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my ($code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $timeout = env_timeout(QDB_START_TIMEOUT => 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | my $start = time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $waited = time - $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | die "Timeout waiting for server" if $waited > $timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my ($ok, $err, $out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $out = $code->($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | return $out if $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | die $err unless $err =~ m/the database system is starting up/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | sleep 0.01; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # Without cygserver, Cygwin's shmget fails with ENOSYS and initdb dies with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # "could not create shared memory segment". Probe what PostgreSQL needs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub _cygwin_has_shm { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cygwin_has_shm: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | require IPC::SysV; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $id = shmget(IPC::SysV::IPC_PRIVATE(), 4096, 0600); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | return 0 unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | shmctl($id, IPC::SysV::IPC_RMID(), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||