pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pqReadData()  error
4+ messages / 4 participants
[nested] [flat]

* pqReadData()  error
@ 1999-11-25 12:23 Dipankar Chakrabarti <dipanc@yahoo.com>
  1999-11-25 12:37 ` Re: [SQL] pqReadData()  error Jan Wieck <wieck@debis.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Dipankar Chakrabarti @ 1999-11-25 12:23 UTC (permalink / raw)
  To: pgsql-sql@hub.org

Hi,

I am creating functions from saved in text files on
PostgreSQL 6.5 on linux by
$ psql mydb2 <myfunc.txt

If the function is large ( more than say 50 lines) or
I am creating small functions in series ( like
myfunc1, myfunc2, myfunc3),
suddenly I am getting the following error:
----------------------------------------------
pqReadData() -- backend closed the channel
unexpectedly.
        This probably means the backend terminated
abnormally
        before or while processing the request.
We have lost the connection to the backend, so further
processing is impossible.
  Terminating.
---------------------------------------------------

After exiting from telnet session and re-entering, I
may create the function again.

I am baffled by this odd behaviour.
Could any body help me with some suggestions?

Regards,

Dipankar Chakrabarti
Senior Manager (Projects)
Mindteck (I) Ltd.


__________________________________________________
Do You Yahoo!?
Thousands of Stores.  Millions of Products.  All in one place.
Yahoo! Shopping: http://shopping.yahoo.com



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] pqReadData()  error
  1999-11-25 12:23 pqReadData()  error Dipankar Chakrabarti <dipanc@yahoo.com>
@ 1999-11-25 12:37 ` Jan Wieck <wieck@debis.com>
  0 siblings, 0 replies; 4+ messages in thread

From: wieck@debis.com @ 1999-11-25 12:37 UTC (permalink / raw)
  To: dipanc@yahoo.com; +Cc: pgsql-sql@hub.org

>
> Hi,
>
> I am creating functions from saved in text files on
> PostgreSQL 6.5 on linux by
> $ psql mydb2 <myfunc.txt
>
> If the function is large ( more than say 50 lines) or

    Maybe the functions text portion exceeds 2K?

    There  is  an  index on functions source text in version 6.5.
    It's totally useless, left over from the history.  Now  there
    is  some problem with btree indices when the items exceed 2K,
    that can crash the backend.

    I've removed this index in the actual 7.0 tree.  It's  not  a
    trivial   task   and   requires   an  initdb  run  after  the
    modification. If you want to give it a try, I might help  you
    to do it.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#========================================= wieck@debis.com (Jan Wieck) #





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pqReadData() error
@ 1999-12-06 07:44 Imtiaz. S. M <imtiaz_sm@yahoo.com>
  1999-12-06 16:01 ` Re: [SQL] pqReadData() error Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Imtiaz. S. M @ 1999-12-06 07:44 UTC (permalink / raw)
  To: pgsql-sql

Check this out.

I have a table with the following structure.

ip_ad    char(20)
type      int2
bytes    int8
dates    datetime

Newest data keeps getting filled every hour into the table and the
oldest one hour data gets deleted.  So you have the network traffic data
for the last one day in this table which consists of 12 one hour summary
blocks. Now to delete the oldest data I use the following SQL queries.

create table tempdates as select distinct dates from daydata;
delete from daydata where dates in (select b.dates from tempdates a,
tempdates b where a.dates-b.dates > '22 hours');

So this deletes data from the table where the data is more than 1 day
old.

This works fine if the no. of rows are very small. But in my case
approximately 500 new rows get inserted and 500 oldest rows get deleted
every one hour. The query takes a long time and then gives me the
following error

"pqReadData() -- backend closed the channel unexpectedly.
                    This probably means the backend terminated
abnormally before or while processing the request.
We have lost the connection to the backend, so further processing is
impossible. Terminating."

But it works efficiently if I give the following queries instead of the
above one. All I do is replace the "in" with "="

create table tempdates as select distinct dates from daydata;
delete from daydata where dates =(select b.dates from tempdates a,
tempdates b where a.dates-b.dates > '22 hours');

But unfortunaltely for me I cannot use the above query because sometimes
multiple rows might be retrurned from the subquery ie when some data is
lost in between.

Also if I substitute the subquery with actual values for dates , the
query works really fast without giving any errors.

I have tried all possible combinations of indexing also. Still I get the
same error.

Is ther any other way to work around it.

I am using Postgres version 6.5.1 on Linux 2.0.36 Kernel ,Redhat 5.2 ,
Pentium PII 350 Mhz
I have 32MB of Ram.

Thanx in advance

regards
Imtiaz




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] pqReadData() error
  1999-12-06 07:44 pqReadData() error Imtiaz. S. M <imtiaz_sm@yahoo.com>
@ 1999-12-06 16:01 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 1999-12-06 16:01 UTC (permalink / raw)
  To: Imtiaz. S. M <imtiaz_sm@yahoo.com>; +Cc: pgsql-sql

"Imtiaz. S. M" <imtiaz_sm@yahoo.com> writes:
> ... to delete the oldest data I use the following SQL queries.

> create table tempdates as select distinct dates from daydata;
> delete from daydata where dates in (select b.dates from tempdates a,
> tempdates b where a.dates-b.dates > '22 hours');

This is certainly the hard, hard way to do it.  Why not

create table tempdates as
    select max(dates) - '22 hours'::interval as cutoff from daydata;
delete from daydata where dates < (select cutoff from tempdates);

As you have it, the subselect must generate O(N^2) rows for an N-row
daydata table (assuming the distribution of dates is fairly even).
If I read you correctly, there are about 12,000 rows in daydata at all
times?  If so the subselect will examine 144,000,000 pairs of a.dates
and b.dates, and probably output about 25,000 rows (500 a rows matching
each b row, and vice versa).

That's a lot of data, and then it has to be scanned over for each row of
the daydata table in order to implement the IN; the rows that you are
keeping will require a comparison against *every single one* of the
subselect output rows to verify that the IN fails.  So about 11,500 *
25,000 row comparisons done by the IN just for the non-deleted rows,
and probably a few million more for the deletable rows.

Lots faster to calculate the cutoff time once and then do one compare
for each row.

You could probably simplify this even more, to

delete from daydata
where dates < (select max(dates) - '22 hours'::interval from daydata);

unless you have some other use for the temp table's contents.

> The query takes a long time and then gives me the
> following error

> "pqReadData() -- backend closed the channel unexpectedly.

Probably all that date arithmetic is overflowing memory with temporary
results ... which won't get reclaimed till end of query, at present.
But even if it didn't run out of memory, doing it this way is very slow.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~1999-12-06 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-11-25 12:23 pqReadData()  error Dipankar Chakrabarti <dipanc@yahoo.com>
1999-11-25 12:37 ` Jan Wieck <wieck@debis.com>
1999-12-06 07:44 pqReadData() error Imtiaz. S. M <imtiaz_sm@yahoo.com>
1999-12-06 16:01 ` Re: [SQL] pqReadData() error Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox