From: | Federico Di Gregorio <federico(dot)digregorio(at)dndg(dot)it> |
---|---|
To: | psycopg(at)postgresql(dot)org |
Subject: | Re: performance of copy_from() vs. raw COPY command |
Date: | 2011-06-25 16:45:16 |
Message-ID: | 4E06109C.2010301@dndg.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
On 24/06/11 20:38, Daniel Lenski wrote:
> I'm using Postgre's COPY feature to populate a large table (~500M
> rows, 100 GB) with frequent updates from CSV text files. Currently
> I'm using psycopg's copy_expert():
>
> cur.copy_expert("COPY Table (c1, c2, ...) FROM STDIN WITH CSV",
> open(filename))
>
> This avoids any issue with client vs. server file permissions, but I'm
> wondering if it carries a significant performance penalty by reading
> the text file at the Python level rather than the OS level. Instead I
> could do:
>
> cur.execute("COPY Table (c1, c2, ...) FROM $$%s$$ WITH CSV" % fn)
>
> Of course, this opens up a whole host of permissions and security
> issues. Is there any reason to believe that the Python file interface
> significantly slows down COPY FROM?
Using copy_expert() is inherently slower than reading file on the server
because you read it into Python's memory, transfer it to the backend
going through libpq and finally parsing it on the server. Python surely
has some kind of overhead but I don't think is much. Storing the file on
the server and reading it from there is surely faster.
Hope this helps,
federico
--
Federico Di Gregorio federico(dot)digregorio(at)dndg(dot)it
Studio Associato Di Nunzio e Di Gregorio http://dndg.it
Those who do not study Lisp are doomed to reimplement it. Poorly.
-- from Karl M. Hegbloom .signature
From | Date | Subject | |
---|---|---|---|
Next Message | Joe Abbate | 2011-06-28 01:33:42 | Listing in Software Catalogue |
Previous Message | Israel Ben Guilherme Fonseca | 2011-06-24 19:54:25 | Re: Unpacking a Python list in a query. |