转到Postgres的连接SSL
问题描述:
我试图连接到我的本地PostgreSQL服务器没有SSL,我得到这个错误:转到Postgres的连接SSL
pq: SSL is not enabled on the server
这很好,我知道如何解决它:
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()
}
但是我仍然收到错误!
答
我能够重新安装postgres来重新创建错误。虽然错误输出是
pq: SSL is not enabled on the server
是没有创建的任何数据库,真正的错误。要创建一个testdb的让我们运行
createdb testdb
在Postgres已经在后台运行。
还有其他的语法来连接到使用golang的postgres数据库,你有没有尝试过其他方式? – zenwraight
@zenwraight是的,我结束了与URL字符串版本去获取最初的东西的工作,但我需要能够更改数据库名称,以测试'a.DB,err = sql.Open(“ postgres“,”postgresql:// localhost:5432/bookstore?sslmode = disable“)' – Godzilla74
雅我只是建议这一个,因为我也遇到了同样的错误,然后结束了使用这个上面的字符串只有 – zenwraight