Home > Backend Development > Golang > How to Fix 'pq: SSL is not enabled on the server' Errors When Connecting to Postgres with Go?

How to Fix 'pq: SSL is not enabled on the server' Errors When Connecting to Postgres with Go?

Susan Sarandon
Release: 2024-12-09 15:01:12
Original
706 people have browsed it

How to Fix

Troubleshooting SSL Error while Communicating with Postgres Database in Go

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
Copy after login

Causes of the Error

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.

Solution

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)
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template