英文:
Go postgres connection SSL not enabled
问题
我正在尝试在没有 SSL 的情况下连接到我的本地 PostgreSQL 服务器,但是我遇到了这个错误:
pq: 服务器上未启用 SSL
没关系,我知道如何修复它:
type App struct {
Router *mux.Router
DB *sql.DB
}
func (a *App) Initialize(dbname string) {
connectionString := fmt.Sprintf("dbname=%s sslmode=disable", dbname)
var err error
a.DB, err = sql.Open("postgres", connectionString)
if err != nil {
log.Fatal(err)
}
defer a.DB.Close()
}
然而,我仍然遇到了这个错误!
英文:
I'm trying to connect to my localhost postgresql server without SSL and I'm getting this error:
pq: SSL is not enabled on the server
That's fine, I know how to fix it:
type App struct {
Router *mux.Router
DB *sql.DB
}
func (a *App) Initialize(dbname string) {
connectionString := fmt.Sprintf("dbname=%s sslmode=disable", dbname)
var err error
a.DB, err = sql.Open("postgres", connectionString)
if err != nil {
log.Fatal(err)
}
defer a.DB.Close()
}
However I'm still getting the error!
答案1
得分: 4
我能够通过重新安装Postgres来重现你的错误。虽然错误输出是
pq: SSL is not enabled on the server
但真正的错误是没有创建任何数据库。要创建一个名为testdb的测试数据库,请在终端中运行
createdb testdb
在后台已经运行了Postgres。
英文:
I was able to recreate your error with a fresh install of postgres. While the error output was
pq: SSL is not enabled on the server
the real error was not having any databases created. To create a testdb let's run
createdb testdb
in your terminal with postgres already running in the background.
答案2
得分: 1
我认为答案更多地是将一个参数标志分配给你的Postgres连接字符串URL。
我之前是通过URL连接到AWS RDS,现在我只是将其更改为默认端口5432
上的本地主机。
http://127.0.0.1:5432?sslmode=disable
或者
http://localhost:5432?sslmode=disable
英文:
I think the answer comes more just to assign a parameter flag to your Postgres connection string url.
I was connecting to an AWS RDS by URL and I've just change to localhost on 5432
default port.
http://127.0.0.1:5432?sslmode=disable
or
http://localhost:5432?sslmode=disable
答案3
得分: -1
我在尝试使用错误的密码从我的Go程序连接到PostgreSQL服务器时遇到了问题。
英文:
I stumbled upon this trying to connect to Postgresql server from my Go program with wrong password.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论