Thread: Maximum PQsendQuery size?

Maximum PQsendQuery size?

From
Andreas Pflug
Date:
I'm having trouble with PQsendQuery if sending medium sized queries.
Everything's fine with queries up to 8190 bytes (0x1fffe), but one byte
more will not work.
In this case, PQsendQuery and PQconsumeInput will return ok, but
PQisBusy stays busy. How can I get around this?

Regards,

Andreas


Re: Maximum PQsendQuery size?

From
Andreas Pflug
Date:
Andreas Pflug wrote:

> I'm having trouble with PQsendQuery if sending medium sized queries.
> Everything's fine with queries up to 8190 bytes (0x1fffe), but one
> byte more will not work.
> In this case, PQsendQuery and PQconsumeInput will return ok, but
> PQisBusy stays busy. How can I get around this?
>
> Regards,
>
> Andreas
>
>
I already found a solution in pgsql/src/interfaces/libpq/fe-misc.c.

conn->outBuffer initially has 8k size. For a successful 8190 byte
execute, this contains a 'Q', the query and the terminating zero byte.
If pqPutBytes() finds avail to be too small, it will first try to
pqSendSome(), but this will not be good if the connection is nonblocking.

As a fix, the outbuffer is realloced to be big enough, before processing
continues:

        avail = Max(conn->outBufSize - conn->outCount, 0);
 >>>>>
        if (nbytes > avail && pqIsnonblocking(conn))
        {
            char *newbuf;
            conn->outBufSize = conn->outBufSize  - avail + nbytes;
            newbuf = realloc(conn->outBuffer, conn->outBufSize);
            conn->outBuffer = newbuf;
            avail = conn->outBufSize - conn->outCount;
        }
<<<<<
        remaining = Min(avail, nbytes);


pgadmin3 (to be found at
http://www.pse-consulting.de/pgadmin3/pgadmin3.zip) ist linked with this
patched libpq.


Regards,
Andreas


Re: Maximum PQsendQuery size?

From
"Dave Page"
Date:
Hi Andreas,

Have you reported this to the pg hackers?

Regards, Dave.

> -----Original Message-----
> From: Andreas Pflug [mailto:Andreas.Pflug@web.de]
> Sent: 31 March 2003 17:57
> To: pgadmin-hackers@postgresql.org
> Subject: Re: [pgadmin-hackers] Maximum PQsendQuery size?
>
>
> Andreas Pflug wrote:
>
> > I'm having trouble with PQsendQuery if sending medium sized
> queries.
> > Everything's fine with queries up to 8190 bytes (0x1fffe), but one
> > byte more will not work. In this case, PQsendQuery and
> PQconsumeInput
> > will return ok, but PQisBusy stays busy. How can I get around this?
> >
> > Regards,
> >
> > Andreas
> >
> >
> I already found a solution in pgsql/src/interfaces/libpq/fe-misc.c.
>
> conn->outBuffer initially has 8k size. For a successful 8190 byte
> execute, this contains a 'Q', the query and the terminating
> zero byte.
> If pqPutBytes() finds avail to be too small, it will first try to
> pqSendSome(), but this will not be good if the connection is
> nonblocking.
>
> As a fix, the outbuffer is realloced to be big enough, before
> processing
> continues:
>
>         avail = Max(conn->outBufSize - conn->outCount, 0);  >>>>>
>         if (nbytes > avail && pqIsnonblocking(conn))
>         {
>             char *newbuf;
>             conn->outBufSize = conn->outBufSize  - avail + nbytes;
>             newbuf = realloc(conn->outBuffer, conn->outBufSize);
>             conn->outBuffer = newbuf;
>             avail = conn->outBufSize - conn->outCount;
>         }
> <<<<<
>         remaining = Min(avail, nbytes);
>
>
> pgadmin3 (to be found at
> http://www.pse-consulting.de/pgadmin3/pgadmin3.zip) ist
> linked with this
> patched libpq.
>
>
> Regards,
> Andreas
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
>