【发布时间】:2020-02-04 00:02:51
【问题描述】:
我需要将一个数据库的 3 个分片放在三个不同的服务器上。所以我在 pgAdmin(s1,s2,s3) 中创建了 3 个服务器,然后我将每个服务器放置一个分片。然后,我尝试连接 R 中的一台服务器;但是,我无法建立联系。我总是得到一个错误:
postgresqlNewConnection(drv, ...) 中的错误:RS-DBI 驱动程序:(无法连接数据库名称“postgres”上的 postgres@172.17.0.1:5432:无法连接到服务器:操作超时服务器是否正在运行主机 "172.17.0.1" 并接受端口 5432 上的 TCP/IP 连接?
我的代码是:
#install.packages("RPostgreSQL")
require("RPostgreSQL")
library(DBI)
# create a connection
# save the password that we can "hide" it as best as we can by collapsing it
pw <- {
"postgres"
}
# loads the PostgreSQL driver
drv <- dbDriver("PostgreSQL")
# creates a connection to the postgres database
con <- dbConnect(
drv,
dbname = "postgres",
host = "172.17.0.1",
port = 5432,
user = "postgres",
password = pw
)
rm(pw) # removes the password
我写错了吗?
【问题讨论】:
-
我不确定这是否会有所不同,但我通常将我的论点放在单引号中并尝试将 postgres 的端口更改为 5439。另外,我不确定你为什么放您在 {} 中的密码。这可能会改变一些事情。您可以尝试将其放入您的 .Renviron
标签: r postgresql pgadmin