When attempting to establish a connection with a Postgres database using Go, it's possible to encounter the following error:
db.Prepare error: pq: SSL is not enabled on the server
This error occurs when the Postgres server is configured to use SSL encryption, but the Go application is not set up to connect using SSL.
To resolve this issue, modify the connection string to disable SSL encryption:
connString := "user=test password=test dbname=test sslmode=disable" db, err := sql.Open("postgres", connString)
By including sslmode=disable in the connection string, the Go application is instructed not to use SSL encryption when connecting to the database. This allows the connection to be established successfully even though SSL is not enabled on the server.
The above is the detailed content of How to Fix 'pq: SSL is not enabled on the server' Errors When Connecting to Postgres with Go?. For more information, please follow other related articles on the PHP Chinese website!