I'm building an app in Go and am using Google App Engine for deployment.
I have set up a PostgreSQL instance on Google Cloud, have enabled the API and have successfully connected to it using the SQL proxy from my local machine, both from a local PSequel client and from my app.
When I do gcloud app deploy, however, I get this error:
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
panic: dial unix /cloudsql/sapling:europe-west1:sapling/.s.PGSQL.5432: connect: no such file or directory
I have tried downgrading the Postgres instance from version 11 Beta to 9.6. Have also tried using this driver https://github.com/broady/gae-postgres, which seemed promising but I couldn't get working for the flex environment.
app.yaml
runtime: go
#Here we select the AppEngine Flex environment which performs a lot of the backend preparation for us including the ability to scale give the demand
env: flex
env_variables:
POSTGRES_CONNECTION: "user=postgres password=thisisntmypwd dbname=postgres host=/cloudsql/sapling:europe-west1:sapling"
manual_scaling:
instances: 1
#Select resource size
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
beta_settings:
cloud_sql_instances: sapling:europe-west1:sapling=tcp:5432
config/db.go
package config
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
"os"
)
var Db *sql.DB
//Set up connection to the database
func init() {
var err error
datastoreName := os.Getenv("POSTGRES_CONNECTION")
Db, err = sql.Open(
"postgres",
datastoreName,
)
if err != nil {
panic(err)
}
err = Db.Ping()
if err != nil {
panic(err)
}
fmt.Println("Connected to database")
}