Cookies management by TermsFeed Cookie Consent

Install PostgreSQL

Please consider supporting us by disabling your ad blocker


After defining the basic assumptions about the project, it is time to install PostgreSQL.

The most convenient and fastest way is to run the PostgreSQL instance as a Docker container. If you are not familiar with Docker, check out the documentation here and how to get Docker here.

If you want to install PostgreSQL directly on your machine, check out the instructions on the official PostgreSQL site.

The command on the right starts the PostgreSQL database instance inside a Docker container.

The command to run PostgreSQL instance in Docker container with the required POSTGRES_PASSWORD environment variable, which is the superuser password, and with the POSTGRES_DB environment variable, which is the name of the default database created when the image starts. In our project, the database name is website.

docker run --rm --name postgresql-intro-gosamples -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=website postgres

The command also maps port 5432 of our container to port 5432 on our host according to the pattern:

-p <host_port>:<container_port>

This step is necessary to connect from our machine to the PostgreSQL located inside the container.

The --rm ensures that the container will be automatically cleaned up and the file system removed when the container exits. This is a convenient option because we will be restarting the container frequently.

If PostgreSQL was started correctly, you should see a similar log message at the end of the standard output:

database system is ready to accept connections