Install PostgreSQL database management system

Tram Ho

In this article, I will show you how to install PostgreSQL on Windows, MacOS and Docker

1. Install PostgreSQL on Docker

To install PostgreSQL on Docker is very simple, follow the steps below:

  • In the terminal, go to drag its image:

By default, I will use the latest version. You can see its versions here https://hub.docker.com/_/postgres .

  • To use a specific version, you can add the following statement on the version you want to use:

  • Then you can check whether the image has been pulled or not as follows:

  • The last step is to run the following command and you already have a PostgreSQL to use:

Let me explain the following command a bit:

  • –name in this parameter will pass up the name of the container you want to set, here I set it as postgres-db .
  • -e POSTGRES_USER this is the parameter passed to name the user using PostgreSQL, if not, the default is postgres , guys, here, I’m passing it on as huytx .
  • -e POSTGRES_PASSWORD this is the parameter passed to set the password for the user just created above, this is a mandatory variable so there is no default value, the value I left in the above command is huy123 .
  • -p 5432:5432 this is the port setting parameter that will be mapped between the docker container and the host machine, I leave it here as port 5432.
  • -v this is the parameter that will help the container mount the data folder outside the host machine, ensuring that the data will not be lost when the container is suddenly lost.
  • -d add this parameter the container will run in detached mode ie running in the background.
  • postgres this parameter indicates the image we just pulled above.

Using docker-compose:

First you create the file docker-compose.yml then copy the content below into the file and run the command:

That’s it, you guys have something to play with, check the results you just set up above:

image.png

2. Install PostgreSQL on MacOS and Windows

To install PostgreSQL on MacOS or Windows, go to this page and download it according to your operating system https://www.postgresql.org/download/ image.png

At the last step, it will ask if you want to install any more tools, check it if there is no need and complete it. image.png

After the installation is complete, PostgreSQL will come with PgAdmin, please open it and enjoy image.png

Thank you for reading this far, if you find it useful, give me an upvote to be motivated to make more posts.

Share the news now

Source : Viblo