Search code examples
rpostgresqliphostrpostgresql

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


When you connect to PostgreSQL thorough RPostgreSQL for example I do the following.

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

But if you want to connect to a postgreSQL in a Server, I'm not sure how to do it. I'd do the following:

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

and this gives me this error:

Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: (could not connect [email protected] on dbname "postgres"


Solution

  • You (or whoever admins the server) needs to allow access from another machine over tcp/ip -- this is turned off by default. See for example