Golang Postgres

4 min readOct 9, 2020

In this article, We will show you how to connect to the Postgres Database using Golang.

We are using the following framework and libraries for this article

  1. Echo Framework (Highly Scalable API development framework)
  2. GORM (GoLang Object Relation Mapping/Database Connectivity)

Video Tutorial

Golang Configuration

In our case, we have configured the Golang path in the .bash_profile file using MacOS as following

export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

In the go directory, we have a folder called github.com

Inside the github.com directory, we have our GitHub user directory called oxlb as showing the following screenshot

We will create a new GoLang project under the oxlb directory

Create a Golang Project

Go to your go configuration directory and create a new directory called


Open the terminal and change directory to GoLangPostgresHelloWorld

$ cd GoLangPostgresHelloWorld

Then create a go.mod file using the following file

$ go mod init github.com/oxlb/GoLangPostgresHelloWorld

this will create the go.mod file as shown below

The above file contains the module and version of the GoLang