Unix Technical Forum

postgres Recover Deleted Data

This is a discussion on postgres Recover Deleted Data within the pgsql Admins forums, part of the PostgreSQL category; --> Hi, I accidentally deleted two records in one of my tables, the problem I had not done a back ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Admins

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 12:18 AM
Martin Kuria
 
Posts: n/a
Default postgres Recover Deleted Data

Hi,
I accidentally deleted two records in one of my tables, the problem I had
not done a back for the database.

I can I restore my records, please advice how I can recover my deleted
records, thanks again.

Kind Regards,
+-----------------------------------------------------+
| Martin W. Kuria (Mr.) martin.kuria@unon.org
+----------------------------------------------------+

__________________________________________________ _______________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/...ave/direct/01/


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 12:18 AM
Michael Fuhr
 
Posts: n/a
Default Re: postgres Recover Deleted Data

On Mon, Jan 17, 2005 at 11:42:20AM +0300, Martin Kuria wrote:

> I accidentally deleted two records in one of my tables, the problem I had
> not done a back for the database.
>
> I can I restore my records, please advice how I can recover my deleted
> records, thanks again.


If you haven't VACUUMed the database then the deleted rows are
probably still there. I don't know if any recovery tools exist,
but to have any chance of recovering the data make a filesystem
backup of $PGDATA as soon as possible, or at least make a backup
of the table's file(s) (see below). They might not do you any good,
but you'll probably need those files if you do find any recovery
tools.

If you don't find any recovery tools and you *really* need to get
the data back, then you might enjoy reading the chapter describing
page file formats in the documentation ("Page Files" in PostgreSQL
7.x; "Database Physical Storage" in the upcoming 8.0).

You can find out which files hold a table's data by querying
pg_database and pg_class. For example, suppose I have a table "foo"
in the database "test". I connect to the database and issue the
following queries:

SELECT oid FROM pg_database WHERE datname = current_database();
oid
-------
26492
(1 row)

SELECT relfilenode, reltoastrelid FROM pg_class WHERE relname = 'foo';
relfilenode | reltoastrelid
-------------+---------------
36008 | 36011

The table's main file is $PGDATA/base/26492/36008 (also 36008.1,
36008.2, etc. if they exist). If reltoastrelid has a value other
than 0, then you'll also want to find out where the table's TOAST
data is stored:

SELECT relname, relfilenode FROM pg_class WHERE oid = 36011;
relname | relfilenode
----------------+-------------
pg_toast_36008 | 36011

The table's TOAST data is in $PGDATA/base/26492/36011*.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:48 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com