0
votes

I'm trying to connect to a Google Cloud SQL database (postgresql flavor) using RPostgreSQL. I've used that package to connect to several postgresql db's in the past but can't seem to get the Google Cloud version to connect.

I have the Google Cloud SQL database set up to accept my public ip address.

The connect command seems to be failing on the database name parameter. Does anyone know of a way around this? Or is there another way to connect to a Google Cloud SQL db using R? I even tried the mysql flavor of a Google Cloud SQL db and I have the same issue.

I've tried several 'variations' of the Google Cloud SQL instance/database name and none seem to work. (See below for code and errors.)

library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="app-analytics-243422:us-west1:analytics-postgres",host=ip,port=5432,user=user,password=pwd)

#FATAL:  database "app-analytics-243422:us-west1:analytics-postgres" does not exist

con <- dbConnect(drv, dbname="analytics-postgres",host=ip,port=5432,user=user,password=pwd)

#FATAL:  database "analytics-postgres" does not exist

con <- dbConnect(drv, dbname="",host=ip,port=5432,user=user,password=pwd)
#FATAL:  database "analytics" does not exist
1

1 Answers

1
votes

You are using the Instance's connection string instead of a database name.

An instance is a single server of Postgres. A database is a namespace on that instance. Most instance's contain several databases at once time.

You can see more about managing the databases on your instance here.