I needed to put 3 shards of a database on three different servers. So I created 3 servers in pgAdmin(s1,s2,s3), then I put each server one shard. Then, I tried to connect one of the servers in R; however, I couldn't make the connection. I always get an error:
Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: (could not connect postgres@172.17.0.1:5432 on dbname "postgres": could not connect to server: Operation timed out Is the server running on host "172.17.0.1" and accepting TCP/IP connections on port 5432?
My code is:
#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
Did I write something wrong?