# Ruby postgresql library: time out error

**URL:** <https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459>\
**Category:** ruby-talk\
**Created:** [17 May 2005 15:17 UTC](https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459 "2005-05-17T15:17:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rgilaard](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@Rgilaard](https://rubytalk.org/u/Rgilaard)\
**Post date:** [17 May 2005 15:17 UTC](https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459/1 "2005-05-17T15:17:34Z")

</div>

Dear all,  
Im using a ruby script to manipulate some database tables in postgresql 7.4.6  
running under freebsd.

The following query

create table as select ident,count(ident) as totnrchange from bookhistory group  
by ident

Takes almost 20 minutes to accomplish if I issue these commands from the psql  
client utility.

However, if I use ruby to do the same as in:

Res=conn.exec(create table as select ident,count(ident) as totnrchange from  
bookhistory group by ident)

I get the follwing error:

Maketestset.rb : 47: IN exec: could not receive data from server: Operation  
timed out (PGError) from maketestset.rb

I also notice when looking at the outcome of top, that the % the cpu is busy  
with the postgers process gradually decreases and after a certain time the cpu  
stops doing anything and I get this error message.

What could cause this? Im suspecting ruby because when I normally do this in  
psql, the query finishes.  
I have to do it like this because this statement is in a for loop and gets  
repeated almost 300 times

Can anyone help with this one?  
Thanks in advance  
Robert

---

<div class="post-metadata">

**Author:** ![Brian\_Schroder1](https://avatars.discourse-cdn.com/v4/letter/b/2bfe46/32.png) [@Brian\_Schroder1](https://rubytalk.org/u/Brian_Schroder1)\
**Post date:** [17 May 2005 15:26 UTC](https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459/2 "2005-05-17T15:26:22Z")

</div>

> Dear all,  
> I'm using a ruby script to manipulate some database tables in postgresql 7.4.6  
> running under freebsd.
> 
> The following query
> 
> create table as select ident,count(ident) as totnrchange from bookhistory group  
> by ident
> 
> Takes almost 20 minutes to accomplish if I issue these commands from the psql  
> client utility.
> 
> However, if I use ruby to do the same as in:
> 
> Res=conn.exec("create table as select ident,count(ident) as totnrchange from  
> bookhistory group by ident")
> 
> I get the follwing error:
> 
> Maketestset.rb : 47: IN 'exec': could not receive data from server: Operation  
> timed out (PGError) from maketestset.rb
> 
> I also notice when looking at the outcome of top, that the % the cpu is busy  
> with the postgers process gradually decreases and after a certain time the cpu  
> stops doing anything and I get this error message.
> 
> What could cause this? I'm suspecting ruby because when I normally do this in  
> psql, the query finishes.  
> I have to do it like this because this statement is in a for loop and gets  
> repeated almost 300 times

Just curious, does that mean that you wait \> 4 Days creating the table  
300 times? Thats a lot of time. Would you care to tell me how many  
rows are in this table?

best regards,

Brian

> **···**
>
> On 17/05/05, rgilaard@few.vu.nl \<rgilaard@few.vu.nl\> wrote:
> 
> > Can anyone help with this one?  
> > Thanks in advance  
> > Robert
> 
> --  
> [http://ruby.brian-schroeder.de/](http://ruby.brian-schroeder.de/)
> 
> Stringed instrument chords: [http://chordlist.brian-schroeder.de/](http://chordlist.brian-schroeder.de/)

---

<div class="post-metadata">

**Author:** ![Pat\_Maddox1](https://avatars.discourse-cdn.com/v4/letter/p/ccd318/32.png) [@Pat\_Maddox1](https://rubytalk.org/u/Pat_Maddox1)\
**Post date:** [17 May 2005 15:52 UTC](https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459/3 "2005-05-17T15:52:59Z")

</div>

That's a postgres problem, not a Ruby problem. You said it takes  
nearly 20 minutes when using the command line client. Don't you think  
that's a little excessive? Actually, let me just inform you right now  
that it's a lot excessive. Ruby times out because it says, "Uh,  
there's no reason it should be taking this long. I quit." And it's  
right, there's no reason it should take that long.

I don't know what the problem is, but it's a problem with your db, not  
Ruby. There's probably a way to change the timeout in Ruby, so it  
would in fact wait that long. I'd look to fix your db first though.

> **···**
>
> On 5/17/05, rgilaard@few.vu.nl \<rgilaard@few.vu.nl\> wrote:
> 
> > Dear all,  
> > I'm using a ruby script to manipulate some database tables in postgresql 7.4.6  
> > running under freebsd.
> > 
> > The following query
> > 
> > create table as select ident,count(ident) as totnrchange from bookhistory group  
> > by ident
> > 
> > Takes almost 20 minutes to accomplish if I issue these commands from the psql  
> > client utility.
> > 
> > However, if I use ruby to do the same as in:
> > 
> > Res=conn.exec("create table as select ident,count(ident) as totnrchange from  
> > bookhistory group by ident")
> > 
> > I get the follwing error:
> > 
> > Maketestset.rb : 47: IN 'exec': could not receive data from server: Operation  
> > timed out (PGError) from maketestset.rb
> > 
> > I also notice when looking at the outcome of top, that the % the cpu is busy  
> > with the postgers process gradually decreases and after a certain time the cpu  
> > stops doing anything and I get this error message.
> > 
> > What could cause this? I'm suspecting ruby because when I normally do this in  
> > psql, the query finishes.  
> > I have to do it like this because this statement is in a for loop and gets  
> > repeated almost 300 times
> > 
> > Can anyone help with this one?  
> > Thanks in advance  
> > Robert

---

<div class="post-metadata">

**Author:** ![Dalibor\_Sramek1](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Dalibor\_Sramek1](https://rubytalk.org/u/Dalibor_Sramek1)\
**Post date:** [17 May 2005 16:28 UTC](https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459/4 "2005-05-17T16:28:36Z")

</div>

I don't know whay Ruby timeouts but I would suggest using a rule or a  
trigger to keep the aggregates updated.

Regards

Dalibor Sramek

> **···**
>
> On Wed, May 18, 2005 at 12:17:34AM +0900, rgilaard@few.vu.nl wrote:
> 
> > create table as select ident,count(ident) as totnrchange from bookhistory group  
> > by ident
> 
> --  
> Dalibor Sramek [insula.cz](http://www.insula.cz/dali) \ In the eyes of cats  
> / dalibor.sramek@insula.cz \ all things  
> / \>H blog [http://www.transhumanismus.cz/blog.php](http://www.transhumanismus.cz/blog.php) \ belong to cats.

---

<div class="post-metadata">

**Author:** ![Rgilaard](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@Rgilaard](https://rubytalk.org/u/Rgilaard)\
**Post date:** [17 May 2005 15:37 UTC](https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459/5 "2005-05-17T15:37:35Z")

</div>

No:-)  
In production I will have it accumulate by putting another expression in the  
query.

There are a few million records in this table.  
I've also created an index on the where clause I was talking about in the  
beginning but that didn't help.

The query just times out, only in Ruby.

Thanks,

Quoting Brian Schröder \<ruby.brian@gmail.com\>:

> **···**
>
> > On 17/05/05, rgilaard@few.vu.nl \<rgilaard@few.vu.nl\> wrote:  
> > \> Dear all,  
> > \> I'm using a ruby script to manipulate some database tables in postgresql  
> > 7.4.6  
> > \> running under freebsd.  
> > \>  
> > \> The following query  
> > \>  
> > \> create table as select ident,count(ident) as totnrchange from bookhistory  
> > group  
> > \> by ident  
> > \>  
> > \> Takes almost 20 minutes to accomplish if I issue these commands from the  
> > psql  
> > \> client utility.  
> > \>  
> > \> However, if I use ruby to do the same as in:  
> > \>  
> > \> Res=conn.exec("create table as select ident,count(ident) as totnrchange  
> > from  
> > \> bookhistory group by ident")  
> > \>  
> > \> I get the follwing error:  
> > \>  
> > \> Maketestset.rb : 47: IN 'exec': could not receive data from server:  
> > Operation  
> > \> timed out (PGError) from maketestset.rb  
> > \>  
> > \> I also notice when looking at the outcome of top, that the % the cpu is  
> > busy  
> > \> with the postgers process gradually decreases and after a certain time the  
> > cpu  
> > \> stops doing anything and I get this error message.  
> > \>  
> > \> What could cause this? I'm suspecting ruby because when I normally do this  
> > in  
> > \> psql, the query finishes.  
> > \> I have to do it like this because this statement is in a for loop and gets  
> > \> repeated almost 300 times
> > 
> > Just curious, does that mean that you wait \> 4 Days creating the table  
> > 300 times? Thats a lot of time. Would you care to tell me how many  
> > rows are in this table?
> > 
> > best regards,
> > 
> > Brian
> > 
> > \>  
> > \> Can anyone help with this one?  
> > \> Thanks in advance  
> > \> Robert  
> > \>  
> > \>
> > 
> > --  
> > [http://ruby.brian-schroeder.de/](http://ruby.brian-schroeder.de/)
> > 
> > Stringed instrument chords: [http://chordlist.brian-schroeder.de/](http://chordlist.brian-schroeder.de/)

---

<div class="post-metadata">

**Author:** ![Florian\_G\_Pflug](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@Florian\_G\_Pflug](https://rubytalk.org/u/Florian_G_Pflug)\
**Post date:** [17 May 2005 20:41 UTC](https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459/6 "2005-05-17T20:41:27Z")

</div>

Pat Maddox wrote:

> That's a postgres problem, not a Ruby problem. You said it takes  
> nearly 20 minutes when using the command line client. Don't you think  
> that's a little excessive? Actually, let me just inform you right now  
> that it's a lot excessive. Ruby times out because it says, "Uh,  
> there's no reason it should be taking this long. I quit." And it's  
> right, there's no reason it should take that long.

Actually, if you copy a few million rows, there is reason enough

> I don't know what the problem is, but it's a problem with your db, not  
> Ruby. There's probably a way to change the timeout in Ruby, so it  
> would in fact wait that long. I'd look to fix your db first though.

I'd say that its quite reasonable for \_some\_ statements to take  
a long time - I'm running imports in a postgres database that  
take a few hours, and don't time out. I'd probably not  
want to call this from a webrequest, but it can still make sense ;-))

Which postgres module are you using? I'm using the (quite old)  
binding for the pg-c-libs - There is a pure-ruby-implementation  
too, which might inherit some ruby-specific socket-timeouts.

greetings, Florian Pflug

---

<div class="post-metadata">

**Author:** ![Rgilaard](https://avatars.discourse-cdn.com/v4/letter/r/ac91a4/32.png) [@Rgilaard](https://rubytalk.org/u/Rgilaard)\
**Post date:** [18 May 2005 10:32 UTC](https://rubytalk.org/t/ruby-postgresql-library-time-out-error/18459/7 "2005-05-18T10:32:40Z")

</div>

This is definately not a web application.

I'm using the extension library ruby-postgres version 0.7.1.  
It did mention that it worked with Posgresql from 6.5 up to 7.2 while I'm  
running Postgresql 7.4.2

How can I manipulate the time out settings in this ruby library?

Brgds  
Robert

Quoting "Florian G. Pflug" \<fgp@phlo.org\>:

> **···**
>
> > Pat Maddox wrote:  
> > \> That's a postgres problem, not a Ruby problem. You said it takes  
> > \> nearly 20 minutes when using the command line client. Don't you think  
> > \> that's a little excessive? Actually, let me just inform you right now  
> > \> that it's a lot excessive. Ruby times out because it says, "Uh,  
> > \> there's no reason it should be taking this long. I quit." And it's  
> > \> right, there's no reason it should take that long.  
> > Actually, if you copy a few million rows, there is reason enough
> > 
> > \> I don't know what the problem is, but it's a problem with your db, not  
> > \> Ruby. There's probably a way to change the timeout in Ruby, so it  
> > \> would in fact wait that long. I'd look to fix your db first though.  
> > I'd say that its quite reasonable for \_some\_ statements to take  
> > a long time - I'm running imports in a postgres database that  
> > take a few hours, and don't time out. I'd probably not  
> > want to call this from a webrequest, but it can still make sense ;-))
> > 
> > Which postgres module are you using? I'm using the (quite old)  
> > binding for the pg-c-libs - There is a pure-ruby-implementation  
> > too, which might inherit some ruby-specific socket-timeouts.
> > 
> > greetings, Florian Pflug
