C program Killed

Started by Patrick L. Nolanalmost 24 years ago2 messagesgeneral
Jump to latest
#1Patrick L. Nolan
pln@cosmic.stanford.edu

I'm writing a C program to read from a database table
on Red Hat Linux 7.1, Postgresql version 7.1.
I practiced running it on a small table and everything
was OK. When I switched to a large table, with 100
times as many rows, the program ran for a while and
then said
Killed

To try to get to the root of the problem, I ran it under
gdb. It says,
(gdb) run
Starting program: /home/pln/pg/find_pg
Program terminated with signal SIGKILL, Killed.
The program no longer exists.

I'm puzzled. Here are some possibly relevant bits of
information:

Both of the tables look like this:
Column | Type | Modifiers
-----------+------------------+-----------
event_num | integer | not null
ph_time | double precision |
ph_l | real |
ph_b | real |
ph_incl | real |
ph_energy | real |
sp_index7 | integer |

The small table has 142427 rows.
The large one has 14958509 rows.

Here's a fragment of the program:
res = PQexec(conn,
"SELECT event_num,ph_time,ph_l,ph_b,ph_incl,ph_energy FROM hundred_days");
nrows = PQntuples(res);
printf ("Fetching %d rows from the database.\n", nrows);
for (i = 0; i<nrows; i++) {

When it dies, it does so before getting to the printf.

--
* Patrick L. Nolan *
* W. W. Hansen Experimental Physics Laboratory (HEPL) *
* Stanford University *

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Patrick L. Nolan (#1)
Re: C program Killed

"Patrick L. Nolan" <pln@cosmic.stanford.edu> writes:

I practiced running it on a small table and everything
was OK. When I switched to a large table, with 100
times as many rows, the program ran for a while and
then said
Killed

My guess is you're running out of memory on the client side.
Consider using a cursor so you can read the data in units
smaller than 14M rows at a time ...

regards, tom lane