In this document you'll learn how to set up your first PostgreSQL database. You have several options for running PostgreSQL, and we recommend using Docker for the best learning experience.
Docker provides an easy and consistent way to run PostgreSQL across different operating systems.
Install Docker Desktop for your operating system.
Note: If you use an older macOS version, the latest Docker Desktop may not be supported. Download an older version that supports your macOS installation:
- macOS 12 Monterey - Version 4.41.2
- macOS 11 Big Sur - Version 4.24.2
After the installation, open Docker Desktop and confirm that the Docker engine is running (check the bottom left of the window).
[Optional] To learn more about Docker:
- Read: What is Docker? (Official documentation)
- Watch: What is Docker in 5 minutes
Run the following command:
docker run -d --name my-postgres -e POSTGRES_USER=hyfuser -e POSTGRES_PASSWORD=hyfpassword -p 5432:5432 postgres:latestThis command will first download the PostgreSQL docker image from DockerHub and then create and a new PostgreSQL docker container. It may take a couple of minutes.
Once the command has been successfully executed, confirm that your container is running using the following command:
docker ps -aConfirm that the status of the container shows "Up":

You can also confirm the status using the Docker Desktop app:

If you followed the steps correctly, your local PostgreSQL server should be running with the following settings:
- Container name:
my-postgres - Host and port:
localhost:5432 - Username:
hyfuser - Password:
hyfpassword
Connect to your database using the powerful psql command-line tool:
docker exec -it my-postgres psql -U hyfuser -d hyfuserYou should see the psql prompt:
psql (17.6 (Debian 17.6-1.pgdg13+1))
Type "help" for help.
postgres=#
Next, type the command \list or \l to show all databases:
You'll see a few system databases that are managed by the PostgreSQL server - you can ignore these.
Let's create your first database by executing the following command:
CREATE DATABASE userdb;Confirm the database was created using the \list command again. Finally, type exit to leave psql.
Using the command line isn't always the most convenient way to manage your PostgreSQL server. Here are some free GUI tools:
pgAdmin is a free and open-source web-based administration tool for PostgreSQL servers. It provides a comprehensive interface for database management.
Database Client is a free VS Code extension that can connect to many different database providers, including PostgreSQL. It allows you to manage databases directly from your code editor.
DataGrip is a powerful database management IDE developed by JetBrains. It supports many database providers including PostgreSQL. While it's not free, it offers a 30-day trial. Trainees can get it for free through the GitHub Education Program.
Stop your container:
docker stop my-postgresStart your container:
docker start my-postgresConnect to your container's shell:
docker exec -it my-postgres bashCheck container logs:
docker logs my-postgresDelete your container (to start over):
docker rm my-postgres