从本地计算机 R 连接到服务器中的 PostgreSQL 数据库

Connect to a PostgreSQL database in a Server from a local machine R

例如,当您通过 RPostgreSQL 连接到 PostgreSQL 时,我会执行以下操作。

m <- dbDriver("PostgreSQL")
con <- dbConnect(m, host = "localhost", user= "postgres", password="admin", 
dbname = "postgres")

但是如果你想连接到服务器中的 postgreSQL,我不知道该怎么做。我会执行以下操作:

m <- dbDriver("PostgreSQL")
con <- dbConnect(m, host = "10.100.100.10", port = "5432", user= "postgres", 
                 password="admin", dbname = "postgres")

这给了我这个错误:

postgresqlNewConnection(drv, ...) 错误: RS-DBI 驱动程序:(无法在 dbname "postgres"

上连接 postgres@10.100.100.10

您(或任何管理服务器的人)需要允许从另一台计算机通过 tcp/ip 进行访问——默认情况下这是关闭的。例如见