Commit 96ea2709 authored by Martin Pitt's avatar Martin Pitt

* pg_dropcluster: Clean up half-existing broken cluster configurations

  (which happen when disk becomes full, etc) instead of failing. (part of
  bug #368335).
* t/030_errors.t: Test that pg_dropcluster copes with broken cluster
  configurations.
parent a16038a1
postgresql-common (55) unstable; urgency=low
* Add missing procps dependency to p-common. Closes: #369768
* pg_dropcluster: Clean up half-existing broken cluster configurations
(which happen when disk becomes full, etc) instead of failing. (part of
bug #368335).
* t/030_errors.t: Test that pg_dropcluster copes with broken cluster
configurations.
-- Martin Pitt <mpitt@debian.org> Thu, 1 Jun 2006 10:54:27 +0200
-- Martin Pitt <mpitt@debian.org> Thu, 1 Jun 2006 22:29:43 +0200
postgresql-common (54) unstable; urgency=low
......
......@@ -28,25 +28,33 @@ error 'This command needs to be executed as root' if $> != 0;
($cluster) = $ARGV[1] =~ /^([-.\w]+)$/;
error 'invalid version' unless defined $version;
error 'invalid cluster name' unless defined $cluster;
error 'specified cluster does not exist' unless cluster_exists $version, $cluster;
%info = cluster_info ($version, $cluster);
if ($info{'running'}) {
if ($stopserver) {
if ($info{'pgdata'} && -d $info{'pgdata'}) {
if (system ('pg_ctlcluster', $version, $cluster, 'stop')) {
error 'could not stop server, aborting';
}
} else {
print STDERR "warning: corrupted cluster: data directory does not exist any more, but server is still running; you have to manually kill the postmaster process\n";
}
} else {
error 'This cluster is still running. Stop it or supply the --stop option';
my %info;
my $c; # configuration directory
if (cluster_exists $version, $cluster) {
%info = cluster_info ($version, $cluster);
if ($info{'running'}) {
if ($stopserver) {
if ($info{'pgdata'} && -d $info{'pgdata'}) {
if (system ('pg_ctlcluster', $version, $cluster, 'stop')) {
error 'could not stop server, aborting';
}
} else {
print STDERR "warning: corrupted cluster: data directory does not exist any more, but server is still running; you have to manually kill the postmaster process\n";
}
} else {
error 'This cluster is still running. Stop it or supply the --stop option';
}
}
$c = $info{'configdir'};
} else {
$c = "/etc/postgresql/$version/$cluster";
# check if we have a broken cluster, clean up if necessary
-d $c or error 'specified cluster does not exist';
}
$c = $info{'configdir'};
if ($info{'pgdata'} && -d $info{'pgdata'}) {
$result = system '/bin/rm', '-r', $info{'pgdata'};
exit $result if $result;
......
......@@ -4,7 +4,7 @@ use strict;
use lib 't';
use TestLib;
use Test::More tests => 89;
use Test::More tests => 111;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -194,4 +194,35 @@ check_nonexisting_cluster_error "pg_ctlcluster $MAJORS[0] foo stop";
check_clean;
# check that pg_dropcluster copes with partially existing cluster
# configurations (which can happen if the disk becomes full)
mkdir '/etc/postgresql/';
mkdir "/etc/postgresql/$MAJORS[-1]";
mkdir "/etc/postgresql/$MAJORS[-1]/broken" or die "mkdir: $!";
symlink "/var/lib/postgresql/$MAJORS[-1]/broken", "/etc/postgresql/$MAJORS[-1]/broken/pgdata" or die "symlink: $!";
unlike_program_out 0, "pg_dropcluster $MAJORS[-1] broken", 0, qr/error/i,
'pg_dropcluster cleans up broken cluster configuration (only /etc with pgdata)';
check_clean;
mkdir '/etc/postgresql/';
mkdir '/var/lib/postgresql/';
mkdir "/etc/postgresql/$MAJORS[-1]" and
mkdir "/etc/postgresql/$MAJORS[-1]/broken";
mkdir "/var/lib/postgresql/$MAJORS[-1]";
mkdir "/var/lib/postgresql/$MAJORS[-1]/broken";
mkdir "/var/lib/postgresql/$MAJORS[-1]/broken/base" or die "mkdir: $!";
symlink "/var/lib/postgresql/$MAJORS[-1]/broken", "/etc/postgresql/$MAJORS[-1]/broken/pgdata" or die "symlink: $!";
open F, ">/etc/postgresql/$MAJORS[-1]/broken/postgresql.conf" or die "open: $!";
close F;
open F, ">/var/lib/postgresql/$MAJORS[-1]/broken/PG_VERSION" or die "open: $!";
close F;
unlike_program_out 0, "pg_dropcluster $MAJORS[-1] broken", 0, qr/error/i,
'pg_dropcluster cleans up broken cluster configuration (/etc with pgdata and postgresql.conf and partial /var)';
check_clean;
# vim: filetype=perl
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment