Re: postgres server failure during some database opearion

From: Shachar Shemesh <psql(at)shemesh(dot)biz>
To: Surabhi Ahuja <surabhi(dot)ahuja(at)iiitb(dot)ac(dot)in>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: postgres server failure during some database opearion
Date: 2005-02-10 12:45:12
Message-ID: 420B5758.4050502@shemesh.biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Surabhi Ahuja wrote:

> I have a query regarding, the postgres Sever failure, for eg say i am
> parsng a file and inserting rows into a table. Now while this
> opeartion is taking place the server crashes, or say the power goes
> off, or say someone kills the postmaster demon.
>
> what happens to the rows that have been inserted till now? can we get
> a status of how many rows have been installed or not?

I highly suggest you read about "transactions". That's exactly what they
are here for.

If you opened a transaction for the entire insert operation, or if it is
done in a single operation (say - insert ... from select ... ), then
none of the rows are in the database, and you can start the entire
operation over with no risk for data integrity.

If each operation is in a different transaction then it is up to you to
put some mechanism in place to count how many rows got in. For example,
assuming you don't need to support multiple clients simultaneously and
you can figure out by the last row inserted which is the next one, you
can can open a transaction, insert a row, update a second table with the
identifier of the last row successfully inserted, and flush the
transaction. This way, you can always know which is the last row
inserted in a reliable way.

From the sound of it, you really just want to perform the entire insert
operation inside one transaction.

> regards
> surabhi

Shachar

--
Shachar Shemesh
Lingnu Open Source Consulting ltd.
Have you backed up today's work? http://www.lingnu.com/backup.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2005-02-10 13:21:33 Re: postgres server failure during some database opearion
Previous Message Surabhi Ahuja 2005-02-10 12:25:08 postgres server failure during some database opearion