r - postgresqlNewConnection(drv, ...) RS-DBI 驱动程序错误 : (could not connect postgres@local on dbname

标签 r postgresql

我是 R 的新手,我正在尝试使用 RStudio 连接到 PostgreSQL。

我已经安装了 RPostgreSQL 并尝试了以下代码:

> library("DBI", lib.loc="~/R/win-library/3.2")
> library("RPostgreSQL", lib.loc="~/R/win-library/3.2")
> con <- dbConnect(dbDriver("PostgreSQL"), dbname="Delta", user="postgres")
Error in postgresqlNewConnection(drv, ...) : 
  RS-DBI driver: (could not connect postgres@local on dbname "Delta"

由于某种原因,我无法连接到数据库。我试图解决这个问题很长时间了,但不知道如何解决。

最佳答案

我对这个问题的解决方案是使用RPostgres https://github.com/rstats-db/RPostgres .

假设你有一个连接 url,下面的代码将起作用:

library(DBI)
library(RPostgres)

con <- dbConnect(RPostgres::Postgres(),
  host = url$host,
  port = url$port,
  dbname = url$dbname,
  user = url$user,
  password = url$password
)

关于r - postgresqlNewConnection(drv, ...) RS-DBI 驱动程序错误 : (could not connect postgres@local on dbname,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36026436/

相关文章:

sql - 在 Postgres 中删除特定行号的行

postgresql - 搜索表中任何记录的 X 距离内的所有记录

sql - Postgresql 递归返回意外结果

regex - 在R中的字符串中的两个字母之间添加空格

r - 如何找到序列中缺失的数字?

R - 将某些行中某些列的值传输到倾向得分匹配中的匹配 ID

sql - 如何使用sql查询获取输出列

sql - Django 查询 Postgres 返回错误列

r - 如何更改排列Grob 上的标题(顶部)大小?

r - R 中的全局变量和局部变量