2017-08-08 207 views
2

我試圖連接到我的本地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() 
} 

但是我仍然收到錯誤!

+0

還有其他的語法來連接到使用golang的postgres數據庫,你有沒有嘗試過其他方式? – zenwraight

+0

@zenwraight是的,我結束了與URL字符串版本去獲取最初的東西的工作,但我需要能夠更改數據庫名稱,以測試'a.DB,err = sql.Open(「 postgres「,」postgresql:// localhost:5432/bookstore?sslmode = disable「)' – Godzilla74

+0

雅我只是建議這一個,因爲我也遇到了同樣的錯誤,然後結束了使用這個上面的字符串只有 – zenwraight

回答

0

我能夠重新安裝postgres來重新創建錯誤。雖然錯誤輸出是

pq: SSL is not enabled on the server

是沒有創建的任何數據庫,真正的錯誤。要創建一個testdb的讓我們運行

createdb testdb

在終端

在Postgres已經在後臺運行。