I work on an application written in Go which uses a PostgreSQL database. I am deploying that app on Google Cloud Platform, for which I chose the Compute Engine service.
I created 2 instances: an instance for running the application and another for the database server. The OS of both instances is Ubuntu 18.04.
When I test the application locally, everything works as expected. Specifically, there are no problems connecting the app with the database.
When I try to run the app on Compute Engine, I get this error:
panic: dial tcp 10.132.0.4:5432: connect: connection refused
goroutine 1 [running]:
main.init.0()
/home/gauthier/gocode/sprint0/main.go:29 +0x113
exit status 2
Here's some information about my VMs:
-VM1(go)
Internal IP: 10.132.0.3
External IP: 35.205.41.152
-VM2(postgreSQL)
Internal IP: 10.132.0.4
External IP: 35.241.174.119
In my app, I connect to the database like this
var db *sql.DB
func init() {
var err error
db, err =sql.Open("postgres","postgres://postgres:postgres@10.132.0.4/quotes?sslmode=disable")
if err != nil {
panic(err)
}
if err = db.Ping(); err != nil {
panic(err)
}
fmt.Println("You connected to your database")
}
I cannot find anything in the GCP documentation which fixes this issue.