英文:
Connection refused when running go migrate in cloud run
问题
我正在尝试在Cloud Run上使用Golang迁移工具对Cloud SQL进行数据库迁移,但是日志显示如下错误:
无法创建迁移:拨号tcp 127.0.0.1:5432:连接被拒绝
我使用的URI格式是postgres://{user}:{password}@cloudsql/{host}:{port}/{db_name}
,其中主机名是来自Cloud SQL的连接名称project-name:region-name:instance-name
。
我的设置有什么问题吗?或者在Cloud Run设置中我漏掉了什么?还有没有更好的方法在Go项目内部进行数据库迁移?顺便说一下,我是通过GitHub Action将项目部署到Cloud Run并使用Artifact Registry。
英文:
I'm trying to run db migration with golang migrate for Cloud SQL, on cloud run and it shows this log
> cannot create migration: dial tcp 127.0.0.1:5432: connect: connection
> refused
The URI format I'm using is postgres://{user}:{password}@cloudsql/{host}:{port}/{db_name}
The host is from the connection name from Cloud SQL project-name:region-name:instance-name
Is there anything wrong with my setup, or am I missing something on the cloud run setup?
Or there is better way to do the db migration from inside the go project?
Btw, i'm deploying the project to cloud run via github action to artifact registry
答案1
得分: 1
你需要使用Go Connector或使用Cloud Run内置的Cloud SQL集成(在底层运行Cloud SQL Auth Proxy)。默认情况下,Cloud SQL的IP地址被防火墙阻止与互联网的连接,这就是为什么你当前的方法不起作用的原因。
英文:
You'll need to either use the Go Connector or use Cloud Run's built-in Cloud SQL integration (which runs the Cloud SQL Auth Proxy under the hood). By default, Cloud SQL IP addresses are firewalled off from the internet, which is why your current approach isn't working.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论