首页 > 解决方案 > RSQLite dbWriteTable 不适用于大数据

问题描述

这是我的代码,我试图将数据从 R 写入 SQLite 数据库文件。

library(DBI)
library(RSQLite)
library(dplyr)
library(data.table)

con <- dbConnect(RSQLite::SQLite(), "data.sqlite")

### Read the file you want to load to the SQLite database

data <- read_rds("data.rds")

dbSafeNames = function(names) {
  names = gsub('[^a-z0-9]+','_',tolower(names))
  names = make.names(names, unique=TRUE, allow_=TRUE)
  names = gsub('.','_',names, fixed=TRUE)
  names
}

colnames(data) = dbSafeNames(colnames(data))

### Load the dataset to the SQLite database

dbWriteTable(conn=con, name="data", value= data, row.names=FALSE, header=TRUE)

在写入 80GB 数据时,我看到 data.sqlite 的大小增加到 45GB,然后它停止并抛出以下错误。

Error in rsqlite_send_query(conn@ptr, statement) : disk I/O error
Error in rsqlite_send_query(conn@ptr, statement) : 
  no such savepoint: dbWriteTable

解决方法是什么,我该怎么办?如果只使用 RSQLite,请推荐最健壮的数据库创建方法,如 RMySQL、RPostgreSQL 等。

标签: rrmysqlrpostgresqlrsqliter-dbi

解决方案


推荐阅读