Skip to main content
PostgreSQL
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. 1. Download: Go to the official PostgreSQL download page (postgresql.org/download) and select the Windows installer provided by EDB.
  1. 2. Install: Run the .exe file.
  1. 3. Components: Ensure both "PostgreSQL Server" and "pgAdmin 4" are checked.
  1. 4. Password: You will be prompted to create a password for the postgres superuser. Do not forget this password. You will need it every time you connect.
  1. 5. Port: Leave the default port as 5432.
  1. 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. 1. Go to postgresapp.com and download the installer.
  1. 2. Move it to your Applications folder and open it.
  1. 3. Click "Initialize" to create a new database cluster.
  1. 4. Download pgAdmin separately from pgadmin.org.

Method 2: Homebrew (Terminal)

bash
12
brew install postgresql
brew services start postgresql

5. Linux Setup (Ubuntu/Debian)

Linux relies heavily on the terminal. You will use the apt package manager.
bash
12345678
# Update your package list
sudo apt update

# Install PostgreSQL and the contrib package (additional features)
sudo apt install postgresql postgresql-contrib

# Start the PostgreSQL service
sudo systemctl start postgresql

*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 a blog_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. 1. Open the pgAdmin 4 application.
  1. 2. It will prompt you for a Master Password (this secures the pgAdmin app itself).
  1. 3. In the left sidebar, expand Servers.
  1. 4. You should see "PostgreSQL [Version]". Click it.
  1. 5. It will prompt you for the password you created during the installation (the postgres superuser password).
  1. 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 called psql. Open your terminal (or SQL Shell on Windows) and type: psql -U postgres Once inside, type: SELECT version();

Using pgAdmin:

  1. 1. Right-click on the postgres database in the left sidebar.
  1. 2. Select Query Tool.
  1. 3. In the code editor that opens, type:

sql
1
SELECT current_date;
  1. 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 postgres superuser. 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 psql command line for running massive backup scripts or automating tasks. Get comfortable with both!

11. Exercises

  1. 1. Locate the "Query Tool" in pgAdmin and execute SELECT 2 + 2; to verify the database can process math.
  1. 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
1
SHOW ALL;

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 psql and pgAdmin. Which one would you use to automate a nightly server backup via a bash script?

15. FAQs

Q: Do I have to use pgAdmin? A: No! pgAdmin is just a client. You can use other popular GUI tools like DBeaver, DataGrip, or TablePlus to connect to your PostgreSQL server.

16. Summary

You have successfully laid the foundation. Your local PostgreSQL server is running quietly in the background on port 5432, and you have pgAdmin configured to visually interface with it. You are officially ready to start building.

17. Next Chapter Recommendation

Before we start writing code to create tables, we must understand the mathematical rules that govern them. In Chapter 3: Understanding Relational Databases, we will explore rows, columns, relationships, and the vital concept of Database Normalization.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·