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

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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大