Package: postgresql-common Version: 94lenny1 I need to run a customized postgresql installation and wanted to get good integration into the debian installation when I realized that the highly useful postgresql-common scripts only support purely numerical version ids. Here's a simplistic example:
# pg_createcluster 8.3nfs test Use of uninitialized value $version in concatenation (.) or string at /usr/bin/pg_createcluster line 281. Use of uninitialized value $version in concatenation (.) or string at /usr/bin/pg_createcluster line 282. Use of uninitialized value $version in concatenation (.) or string at /usr/bin/pg_createcluster line 286. Error: invalid version: I'll attach suggested patches to extend the scripts to also handle alphanumerical version ids matching the regexp [a-z]*\d+.\d+[a-z]* This was seen on: # uname -a Linux <name> 2.6.26-2-amd64 #1 SMP Tue Mar 9 22:29:32 UTC 2010 x86_64 GNU/Linux # cat /etc/debian_version 5.0.4 Thank you, Nils -- ** * * UPLEX - Nils Goroll Systemoptimierung Schwanenwik 24 22087 Hamburg tel +49 40 28805731 mob +49 170 2723133 fax +49 40 42949753 http://uplex.de/
diff -rub usr/bin.o/pg_createcluster usr/bin/pg_createcluster --- usr/bin.o/pg_createcluster 2009-02-06 00:00:51.000000000 +0100 +++ usr/bin/pg_createcluster 2010-06-11 18:26:55.000000000 +0200 @@ -50,16 +50,19 @@ sub init_db { $datadir = (-l $_[1]) ? readlink $_[1] : $_[1]; + my $v; + ($v = $_[0]) =~ y/0-9.//cd; + if (system 'install', '-d', '-o', $_[2], '-g', $_[3], $datadir) { error 'could not create data directory; you might need to run this program with root privileges'; } @initdb = ((get_program_path 'initdb', $_[0]), '-D', $datadir); - if ($_[0] ge '8.0') { + if ($v ge '8.0') { push @initdb, ('-A', 'ident sameuser'); } die 'Internal error: could not determine initdb path' unless $initdb[0]; - if (!$encoding and $version < 8) { + if (!$encoding and $nversion < 8) { $encoding = get_encoding_from_locale(); } push @initdb, ('--encoding', $encoding) if $encoding; @@ -73,7 +76,7 @@ # pre-8.2 servers do not ignore LANG when LC_ALL is set; work around this # bug - if ($_[0] le '8.2' && $ENV{'LC_ALL'}) { + if ($v le '8.2' && $ENV{'LC_ALL'}) { $ENV{'LANG'} = $ENV{'LC_ALL'}; } @@ -106,7 +109,7 @@ @pathcomps = split ('/', $file); $target .= '/' . $pathcomps[-1]; - if ($version lt '8') { + if ($nversion lt '8') { $oldgid = $); $olduid = $>; $) = $gid; @@ -274,7 +277,8 @@ error 'clusters must not be owned by root' unless $owneruid && $ownergid; -($version) = $ARGV[0] =~ /^(\d+\.\d+)$/; +($version) = $ARGV[0] =~ /^([a-z]*\d+\.\d+[a-z]*)$/; +($nversion = $version) =~ y/0-9.//cd; ($cluster) = $ARGV[1] =~ /^([-.\w]+)$/; error 'invalid cluster name' unless defined $cluster; @@ -337,7 +341,7 @@ move_conffile "$datadir/pg_ident.conf", $confdir, $owneruid, $ownergid, '640', 'ident_file'; chown $owneruid, $ownergid, $datadir, $confdir, "$confdir/start.conf" or die "chown: $!"; -if ($version ge '8.0') { +if ($nversion ge '8.0') { PgCommon::set_conf_value $version, $cluster, 'postgresql.conf', 'data_directory', $datadir; } else { # pre-8.0 clusters did not have data_directory and thus need a pgdata symlink @@ -395,7 +399,7 @@ } # create autovacuum log file for servers < 8.1 -if ($version < 8.1) { +if ($nversion < 8.1) { $real_logfile = "/var/log/postgresql/pg_autovacuum-$version-$cluster.log"; if (! -e $real_logfile) { open L, ">$real_logfile" or error "could not create log file $real_logfile"; @@ -407,7 +411,7 @@ } # version specific default configuration tweaking -$conf_fn = "configure_$version"; +$conf_fn = "configure_$nversion"; $conf_fn =~tr/./_/; &$conf_fn if defined &$conf_fn and $newcluster; @@ -426,7 +430,7 @@ # so, enable SSL if ($newcluster && -e '/etc/ssl/certs/ssl-cert-snakeoil.pem' && - $ssl_key_access && $version ge '8.0') { + $ssl_key_access && $nversion ge '8.0') { symlink '/etc/ssl/certs/ssl-cert-snakeoil.pem', $datadir.'/server.crt'; symlink '/etc/ssl/private/ssl-cert-snakeoil.key', $datadir.'/server.key'; @@ -455,7 +459,7 @@ $createsuccess = 1; # configure to create external PID file -if ($version ge '8.0' && $socketdir eq '/var/run/postgresql') { +if ($nversion ge '8.0' && $socketdir eq '/var/run/postgresql') { PgCommon::set_conf_value $version, $cluster, 'postgresql.conf', 'external_pid_file', "/var/run/postgresql/$version-$cluster.pid"; } diff -rub usr/bin.o/pg_ctlcluster usr/bin/pg_ctlcluster --- usr/bin.o/pg_ctlcluster 2009-02-06 00:02:22.000000000 +0100 +++ usr/bin/pg_ctlcluster 2010-06-11 18:29:34.000000000 +0200 @@ -131,7 +131,7 @@ } sub autovacuum_start { - if ($version ge '8.1') { + if ($nversion ge '8.1') { error 'PostgreSQL 8.1 and above has an integrated autovacuum daemon which cannot be controlled by this program.'; } @@ -207,7 +207,7 @@ } sub autovacuum_stop { - if ($version ge '8.1') { + if ($nversion ge '8.1') { error 'PostgreSQL 8.1 and above has an integrated autovacuum daemon which cannot be controlled by this program.'; } @@ -226,7 +226,7 @@ } sub autovacuum_restart { - if ($version ge '8.1') { + if ($nversion ge '8.1') { error 'PostgreSQL 8.1 and above has an integrated autovacuum daemon which cannot be controlled by this program.'; } @@ -262,7 +262,7 @@ } # versions 8.0+ support configurable conffile locations and external PID files - if ($version ge '8.0') { + if ($nversion ge '8.0') { $postmaster_opts .= " -c config_file=\"$cdir/postgresql.conf\""; if (!(PgCommon::get_conf_value $version, $cluster, 'postgresql.conf', 'hba_file')) { $postmaster_opts .= " -c hba_file=\"$cdir/pg_hba.conf\""; @@ -348,7 +348,7 @@ } if ($success) { - if ($version lt '8.1' && $info{'avac_enable'} && $pg_autovacuum) { + if ($nversion lt '8.1' && $info{'avac_enable'} && $pg_autovacuum) { autovacuum_start; } } else { @@ -426,7 +426,8 @@ } ($version, $cluster, $action) = @ARGV; -($version) = $version =~ /^(\d+\.\d+)$/; # untaint +($version) = $version =~ /^([a-z]*\d+\.\d+[a-z]*)$/; # untaint +($nversion = $version) =~ y/0-9.//cd; ($cluster) = $cluster =~ /^([^'"\s]+)$/; # untaint error 'specified cluster does not exist' unless $version && $cluster && cluster_exists $version, $cluster; %info = cluster_info ($version, $cluster); diff -rub usr/bin.o/pg_dropcluster usr/bin/pg_dropcluster --- usr/bin.o/pg_dropcluster 2009-02-06 00:00:51.000000000 +0100 +++ usr/bin/pg_dropcluster 2010-06-11 18:30:38.000000000 +0200 @@ -22,7 +22,8 @@ exit 1; } -($version) = $ARGV[0] =~ /^(\d+\.\d+)$/; +($version) = $ARGV[0] =~ /^([a-z]*\d+\.\d+[a-z]*)$/; +($nversion = $version) =~ y/0-9.//cd; ($cluster) = $ARGV[1] =~ /^([-.\w]+)$/; error 'invalid version' unless defined $version; error 'invalid cluster name' unless defined $cluster; diff -rub usr/bin.o/pg_upgradecluster usr/bin/pg_upgradecluster --- usr/bin.o/pg_upgradecluster 2009-02-06 00:00:51.000000000 +0100 +++ usr/bin/pg_upgradecluster 2010-06-11 18:43:39.000000000 +0200 @@ -15,7 +15,7 @@ $ENV{'PATH'} = '/bin:/usr/bin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; -my ($version, $newversion, $cluster); +my ($version, $newversion, $nversion, $nnewversion, $cluster); my (%info, %newinfo); # do not trip over cwd not being accessible to postgres superuser @@ -60,7 +60,7 @@ 'ident_file', strrepl($c{'ident_file'}, $version, $newversion) if $c{'ident_file'}; PgCommon::set_conf_value $newversion, $cluster, 'postgresql.conf', 'external_pid_file', strrepl($c{'external_pid_file'}, $version, $newversion) if $c{'external_pid_file'}; - if ($newversion ge '8.0') { + if ($nnewversion ge '8.0') { PgCommon::set_conf_value $newversion, $cluster, 'postgresql.conf', 'data_directory', $newinfo{'pgdata'}; } @@ -87,7 +87,7 @@ } # sort_mem -> work_mem transition - rename_ \%c, 'sort_mem', 'work_mem' if $newversion ge '8.0'; + rename_ \%c, 'sort_mem', 'work_mem' if $nnewversion ge '8.0'; # log_statement transition if (defined $c{'log_statement'}) { @@ -115,7 +115,7 @@ # obsolete max_expr_depth deprecate \%c, 'max_expr_depth', 'does not exist any more, look at max_stack_depth'; - if ($newversion ge '8.1') { + if ($nnewversion ge '8.1') { # obsolete rendezvous_name deprecate \%c, 'rendezvous_name', 'obsolete in 8.1'; @@ -129,7 +129,7 @@ rename_ \%c, 'bgwriter_maxpages', 'bgwriter_all_maxpages'; } - if ($newversion ge '8.2') { + if ($nnewversion ge '8.2') { # preload_libraries -> shared_preload_libraries transition rename_ \%c, 'preload_libraries', 'shared_preload_libraries'; @@ -142,7 +142,7 @@ } } - if ($newversion ge '8.3') { + if ($nnewversion ge '8.3') { deprecate \%c, 'bgwriter_lru_percent', 'deprecated'; deprecate \%c, 'bgwriter_all_percent', 'deprecated'; deprecate \%c, 'bgwriter_all_maxpages', 'deprecated'; @@ -214,7 +214,8 @@ 'lc-time=s' => \$lc_time); # untaint -($newversion) = $newversion =~ /^(\d+\.\d+)$/; +($newversion) = $newversion =~ /^([a-z]*\d+\.\d+[a-z]*)$/; +($nnewversion = $newversion) =~ y/0-9.//cd; ($locale) = $locale =~ /^([...@._-]+)$/ if $locale; ($lc_collate) = $lc_collate =~ /^([...@._-]+)$/ if $lc_collate; ($lc_ctype) = $lc_ctype =~ /^([...@._-]+)$/ if $lc_ctype; @@ -228,7 +229,8 @@ exit 1; } -($version) = $ARGV[0] =~ /^(\d+\.\d+)$/; +($version) = $ARGV[0] =~ /^([a-z]*\d+\.\d+[a-z]*)$/; +($nversion = $version) =~ y/0-9.//cd; ($cluster) = $ARGV[1] =~ /^([-.\w]+)$/; my $datadir; ($datadir) = $ARGV[2] =~ /(.*)/ if defined $ARGV[2]; @@ -257,7 +259,7 @@ # check for users and groups with the same name when upgrading < 8.1 to >= # 8.1 - if ($version lt '8.1' && $newversion ge '8.1') { + if ($nversion lt '8.1' && $nnewversion ge '8.1') { my @samename; print "Checking for users and groups with the same name...\n"; open F, '-|', $oldpsql, '-h', $oldsocket, '-p', $info{'port'}, @@ -398,7 +400,7 @@ for my $db (keys %databases) { next if $db eq 'template0'; - if ($db eq 'postgres' && $newversion ge '8.1') { + if ($db eq 'postgres' && $nnewversion ge '8.1') { (system 'dropdb', '--cluster', "$newversion/$cluster", '-q', 'postgres'); } @@ -427,9 +429,9 @@ my @restore_argv = ($pg_restore, '-h', $newsocket, '-p', $newinfo{'port'}); if ($upgrade_scripts) { - if ($newversion eq '8.1') { + if ($nnewversion eq '8.1') { push @restore_argv, ('-X', 'no-data-for-failed-tables'); - } elsif ($newversion gt '8.1') { + } elsif ($nnewversion gt '8.1') { push @restore_argv, '--no-data-for-failed-tables'; } }
diff -rub usr/share/postgresql-common.o/maintscripts-functions usr/share/postgresql-common/maintscripts-functions --- usr/share/postgresql-common.o/maintscripts-functions 2009-02-06 00:00:51.000000000 +0100 +++ usr/share/postgresql-common/maintscripts-functions 2010-06-11 18:04:25.000000000 +0200 @@ -49,7 +49,8 @@ configure_contrib_version() { # later versions have integrated autovacuuming - [ "$1" = "7.4" -o "$1" = "8.0" ] || return 0 + v=`echo $1 | tr -cd '[0-9].'` + [ "$v" = "7.4" -o "$v" = "8.0" ] || return 0 if [ "$2" ]; then cmd="autovac-restart" @@ -66,7 +67,8 @@ remove_contrib_version() { # later versions have integrated autovacuuming - [ "$1" = "7.4" -o "$1" = "8.0" ] || return 0 + v=`echo $1 | tr -cd '[0-9].'` + [ "$v" = "7.4" -o "$v" = "8.0" ] || return 0 if [ -x /usr/sbin/invoke-rc.d ]; then invoke-rc.d postgresql-$1 autovac-stop || exit 0 diff -rub usr/share/postgresql-common.o/PgCommon.pm usr/share/postgresql-common/PgCommon.pm --- usr/share/postgresql-common.o/PgCommon.pm 2009-02-06 00:00:51.000000000 +0100 +++ usr/share/postgresql-common/PgCommon.pm 2010-06-11 18:17:17.000000000 +0200 @@ -441,7 +441,9 @@ # autovacuum settings - if ($_[0] lt '8.1') { + my $nversion; + ($nversion = $_[0]) =~ y/0-9.//cd; + if ($nversion lt '8.1') { $result{'avac_logfile'} = readlink ($result{'configdir'} . "/autovacuum_log"); ($result{'avac_logfile'}) = $result{'avac_logfile'} =~ /(.*)/; # untaint if (get_program_path 'pg_autovacuum', $_[0]) { @@ -472,7 +474,7 @@ my $entry; while (defined ($entry = readdir D)) { next if $entry eq '.' || $entry eq '..'; - ($entry) = $entry =~ /^(\d+\.\d+)$/; # untaint + ($entry) = $entry =~ /^([a-z]*\d+\.\d+[a-z]*)$/; # untaint push @versions, $entry if get_program_path ('psql', $entry); } closedir D; @@ -483,7 +485,8 @@ # Return the newest available version sub get_newest_version { my $newest = 0; - map { $newest = $_ if $newest < $_ } get_versions; + my $v; + map { ($v = $_) =~ y/0-9.//cd; $newest = $v if $newest < $v } get_versions; return $newest; } diff -rub usr/share/postgresql-common.o/run-upgrade-scripts usr/share/postgresql-common/run-upgrade-scripts --- usr/share/postgresql-common.o/run-upgrade-scripts 2009-02-06 00:00:51.000000000 +0100 +++ usr/share/postgresql-common/run-upgrade-scripts 2010-06-11 17:53:42.000000000 +0200 @@ -61,6 +61,7 @@ } my $upgraded_version = $ARGV[0]; +my ($nupgraded_version = $upgraded_version) =~ y/0-9.//cd; # determine path of upgrade scripts my @f = split(/\//, $0); @@ -74,9 +75,11 @@ my ($fname, $ext) = split /\./, $script; my ($version, $name, $scope) = split /_/, $fname; my $is_sql = (defined $ext && $ext eq 'sql'); + my ($nversion = $version) =~ y/0-9.//cd; + next unless defined ($scope) && ($is_sql || -x "$scriptpath/$script"); - next unless ($version eq 'all' || $upgraded_version <= $version); + next unless ($version eq 'all' || $nupgraded_version <= $nversion); print "Executing upgrade script $name...\n"; for my $v (get_versions) {