Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 63 by
rmcge...@gmail.com: Could not allocate memory in C
function 'R_AllocStringBuffer' Error
http://code.google.com/p/rpostgresql/issues/detail?id=63
Hello,
I am trying to save R objects into a PostgreSQL table by using
rawToChar(serialize(obj,NULL,TRUE)) to save ascii representations of the
object, and charToRaw(unserialize(obj)) to convert the ascii back into an R
object. Unfortunately, for sufficiently large objects, I am getting the
error "Could not allocate memory (2246 Mb) in C
function 'R_AllocStringBuffer'". This error seems incorrect to me as I am
running a 64-bit version of R and PostgreSQL on a server with 256GB of
(mostly free) RAM. There should not be any difficulty allocating memory.
Moreover, I only encounter the error if I call dbWriteTable from within
another function. Calling it directly inside a script works fine. This
leads me to believe there is perhaps a subtle bug here. I am running
RPostgreSQL 0.4 on R 3.0.3 / Linux x86_64. Please let me know if there is a
problem on my end or a better way for me to do this.
Here is a simple script to reproduce the error:
## This function creates a large object, serializes it, and saves it to the
## table '_test' with an associated unique 'id' column.
saveTest <- function(id) {
## Make a large object
obj <- list(1:3e7, sample(LETTERS, 3e7, replace=TRUE), a~b)
txt <- rawToChar(serialize(obj, NULL, TRUE))
x <- data.frame(id=id, txt=txt)
con <- dbConnect(dbDriver("PostgreSQL"), host=Sys.getenv("PGHOST"),
user=Sys.getenv("PGUSER"),
password=Sys.getenv("PGPWD"),
dbname="template1")
dbSendQuery(con, "SET CLIENT_ENCODING TO 'UTF8';")
dbWriteTable(con, "_test", x, append=TRUE, row.names=FALSE)
dbDisconnect(con)
}
## Create the _test table
> con <- dbConnect(dbDriver("PostgreSQL"), host=Sys.getenv("PGHOST"),
user=Sys.getenv("PGUSER"),
password=Sys.getenv("PGPWD"),
dbname="template1")
> dbSendQuery(con, "CREATE TABLE _test (id INTEGER PRIMARY KEY, txt TEXT);")
> dbDisconnect(con)
> saveTest(1) # Wait ~30 seconds
Error in postgresqlCopyInDataframe(new.con, value) (from
20140509.production.R@32#10) :
could not allocate memory (2246 Mb) in C function 'R_AllocStringBuffer'
> R.version
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 0.3
year 2014
month 03
day 06
svn rev 65126
language R
version.string R version 3.0.3 (2014-03-06)
nickname Warm Puppy
Thanks,
Robert McGehee
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings