-
Notifications
You must be signed in to change notification settings - Fork 0
PostgresSQL Setup Guide
This Golang template is using PostgreSQL for the database. Postgres is a very powerful, easy-to-work-with, and open-source object-relational database system. You do not need to be an expert in SQL to use it. Here are some simple steps to install and get the database running on your local machine.
If you are working on a Macbook or Windows, it is pretty straightforward to install.
For Mac users, run the following command using homebrew:
brew install postgresql@16 # 16 being the current latest version, change the version as needed
Then, you follow the installation process and you are good to go.
On Windows, you will need to download the installer available here Windows Installer. Follow the instructions and you will also be ready.
To make management easier, I recommend downloading pgAdmin as well. It is a graphical tool for managing and developing your database. Very useful if SQL languages aren’t your strength. Again, if you are on Mac, easy to install. Open your terminal and use homebrew:
brew install --cask pgadmin4
Follow the instructions, and you will have the graphical interface ready to use. On Windows, the PostgreSQL installer comes with pgAdmin, so no actions are needed.
From there, you will just need to create your database. You should have a tab named server, just create a new database under the server (or use the default one) you are then ready to connect the database to your app.
For Linux users, the installation is a little more complex and also depends on the distro you are using. So, to avoid writing too many directions, I will just post the link here to the Postgres website where they instruct you to type into your terminal. You can find and pick your distro from this link Linux downloads.
The setup of PostgreSQL should be the same as mentioned for Mac and Windows.
You will now need to gather the required information to add to your .env file to connect your database to your app. You will need your database hostname which should be localhost, your database port, which is often by default 5432, your database username, your database password and your database name (the one you gave during the creation of the database if using the default one, it should be postgres. Here is a summary of the information you will need to gather:
- Database Host Name
- Database Port Number
- Database Username
- Database Password
- Database Name
Here is a screenshot of how pgAdmin should look like with your database. As you can see, postgres is the default created database name.