从Postgresql将大数据加载到R data.table [英] Load large data to R data.table from Postgresql

查看:64
本文介绍了从Postgresql将大数据加载到R data.table的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据存储在Postgresql服务器中。我想将一个具有1500万行的表加载到 data.frame data.table

I store my data in Postgresql server. I want to load a table which has 15mil rows to data.frame or data.table

我使用 RPostgreSQL 加载数据。

library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, ...)

# Select data from a table
system.time(
df <- dbGetQuery(con, "SELECT * FROM 15mil_rows_table")
)

将数据从DB加载到df花费了 20分钟。我使用的Google云服务器具有 60GB内存和16核心CPU

It took 20 minutes to load data from DB to df. I use google cloud server which have 60GB ram and 16 Core CPU

我该如何减少加载时间?

What should I do to reduce load time?

推荐答案

不确定这是否会减少加载时间,因为这两个过程都非常高效,因此可以肯定会减少加载时间。您可以对定时进行评论。

Not sure if this will reduce load time, for sure it may reduce load time as both processes are quite performance efficient. You can leave a comment about the timming.


  1. 使用bash运行 psql 作为转储到csv的表:

  1. using bash run psql as dump table to csv:

COPY 15mil_rows_table TO '/path/15mil_rows_table.csv' DELIMITER ',' CSV HEADER;




  1. 在R中只是读取它:

library(data.table)
DT <- fread("/path/15mil_rows_table.csv")

这篇关于从Postgresql将大数据加载到R data.table的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆