Tutorial for PostgreSQL and pgAdmin
This document provides important details about using PostgreSQL in this course.
PostgreSQL is a powerful, open-source DBMS supporting a substantial part of the SQL standard.
Many organizations use PostgreSQL in major information systems. This tutorial demonstrates
installation of PostgreSQL on Windows 11 and usage of the pgAdmin client software to execute
SQL statements. This tutorial initially uses the latest stable versions of PostgreSQL (14.4) and
pgAdmin (4) for Windows in July 2022.
1. Installation
You can download various versions of PostgreSQL from the organization’s website
(https://www.postgresql.org/) as shown in Figure 1. Select the Download → button to open the
download page (Figure 2).
Figure 1: Home Page
8/15/2022 Tutorial for PostgreSQL and pgAdmin 2
Figure 2: Download Page
Select the appropriate operating system to start the download process. This tutorial demonstrates
the installation of PostgreSQL for Windows 11 so Windows was selected. The Windows
Installers page (Figure 3) shows the PostgreSQL versions supported on Windows 11.
Figure 3: Download Page for Windows
8/15/2022 Tutorial for PostgreSQL and pgAdmin 3
Click the Download the Installer link to open the EDB page for Windows PostgreSQL
installers (Figure 4), then select the version to download. In this tutorial, select Windows x86-64.
The installer should be begun downloading. Keep the installation file if asked (Figure 5)
Figure 4: EDB Windows Installer Page for PostgreSQL
8/15/2022 Tutorial for PostgreSQL and pgAdmin 4
Figure 5: Download Page
After downloading completes, you can start the installation by double clicking the .exe
file (postgresql-14.4-1-windows-x64.exe in this tutorial). Let the installer take control (respond
yes) to begin installation. Select Next > for the first installation window (Figure 6). In the next
window, choose the installation folder (Figure 7). Follow the remaining installation windows
(Figures 8 to 16) to complete the installation. In the Password window (Figure 9), you must enter
a password for the superuser (postgres). You must remember this password as you will need to
use the password when starting PostgreSQL. After the last installation window (Figure 15), you
can skip the Stack Builder additional installation by clicking the Cancel button (Figure 16). You
can use Stack Builder later if you want to install other components.
8/15/2022 Tutorial for PostgreSQL and pgAdmin 5
Figure 5: First Installation Window for PostgreSQL
8/15/2022 Tutorial for PostgreSQL and pgAdmin 6
Figure 6: Second Installation Window to Select Directory
8/15/2022 Tutorial for PostgreSQL and pgAdmin 7
Figure 7: Third Installation Window to Select Components
8/15/2022 Tutorial for PostgreSQL and pgAdmin 8
Figure 8: Fourth Installation Window to Select Data Directory
8/15/2022 Tutorial for PostgreSQL and pgAdmin 9
Figure 9: Fifth Installation Window to Enter Superuser Password
8/15/2022 Tutorial for PostgreSQL and pgAdmin 10
Figure 10: Sixth Installation Window to Enter Port
Note: The port number will be needed to create connections to PostgreSQL server. You should
remember this for later usages.
8/15/2022 Tutorial for PostgreSQL and pgAdmin 11
Figure 11: Seventh Installation Window to Enter Locale
8/15/2022 Tutorial for PostgreSQL and pgAdmin 12
Figure 12: Eigth Installation Window to View Installation Summary
8/15/2022 Tutorial for PostgreSQL and pgAdmin 13
Figure 13: Ninth Installation Window to Start Installation
8/15/2022 Tutorial for PostgreSQL and pgAdmin 14
Figure 14: Create Folders and Extract Files
8/15/2022 Tutorial for PostgreSQL and pgAdmin 15
Figure 15: Completing the PostgreSQL Setup Wizard. (You can uncheck here)
8/15/2022 Tutorial for PostgreSQL and pgAdmin 16
Figure 16: Stack Builder Installation Window (Cancel)
2. Creating and Connecting to a Database using pgAdmin
After installation, you can use pgAdmin, the PostgreSQL client, to create and connect to
databases. Start pgAdmin by typing pgAdmin in search box and click on pgAdmin in the result
(Figure 17) or browse to pgAdmin in PostgreSQL 14 folder and click on it (Figure 18)
8/15/2022 Tutorial for PostgreSQL and pgAdmin 17
Figure 17: Search and Select pgAdmin from Window Start Search Box
8/15/2022 Tutorial for PostgreSQL and pgAdmin 18
Figure 18: Selecting pgAdmin in the Windows Program List
You can create a short cut to pgAdmin by dragging the pgAdmin icon to the desktop, so
you can quickly open it later. Starting pgAdmin window will appear when you click on
pgAdmin.
8/15/2022 Tutorial for PostgreSQL and pgAdmin 19
Figure 19: pgAdmin Starting Window
After pgAdmin begins, you need to enter the master password that you provided in the
installation process (Figure 20). After entering the password, pgAdmin opens with the Servers
object without expansion (Figure 21). After you expand the Servers object, you need to provide
the master password again (Figure 22). You can check save so that you do not need to enter
password for later access. After the Servers object expands, you can expand the Databases object
and Schemas object inside the Databases object (Figure 23).
8/15/2022 Tutorial for PostgreSQL and pgAdmin 20
Figure 20: Enter Master Password Window
8/15/2022 Tutorial for PostgreSQL and pgAdmin 21
Figure 21: pgAdmin Showing the Servers Object without Expansion
8/15/2022 Tutorial for PostgreSQL and pgAdmin 22
Figure 22: Enter Password for Open Servers
The remainder of this tutorial uses pgAdmin connected to a PostgreSQL 14 database
server, the latest version in July 2022. pgAdmin 4 seems to work identically with PostgreSQL 12
and 13 database servers.
Although you can use the default postgres database to execute SQL statements, I
recommend creating separate databases for each database used in the course. With separate
databases, you will not have conflicts among common table names in the course databases.
Follow these steps to create a new database for the university database tables and then connect to
the new database so that you can enter SQL statements to create and populate tables.
8/15/2022 Tutorial for PostgreSQL and pgAdmin 23
• Right click on the Databases (1) object inside the PostgreSQL 14 object (Figure 24).
Select Create -> Database …
• Enter the database name (UnivDB) and click the Save button (Figure 25). The
window will be closed, and you will see the notification to show the database was
successfully connected. (Figure 26)
• Expand the Databases object to see the StoreSales database (Figure 27).
Figure 23: Expansion of Databases and Schemas Objects
8/15/2022 Tutorial for PostgreSQL and pgAdmin 24
Figure 24: Create New Database
8/15/2022 Tutorial for PostgreSQL and pgAdmin 25
Figure 25: Enter Database Name Window
Figure 26: Connect to New Database
8/15/2022 Tutorial for PostgreSQL and pgAdmin 26
Figure 27: Expanded Databases Object Showing UnivDB Database
3. Executing SQL Statements
pgAdmin provides the Query Tool to enter and execute SQL statements. You open the
Query Tool for each database in which you want to execute SQL statements. Follow these steps
to create and populate the university database tables. For other databases, you can create the
database as described in the previous section and the use the Query Tool to execute SQL
statements.
8/15/2022 Tutorial for PostgreSQL and pgAdmin 27
• Expand the UnivDB object (Figure 28). The click the Query Tool ( ) to open the
Query Window for the UnivDB database. Alternatively, you can right click on the
UnivDB object and select Query Tool.
• The Query Window opens showing a new panel (top right) for the UnivDB database
(Figure 29). Make sure the database name (in red boxes) is correct
• Copy and paste the CREATE statements for the University Database. You can find
these statements in Module 2 Lecture Notes page. Click the Run button ( ) to
execute the statements (Figure 30).
• Use the Clear Query (Figure 31) in Edit menu . Respond Yes to the prompt
about discarding the current changes in the Query Window (Figure 32)
• Copy and paste the INSERT statements for the University Database. You can find
these statements in the Module 3 Lecture Notes. Click the Run button to execute the
statements (Figure 33).
• Expand the Tables object (Figure 34) to see the list of tables created.
• You can count the rows to verify the execution of the INSERT statements. Right click
the Student table and select Count Rows (Figure 35).
8/15/2022 Tutorial for PostgreSQL and pgAdmin 28
Figure 28: Expanded UnivDB Object Showing Query Tool Button
Figure 29: Expanded UnivDB Object with Query Editor Window
8/15/2022 Tutorial for PostgreSQL and pgAdmin 29
Figure 30: Query Editor Window with Executed SQL Statements to Create Tables
Figure 31: Clear Query Window Selection
8/15/2022 Tutorial for PostgreSQL and pgAdmin 30
Figure 32: Selecting Yes to Clear Query Window
Figure 33: Query Editor Window with Executed SQL Statements to Populate Tables
8/15/2022 Tutorial for PostgreSQL and pgAdmin 31
Figure 34: Expansion of Tables Object in the UnivDB Database
8/15/2022 Tutorial for PostgreSQL and pgAdmin 32
Figure 35: Counting Rows Selection for the Student Table
4. Using pgAdmin for Assignments
After completing this tutorial, you should be confident to use pgAdmin for work on SQL
assignments. To use pgAdmin, you should open pgAdmin, expand the database that you
previously created, and open the Query Tool for the database to execute SQL statements. If you
have not created the database used in the assignment, lecture class, or lab class, you should
follow the steps to create and populate a new database before executing SQL statements for the
assignment or course examples.