[R] crash on multiple queries to postgresql db
Dylan Beaudette
debeaudette at ucdavis.edu
Tue Jan 13 00:07:07 CET 2009
On Friday 09 January 2009, Joe Conway wrote:
> Dylan Beaudette wrote:
> > Subsequent calls to:
> >
> > conn <- dbConnect(PgSQL(), host="localhost", dbname="xxx", user="xxx")
> > query <- dbSendQuery(conn, query_text)
> > res <- dbGetResult(query)
> >
> > are resulting in this:
> >
> > *** glibc detected *** /usr/local/lib/R/bin/exec/R: realloc(): invalid
> >
> > other attached packages:
> > [1] RdbiPgSQL_1.8.0 Rdbi_1.8.0 lattice_0.17-20
> >
> > Any ideas?
>
> Well, first off, since you are apparently using RdbiPgSQL from
> bioconductor, you should probably try asking there.
>
> But in any case, you might try the latest release from bioconductor:
> http://www.bioconductor.org/packages/release/bioc/src/contrib/RdbiPgSQL_1.1
>6.0.tar.gz
>
> or else try the recently released PostgreSQL DBI package on CRAN:
> http://cran.stat.ucla.edu/src/contrib/RPostgreSQL_0.1-3.tar.gz
>
> HTH,
>
> Joe
Thanks Joe. I have updated all of my R packages, along with my Bioconductor
packages... and I still get the odd behavior:
*** glibc detected *** /usr/local/lib/R/bin/exec/R: realloc(): invalid old
size: 0xb7dad1e0 ***
======= Backtrace: =========
/lib/i686/cmov/libc.so.6[0xb7cc3624]
/lib/i686/cmov/libc.so.6[0xb7cc71a1]
/lib/i686/cmov/libc.so.6(realloc+0x106)[0xb7cc7b46]
/usr/local/pgsql/lib/libpq.so.5[0xb7802166]
/usr/local/pgsql/lib/libpq.so.5[0xb780239c]
/usr/local/pgsql/lib/libpq.so.5[0xb77fbd31]
/usr/local/pgsql/lib/libpq.so.5(PQfinish+0x15)[0xb77fbe85]
/usr/local/lib/R/site-library/RdbiPgSQL/libs/RdbiPgSQL.so(PgSQLcloseConnection+0x38)
[0xb783bb98]
Again, here is my session info:
R version 2.8.0 (2008-10-20)
i686-pc-linux-gnu
locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] RdbiPgSQL_1.16.0 Rdbi_1.16.0 lattice_0.17-20
Here is the code that appears to be causing the problems:
# load data from a PostGreSQL database, and return a dataframe
# this will get called whenever the parent function is called
# crashes after 3-5 subsequent calls
load_sensor_data <- function(query_text)
{
# conn becomes an object which contains the DB connection:
conn <- dbConnect(PgSQL(), host="localhost", dbname="SJER", user="dylan")
## pre-filter out possible bad data:
query <- dbSendQuery(conn, query_text)
# fetch data according to query:
res <- dbGetResult(query)
# convert characters to factors
res <- transform(res, probe_id = factor(probe_id))
res <- transform(res, pedon_id = factor(pedon_id))
# generate a new date-time object in the dataframe
res$date <- as.POSIXct(strptime(res$date_time, format="%a %b %e %H:%M:%S %Y"))
# cleanup
dbDisconnect(conn)
# doesn't completely fix problem crashing
gc()
# return the resulting dataframe
return(res)
}
Thanks in advance,
Dylan
--
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341
More information about the R-help
mailing list