duan_88598 2017-08-08 14:49
浏览 926
已采纳

Go postgres连接SSL未启用

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条回答 默认 最新

  • dongshou1991 2017-11-23 19:14
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办