COPY problems with psql / libpq
COPY problems with psql / libpq
От:
"Oliver Elphick" <olly@lfix.co.uk>
Дата:
[Using current cvs] I have a problem with COPY when called like this: psql -e bray
Re: [HACKERS] COPY problems with psql / libpq
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Oliver Elphick" writes: > I found that if I broke the first 1000 records into 2 equal parts, all > of them were added correctly without error; so I conclude that data > is being buffered and lost somewhere in psql or libpq, and the problem is > dependent on the amount of data being copied. I have the following note in my (much too long) to-do list: : psql.c doesn't appear to cope correctly with quoted newlines in COPY data; : if one falls just after a buffer boundary, trouble! : Does fe-exec.c work either?? (This note is some months old, and may or may not still apply since Peter's rework of psql.) It could be that your dataset is hitting this problem or a similar one. A buffer-boundary problem would explain why the error seems to be so dataset-specific. > copy address from stdin; > -- 1000 records written > select count(*) from address; > PQexec: you gotta get out of a COPY state yourself. It sure sounds like psql is failing to recognize the trailing \. of the COPY data. regards, tom lane
Re: [HACKERS] COPY problems with psql / libpq
От:
Patrick Welche <prlw1@newn.cam.ac.uk>
Дата:
On Thu, Jan 20, 2000 at 11:02:31AM -0500, Tom Lane wrote: > > It sure sounds like psql is failing to recognize the trailing \. > of the COPY data. Precisely what I saw yesterday (cf Subject: pg_dump disaster) - but what does one do about it? Cheers, Patrick
Re: [HACKERS] COPY problems with psql / libpq
От:
Alfred Perlstein <bright@wintelcom.net>
Дата:
* Patrick Welche [000120 09:10] wrote: > On Thu, Jan 20, 2000 at 11:02:31AM -0500, Tom Lane wrote: > > > > It sure sounds like psql is failing to recognize the trailing \. > > of the COPY data. > > Precisely what I saw yesterday (cf Subject: pg_dump disaster) - but what > does one do about it? Is this with a recent snapshot or 6.5.3 using libpq? Either way, you should check the contents of the send buffer, please let me know if there is data queued in it. You can include the 'internal' header for libpq (libpq-int.h?) to get at the send buffer. -Alfred
Re: [HACKERS] COPY problems with psql / libpq
От:
Patrick Welche <prlw1@newn.cam.ac.uk>
Дата:
On Thu, Jan 20, 2000 at 09:22:16AM -0800, Alfred Perlstein wrote: > * Patrick Welche [000120 09:10] wrote: > > On Thu, Jan 20, 2000 at 11:02:31AM -0500, Tom Lane wrote: > > > > > > It sure sounds like psql is failing to recognize the trailing \. > > > of the COPY data. > > > > Precisely what I saw yesterday (cf Subject: pg_dump disaster) - but what > > does one do about it? > > Is this with a recent snapshot or 6.5.3 using libpq? For me, it's using yesterday's cvs'd source - but I obviously can't speak for Oliver. > Either way, you should check the contents of the send buffer, please let > me know if there is data queued in it. You can include the 'internal' > header for libpq (libpq-int.h?) to get at the send buffer. That will take a while. In the meantime, just pg_dumpall something and try to read the output back in. I do have ^M's in some of the text columns if that matters. Cheers, Patrick
Re: [HACKERS] COPY problems with psql / libpq
От:
"Oliver Elphick" <olly@lfix.co.uk>
Дата:
Patrick Welche wrote: >On Thu, Jan 20, 2000 at 09:22:16AM -0800, Alfred Perlstein wrote: >> * Patrick Welche [000120 09:10] wrote: >> > On Thu, Jan 20, 2000 at 11:02:31AM -0500, Tom Lane wrote: >> > > >> > > It sure sounds like psql is failing to recognize the trailing \. >> > > of the COPY data. >> > >> > Precisely what I saw yesterday (cf Subject: pg_dump disaster) - but what >> > does one do about it? >> >> Is this with a recent snapshot or 6.5.3 using libpq? > >For me, it's using yesterday's cvs'd source - but I obviously can't speak >for Oliver. This morning's. >> Either way, you should check the contents of the send buffer, please let >> me know if there is data queued in it. You can include the 'internal' >> header for libpq (libpq-int.h?) to get at the send buffer. > >That will take a while. In the meantime, just pg_dumpall something and try >to read the output back in. I do have ^M's in some of the text columns if >that matters. I can't do that, because pg_dump seems to be broken if there are tables with foreign key constraints. (See a separate message.) -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight http://www.lfix.co.uk/oliver PGP key from public servers; key ID 32B8FAA1 ======================================== "Neither is there salvation in any other; for there is none other name under heaven given among men, whereby we must be saved." Acts 4:12
Re: [HACKERS] COPY problems with psql / libpq
От:
"Oliver Elphick" <olly@lfix.co.uk>
Дата:
Tom Lane wrote: >"Oliver Elphick" writes: >> I found that if I broke the first 1000 records into 2 equal parts, all >> of them were added correctly without error; so I conclude that data >> is being buffered and lost somewhere in psql or libpq, and the problem is >> dependent on the amount of data being copied. > >I have the following note in my (much too long) to-do list: > >: psql.c doesn't appear to cope correctly with quoted newlines in COPY data; >: if one falls just after a buffer boundary, trouble! >: Does fe-exec.c work either?? New-lines are not the problem in this particular case, since the data does not contain any. -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight http://www.lfix.co.uk/oliver PGP key from public servers; key ID 32B8FAA1 ======================================== "Neither is there salvation in any other; for there is none other name under heaven given among men, whereby we must be saved." Acts 4:12
Re: [HACKERS] COPY problems with psql / libpq
От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
On 2000-01-20, Tom Lane mentioned: > "Oliver Elphick" writes: > > I found that if I broke the first 1000 records into 2 equal parts, all > > of them were added correctly without error; so I conclude that data > > is being buffered and lost somewhere in psql or libpq, and the problem is > > dependent on the amount of data being copied. The buffering is line-based though and the default buffer is 8192. If your line is longer than that you're in all sorts of other troubles. > > I have the following note in my (much too long) to-do list: > > : psql.c doesn't appear to cope correctly with quoted newlines in COPY data; What's a quoted newline? a) "" b) "\n" c) \ Earlier you also mentioned to me something in general about control characters messing up COPY. Could you give me some details on that so I can look into it? > : if one falls just after a buffer boundary, trouble! > : Does fe-exec.c work either?? > > (This note is some months old, and may or may not still apply since > Peter's rework of psql.) It could be that your dataset is hitting this I haven't touched that code. > problem or a similar one. A buffer-boundary problem would explain why > the error seems to be so dataset-specific. At first I thunk a PQExpBuffer based solution would be the answer, but as I said above, if you overflow the buffer, you're in trouble anyway. > > > copy address from stdin; > > -- 1000 records written > > select count(*) from address; > > PQexec: you gotta get out of a COPY state yourself. > > It sure sounds like psql is failing to recognize the trailing \. > of the COPY data. The last call in the function psql/copy.c:handleCopyIn is return !PQendcopy(conn); and there is no way it can exit earlier. Also the connection seems to be good, since that's checked right after it returns. The calls to PQputvalue are not checked for return values, so problems might get missed there, but that would in any case still point to a problem elsewhere. Gotta pass the buck to libpq ... -- Peter Eisentraut Sernanders väg 10:115 peter_e@gmx.net 75262 Uppsala http://yi.org/peter-e/ Sweden
Re: [HACKERS] COPY problems with psql / libpq
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut writes: >> : psql.c doesn't appear to cope correctly with quoted newlines in COPY data; > What's a quoted newline? > a) "" > b) "\n" > c) \ (c). That's how a newline appearing in the data is supposed to be represented. IIRC, I was worried that if the \ falls at the end of a bufferload and the newline at the start of the next, psql and/or libpq would fail to recognize the pattern; if so, they'd probably think the newline is a record boundary. Patrick could be falling victim to this, but Oliver sez he has no newlines in his data, so there's at least one other problem. > that would in any case still point to a problem elsewhere. Gotta pass the > buck to libpq ... Could be. I think Alfred is on the hook here... regards, tom lane