SSL is not enabled on the server

后端 未结 5 575
走了就别回头了
走了就别回头了 2021-01-30 15:46

Trying to communicate with a postgres database with go, preparing the statement like this:

var stmt *sql.Stmt
var err error

stmt, err = db.Prepare(selectStateme         


        
相关标签:
5条回答
  • 2021-01-30 15:55

    This is how I got it working:

    db, err := sql.Open("postgres", "postgres://{user}:{password}@{hostname}:{port}/{database-name}?sslmode=disable")
    
    0 讨论(0)
  • 2021-01-30 16:02

    If your data source name is a url, you will do it like this:

    db, err := sql.Open("postgres", "postgres://username:password@localhost/db_name?sslmode=disable")
    

    sslmode is just added to the db url like a query parameter.

    0 讨论(0)
  • 2021-01-30 16:03

    You should establish DB connection without SSL encryption, like that:

    db, err := sql.Open("postgres", "user=test password=test dbname=test sslmode=disable") 
    
    0 讨论(0)
  • 2021-01-30 16:12

    To establish a connection without SSL, try

    postgres://username:password@host:5432/database?sslmode=disable
    
    0 讨论(0)
  • 2021-01-30 16:17

    Notice, please:

    This even occurs, if you have indicated a sslmode=disable, but have empty other param. For example dbname=

    For example, connection string:

    user=test password=test dbname=sslmode=disable will also issue this error, because dbname is empty.

    0 讨论(0)
提交回复
热议问题