Skip site navigation (1) Skip section navigation (2)

Recovery from hard drive failure ... the hard way ...

From: The Hermit Hacker <scrappy(at)hub(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Cc: pgsql_support(at)pgsql(dot)com
Subject: Recovery from hard drive failure ... the hard way ...
Date: 2000-09-27 19:56:34
Message-ID: Pine.BSF.4.21.0009271653031.4209-100000@thelab.hub.org (view raw or flat)
Thread:
Lists: pgsql-hackers
Well all, I just spent a bit of time trying to figure out how to recover a
database where the tables appear to be intact with postgres in 'single
user mode', and came up with a quick and dirty that might not be totally
complete, but might help someone else in a similar situation ...

----------------------
#!/usr/bin/perl

$table = $ARGV[0];

while(<STDIN>) {
  if(length($fields) > 0 && /\s+----/) {
    print "INSERT INTO $table ( $fields ) VALUES ( $values );\n";
    $fields = "";
    $values = "";
  }
  if(/\s+\d: (\w+) = "(.+)"/) {
    if(length($fields) > 0) { $fields .= ","; }
    $fields .= $1;
    if(length($values) > 0) { $values .= ","; }
    if(/typeid = 23/) {
      $values .= $2;
    } else {
      $values .= "'" . $2 . "'";
    }
  }
}
----------------------

To run it, use:

echo "SELECT * FROM <table>;" | \
~/bin/postgres -O -P -D/home/staff/scrappy/recovery/sales.org <database> | \
../convert.pl <table>

Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
Systems Administrator @ hub.org 
primary: scrappy(at)hub(dot)org           secondary: scrappy(at){freebsd|postgresql}.org 


pgsql-hackers by date

Next:From: Mikheev, VadimDate: 2000-09-27 20:14:53
Subject: RE: Re: function crashes backend
Previous:From: Jim MercerDate: 2000-09-27 15:02:06
Subject: Re: Installation layout is still hazardous for shared prefixes

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group