我正在用 Go 構(gòu)建一個(gè)應(yīng)用程序,并使用 Google App Engine 進(jìn)行部署。我已經(jīng)在 Google Cloud 上設(shè)置了一個(gè) PostgreSQL 實(shí)例,啟用了 API,并使用本地計(jì)算機(jī)上的 SQL 代理(從本地 PSequel 客戶端和我的應(yīng)用程序)成功連接到它。gcloud app deploy但是,當(dāng)我這樣做時(shí),我收到此錯(cuò)誤: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我嘗試將 Postgres 實(shí)例從版本 11 Beta 降級(jí)到 9.6。還嘗試過使用這個(gè)驅(qū)動(dòng)程序https://github.com/broady/gae-postgres,這看起來很有希望,但我無法在 Flex 環(huán)境中工作。應(yīng)用程序.yamlruntime: 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 demandenv: flexenv_variables: POSTGRES_CONNECTION: "user=postgres password=thisisntmypwd dbname=postgres host=/cloudsql/sapling:europe-west1:sapling"manual_scaling: instances: 1#Select resource sizeresources: cpu: 1 memory_gb: 0.5 disk_size_gb: 10beta_settings: cloud_sql_instances: sapling:europe-west1:sapling=tcp:5432配置/db.gopackage configimport ( "database/sql" "fmt" _ "github.com/lib/pq" "os")var Db *sql.DB//Set up connection to the databasefunc 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")}
1 回答

婷婷同學(xué)_
TA貢獻(xiàn)1844條經(jīng)驗(yàn) 獲得超8個(gè)贊
我在我的測(cè)試環(huán)境中復(fù)制了這個(gè)問題,發(fā)現(xiàn)您收到的錯(cuò)誤是由于 beta_settings 指定了端口。我在最后嘗試了它=tcp:5432
,它給了我同樣的錯(cuò)誤,然后我在沒有它的情況下嘗試它,它部署沒有任何問題。
- 1 回答
- 0 關(guān)注
- 138 瀏覽
添加回答
舉報(bào)
0/150
提交
取消