The panic: sql: unknown driver “postgres” occurs in Go when you try to use the “postgres” driver in your SQL-related code, but the driver cannot be found. This is likely because the PostgreSQL driver for your programming language has not been installed or imported correctly.
To fix the panic: sql: unknown driver “postgres”, you need to install and import the “pq” package, the PostgreSQL driver for Go.
To install the package, run the following command in your terminal.
go get github.com/lib/pq
Then, in your Go code, ensure to import the package:
import (
"database/sql"
_ "github.com/lib/pq"
)
The underscore (_) is used as an alias to import the package for its side effects only (registering the “postgres” driver).
That’s it.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.