如何解决通过 R 执行 SQL 查询后清除缓存
我正在通过 dplyr 在大型 Postgres 数据库上执行一个简单的 SELECT COUNT 查询(我正在查询的表有大约 60m 行)。我无法提供 MWE,但这是我在做什么的想法:
# open DB connection
drv <- DBI::dbDriver('PostgreSQL')
con <- RPostgreSQL::dbConnect(...)
# count rows satisfying x = something in table tab
dplyr::tbl(con,"tab") %>%
dplyr::filter(x == something) %>%
dplyr::summarise(n = n()) %>%
print()
# disconnect DB
RPostgreSQL::dbDisconnect(con)
查询工作正常。在查询执行期间缓存内存使用量大幅增加,我认为这是正常的。我的问题是,在查询完成且数据库断开连接后,操作系统缓存内存的使用量不会减少——就像没有垃圾收集或其他东西一样。这是一个问题,因为当连续运行多个查询时,它们开始因我认为缺乏内存而失败。如何确保在查询后清除缓存?
我正在使用以下配置:
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RPostgreSQL_0.6-2 DBI_1.1.0 tmap_2.3-2 sf_0.9-6 forcats_0.5.1
[6] stringr_1.4.0 dplyr_1.0.7 purrr_0.3.4 readr_1.4.0 tidyr_1.1.3
[11] tibble_3.1.3 ggplot2_3.3.3 tidyverse_1.3.1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。