Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: Unloading a...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 15443 of 16553
Post > Topic >>

Re: Unloading a table consistently

by tgl@[EMAIL PROTECTED] (Tom Lane) May 3, 2008 at 12:56 PM

Christophe <xof@[EMAIL PROTECTED]
> writes:
> I will have a log table which, once a day or so, is copied to a file  
> (for movement to a data warehouse), and the log table emptied.  For  
> performance, the log table on the production system has no indexes,  
> and is write-only.  (The unload process is the only reader.)

> To unload it, I will be doing:

> BEGIN;
> SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
> COPY log TO 'filename-path';
> TRUNCATE log;
> COMMIT;

> My understanding is that I need the SERIALIZABLE isolation level so  
> that the COPY and TRUNCATE see exactly the same view of the table.   

No, the SERIALIZABLE bit is useless if not actually counterproductive
here.  What you'll actually need is an exclusive lock:

BEGIN;
LOCK TABLE log;
COPY log TO 'filename-path';
TRUNCATE log;
COMMIT;

to prevent anyone from inserting new rows during the COPY.  Otherwise
any such rows would be lost at the TRUNCATE.

You might be able to get away with a lock that only locks out writers
and not readers (offhand I think IN SHARE MODE is the right thing),
but from your description that would be a useless refinement anyway.

If you can't tolerate locking out writers for that long, you won't
be able to use TRUNCATE.  The operation I think you were imagining is

BEGIN;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
COPY log TO 'filename-path';
DELETE FROM log;
COMMIT;
VACUUM log;	-- highly recommended at this point

Here, the serializable mode is exactly what you want to guarantee
that the DELETE deletes the same rows the COPY copied.  This is
a great deal less efficient than TRUNCATE, but it's secure for
concurrent insertions, which TRUNCATE is definitely not.

			regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 6 Posts in Topic:
Unloading a table consistently
xof@[EMAIL PROTECTED] (C  2008-05-03 09:11:16 
Re: Unloading a table consistently
tgl@[EMAIL PROTECTED] (T  2008-05-03 12:56:57 
Re: Unloading a table consistently
xof@[EMAIL PROTECTED] (C  2008-05-03 10:24:36 
Re: Unloading a table consistently
ptjm@[EMAIL PROTECTED] (  2008-05-03 23:29:11 
Re: Unloading a table consistently
craig@[EMAIL PROTECTED]   2008-05-04 23:28:16 
Re: Unloading a table consistently
xof@[EMAIL PROTECTED] (C  2008-05-04 12:07:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 22:31:09 CDT 2008.