~ubuntu-branches/ubuntu/hardy/postgresql-common/hardy-backports

« back to all changes in this revision

Viewing changes to PgCommon.pm

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-21 16:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20071021160108-6bp6fxhst130l0do
Tags: 80
* pg_upgradecluster: Fix locale error checking.
* pg_upgradecluster: Use cluster_exists() instead of
  cluster_data_directory().
* PgCommon.pm: Fix cluster_data_directory() to consider the data_directory
  setting in postgresql.conf, which should trump the /pgdata symbolic link.
* debian/init.d-functions: Check for 'postgresql.conf' instead of 'pgdata'
  in the test for a valid cluster configuration directory, since 'pgdata' is
  optional now.
* pg_createcluster: Do not create pgdata symlinks to the data directory in
  /etc any more when configuring a >= 8.0 cluster. Use the data_directory
  configuration option instead. (Part of #444689)
* t/020_create_sql_remove.t: Check that clusters still work when replacing
  the data_directory setting with a pgdata symbolic link, and that
  the data_directory setting trumps the symlink.
* pg_upgradecluster: Set correct data_directory config option after copying
  over the old configuration files.
* t/060_obsolete_confparams.t: Restore data_directory setting after
  scribbling over the configuration file with our template.
* PgCommon.pm, cluster_info(): Only return a value for 'logfile' when it is
  not explicitly configured with log_directory and/or log_filename. The
  previous guessing was wrong anyway, since PostgreSQL always appends a
  pretty unpredictable timestamp.
* pg_ctlcluster: Only do log file checks and pass pg_ctl -l option when the
  log file default is used. Otherwise let PostgreSQL do its logfile handling
  and waive log file checks, since we don't know which file is used.
* pg_ctlcluster: Redirect pg_ctl's stdout and stderr to /dev/null, otherwise
  it will hang forever when using a custom log file (and thus not passing
  -l).
* pg_lsclusters: Print "custom" as log file location if a custom one was set
  in postgresql.conf.
* pg_upgradecluster: Enable 'redirect_stderr' in the 7.4 -> 8.x migration of
  'syslog' -> 'log_destination', so that the log output is actually
  complete.
* t/060_obsolete_confparams.t: Enable 'redirect_stderr' in the template
  postgresql.conf's, so that we actually capture log output.
* t/020_create_sql_remove.t: Check proper handling of logs when configuring
  log file in postgresql.conf, using the log symlink, or having neither.
* PgCommon.pm, cluster_info(): Return default log file in 'logfile' if
  neither postgresql.conf nor a 'log' symlink explicitly specify a log file.
* pg_createcluster: Do not create log symlink if using the default log file
  (i. e. when not using -l). (Closes: #444689)
* t/020_create_sql_remove.t: Verify that log symlink is not created by
  default.
* architecture.html: Update to current reality.
* debian/postgresql-common.config: Do not consider versions as obsolete if
  they are newer than the latest officially supported version. This avoids
  confusion when testing new betas in experimental or using backports.
  (Closes: #446635)
* t/TestLib.pm: Make exec_as() work with user name 'root' (not just uid 0).
* Add t/130_nonroot_admin.t: Check that administrative pg_ tools work as
  non-root, too, if the invoker has sufficient permissions on the
  directories (test case for LP #90036).
* pg_{create,drop,upgrade}cluster: Small tweaks to make the scripts work for
  non-root users with sufficient write permissions to
  /etc/postgresql/<version>, /var/lib/postgresql/<version>, and
  /var/log/postgresql. (LP: #90036)

Show diffs side-by-side

added added

removed removed

Lines of Context:
254
254
}
255
255
 
256
256
# Return cluster data directory.
257
 
# Arguments: <version> <cluster name>
 
257
# Arguments: <version> <cluster name> [<config_hash>]
258
258
sub cluster_data_directory {
259
 
    my $d = readlink "$confroot/$_[0]/$_[1]/pgdata";
 
259
    my $d;
 
260
    if ($_[2]) {
 
261
        $d = ${$_[2]}{'data_directory'};
 
262
    } else {
 
263
        $d = get_conf_value($_[0], $_[1], 'postgresql.conf', 'data_directory');
 
264
    }
 
265
    if (!$d) {
 
266
        # fall back to /pgdata symlink (supported by earlier p-common releases)
 
267
        $d = readlink "$confroot/$_[0]/$_[1]/pgdata";
 
268
    }
260
269
    ($d) = $d =~ /(.*)/ if defined $d; #untaint
261
270
    return $d;
262
271
}
279
288
 
280
289
    if ($_[0] && $_[1]) {
281
290
        my $datadir = cluster_data_directory $_[0], $_[1];
282
 
        error "Invalid symbolic link $confroot/$_[0]/$_[1]/pgdata" unless $datadir;
 
291
        error "Invalid data directory" unless $datadir;
283
292
        my @datadirstat = stat $datadir;
284
293
        unless (@datadirstat) {
285
294
            my @p = split '/', $datadir;
398
407
 
399
408
# Return a hash with information about a specific cluster.
400
409
# Arguments: <version> <cluster name>
401
 
# Returns: information hash (keys: pgdata, port, running, logfile, configdir,
402
 
# owneruid, ownergid, socketdir)
 
410
# Returns: information hash (keys: pgdata, port, running, logfile [unless it
 
411
#          has a custom one], configdir, owneruid, ownergid, socketdir)
403
412
sub cluster_info {
404
413
    error 'cluster_info must be called with <version> <cluster> arguments' unless $_[0] && $_[1];
405
414
 
406
415
    my %result;
407
416
    $result{'configdir'} = "$confroot/$_[0]/$_[1]";
408
 
    $result{'pgdata'} = cluster_data_directory $_[0], $_[1];
409
417
    my %postgresql_conf = read_cluster_conf_file $_[0], $_[1], 'postgresql.conf';
 
418
    $result{'pgdata'} = cluster_data_directory $_[0], $_[1], \%postgresql_conf;
410
419
    $result{'port'} = $postgresql_conf{'port'} || $defaultport;
411
420
    $result{'socketdir'} = get_cluster_socketdir  $_[0], $_[1];
412
421
    $result{'running'} = cluster_port_running ($_[0], $_[1], $result{'port'});
416
425
    }
417
426
    $result{'start'} = get_cluster_start_conf $_[0], $_[1];
418
427
 
419
 
    # log file
420
 
    if (exists $postgresql_conf{'log_filename'} || 
 
428
    # default log file (only if not expliticly configured in postgresql.conf)
 
429
    unless (exists $postgresql_conf{'log_filename'} || 
421
430
        exists $postgresql_conf{'log_directory'}) {
422
 
        my $dir;
423
 
        if ( exists $postgresql_conf{'log_directory'} && (substr $postgresql_conf{'log_directory'}, 0, 1) eq '/') {
424
 
            $dir = $postgresql_conf{'log_directory'} || $result{'pgdata'};
425
 
        } else {
426
 
            $dir = $result{'pgdata'} . '/' . ($postgresql_conf{'log_directory'} || '');
427
 
        }
428
 
 
429
 
        my $fname = $postgresql_conf{'log_filename'} || 'postgresql-%Y-%m-%d_%H%M%S.log';
430
 
        $fname .= '.%s' if (index $fname, '%') < 0;
431
 
        $fname = strftime $fname, localtime;
432
 
 
433
 
        $result{'logfile'} = "$dir/$fname";
434
 
    } else {
435
 
        $result{'logfile'} = readlink ($result{'configdir'} . "/log");
 
431
        my $log_symlink = $result{'configdir'} . "/log";
 
432
        if (-l $log_symlink) {
 
433
            ($result{'logfile'}) = readlink ($log_symlink) =~ /(.*)/; # untaint
 
434
        } else {
 
435
            $result{'logfile'} = "/var/log/postgresql/postgresql-$_[0]-$_[1].log";
 
436
        }
436
437
    }
437
 
    ($result{'logfile'}) = $result{'logfile'} =~ /(.*)/; # untaint
438
438
 
439
439
    # autovacuum settings
440
440
 
455
455
            $result{'avac_enable'} = 0;
456
456
        }
457
457
    } else {
458
 
        $result{'avac_enable'} = config_bool $postgresql_conf{'autovacuum'};
 
458
        # autovacuum defaults to on since 8.3
 
459
        $result{'avac_enable'} = config_bool $postgresql_conf{'autovacuum'} || ($_[0] ge '8.3');
459
460
    }
460
461
    
461
462
    return %result;
496
497
        my $entry;
497
498
        while (defined ($entry = readdir D)) {
498
499
            ($entry) = $entry =~ /^(.*)$/; # untaint
499
 
            if (-l $vdir.$entry.'/pgdata' && -r $vdir.$entry.'/postgresql.conf') {
 
500
            if (-r $vdir.$entry.'/postgresql.conf') {
500
501
                push @clusters, $entry;
501
502
            }
502
503
        }