CHAPTER 02
Intermediate
Installing PostgreSQL and pgAdmin
Updated: May 16, 2026
5 min read
# CHAPTER 2
Installing PostgreSQL and pgAdmin
1. Introduction
To start building databases, you need two pieces of software. First, you need the PostgreSQL Server—the invisible background engine that stores the data. Second, you need pgAdmin—the graphical dashboard (GUI) that allows you to click, view, and manage your databases easily, rather than staring at a black terminal screen. In this chapter, we will install both and configure our local development environment.2. Learning Objectives
By the end of this chapter, you will be able to:- Download and install the PostgreSQL Server.
- Understand what a Database Cluster is.
- Install and configure pgAdmin.
- Connect pgAdmin to your local PostgreSQL server.
- Open the SQL Query Tool to execute your first command.
3. Windows Setup
EnterpriseDB (EDB) provides a unified installer that bundles both the database engine and pgAdmin together.-
1.
Download: Go to the official PostgreSQL download page (
postgresql.org/download) and select the Windows installer provided by EDB.
-
2.
Install: Run the
.exefile.
- 3. Components: Ensure both "PostgreSQL Server" and "pgAdmin 4" are checked.
-
4.
Password: You will be prompted to create a password for the
postgressuperuser. Do not forget this password. You will need it every time you connect.
-
5.
Port: Leave the default port as
5432.
- 6. Finish: Complete the installation.
4. macOS Setup
The easiest way to install PostgreSQL on macOS is using the Postgres.app or Homebrew.Method 1: Postgres.app (Easiest)
-
1.
Go to
postgresapp.comand download the installer.
- 2. Move it to your Applications folder and open it.
- 3. Click "Initialize" to create a new database cluster.
-
4.
Download pgAdmin separately from
pgadmin.org.
Method 2: Homebrew (Terminal)
bash
5. Linux Setup (Ubuntu/Debian)
Linux relies heavily on the terminal. You will use theapt package manager.
bash
*Note: On Linux, you must install pgAdmin separately, or use a web-based client.*
6. What is a Database Cluster?
When you install PostgreSQL, it creates a "Database Cluster." A cluster is NOT a group of physical servers. In PostgreSQL terminology, a cluster is simply a collection of databases managed by a single instance of a running PostgreSQL server. Inside your one local cluster, you can create ablog_db, a store_db, and a school_db.
7. Connecting to pgAdmin
Now that the server is running, let's look at it visually.- 1. Open the pgAdmin 4 application.
- 2. It will prompt you for a Master Password (this secures the pgAdmin app itself).
- 3. In the left sidebar, expand Servers.
- 4. You should see "PostgreSQL [Version]". Click it.
-
5.
It will prompt you for the password you created during the installation (the
postgressuperuser password).
-
6.
Once connected, expand Databases. You will see a default database named
postgres.
8. Running Your First Command (CLI vs pgAdmin)
Using the CLI (psql): PostgreSQL comes with a command-line tool calledpsql.
Open your terminal (or SQL Shell on Windows) and type: psql -U postgres
Once inside, type: SELECT version();
Using pgAdmin:
-
1.
Right-click on the
postgresdatabase in the left sidebar.
- 2. Select Query Tool.
- 3. In the code editor that opens, type:
sql
- 4. Click the "Play" button (Execute). It will return today's date!
9. Common Mistakes
-
Forgetting the Superuser Password: There is no simple "Forgot Password" button for the local
postgressuperuser. If you forget it, you will have to dive into deep configuration files (pg_hba.conf) to bypass authentication and reset it, which is very difficult for beginners.
-
Port Conflicts: PostgreSQL runs on port
5432. If another application on your computer is already using that port, the server will fail to start.
10. Best Practices
-
Use pgAdmin for Management, CLI for Automation: While pgAdmin is fantastic for viewing data and managing users, professional DBAs still use the
psqlcommand line for running massive backup scripts or automating tasks. Get comfortable with both!
11. Exercises
-
1.
Locate the "Query Tool" in pgAdmin and execute
SELECT 2 + 2;to verify the database can process math.
- 2. What is the default port number that PostgreSQL uses to communicate?
12. SQL Challenges
Using the Query Tool, execute the following command to see a list of all your current database configurations:
sql
13. MCQ Quiz with Answers
Question 1
In PostgreSQL terminology, what is a "Database Cluster"?
Question 2
Which tool is primarily used as the Graphical User Interface (GUI) to interact with PostgreSQL visually?
14. Interview Questions
- Q: If a new developer cannot connect their application to the local PostgreSQL server, what port should they verify is open and listening?
-
Q: Explain the difference between
psqlandpgAdmin. Which one would you use to automate a nightly server backup via a bash script?