From: | Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com> |
---|---|
To: | "Adam Witney" <awitney(at)sghms(dot)ac(dot)uk>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Can COPY skip a header line? |
Date: | 2004-11-19 18:46:55 |
Message-ID: | opshp6ghl9cq72hf@musicbox |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> can do this fine with small files.... But if I get above a 1000 rows it
> takes so long it time out.
PHP is slow, but not *that* slow, you have a problem somewhere !
> I can upload a 10,000 row equivalent file using COPY from psql in 2
> seconds,
> so the time is down to the PHP processing (really all it does is send
> itto
> pg_put_Line)
If you read the whole file in memory, the server will kick your script (I
think the default limit is 8 megabytes or something)...
So, I'd advise reading the file line by line using fgets() (dunno how it
is spelled in php), and just skip the first line, and pg_put_line() the
rest. This way you just use memory for one line at a time. ALso you can
echo (and flush) messages like 'XX lines inserted...' to the user while it
crunches.
If you're really stuck, and have command execution privileges, why not
system() a command line like "awk -blah your file | psql copy to your
table", or even launch it as a background process ?
From | Date | Subject | |
---|---|---|---|
Next Message | Ian Harding | 2004-11-19 18:47:11 | Re: Can COPY skip columns? |
Previous Message | Taber, Mark | 2004-11-19 16:53:40 | Re: Phantom user in db--'128' |