- Details
- Written by Nam Ha Minh
- Last Updated on 01 December 2026   |   Print Email
This tutorial takes you from an empty Windows machine to a working PostgreSQL database. You will install the server and pgAdmin, verify that PostgreSQL is running as a Windows service, create a database named schooldb, define a students table, and insert two rows. The screenshots show PostgreSQL 19 on Windows x86-64 and pgAdmin 4; the same workflow applies to nearby versions, although labels and screen layout may differ slightly.By the end, you should be able to connect to the local server and run this query:
SELECT *
FROM public.students
ORDER BY student_id;
Table of Content:
1. Download PostgreSQL for Windows
2. Install PostgreSQL Server
3. Install pgAdmin 4
4. Verify the PostgreSQL installation
5. Open pgAdmin and connect to the local PostgreSQL server
6. Create your first PostgreSQL database
7. Create a new table
8. Insert rows with the pgAdmin data editor
9. Disconnect from the server
10. Common installation problems
What the PostgreSQL installer provides
The Windows installer brings together the database server and the tools needed for local development. For a first installation, I recommend keeping the default components selected. They use little extra disk space and save you from returning to the installer when you need a command-line utility later.
| Component | Purpose |
| PostgreSQL Server | Runs the database engine and stores the database cluster on disk. |
| pgAdmin 4 | Provides a graphical interface for connecting to servers and managing databases, schemas, tables, and data. |
| Command Line Tools | Includes utilities such as psql, pg_dump, pg_restore, and createdb. |
| Stack Builder | Downloads optional drivers, extensions, and supporting packages after the core installation. |
Before you begin - Use a 64-bit version of Windows and sign in with an account that can install software.
- Choose a password for the postgres superuser and store it securely. pgAdmin needs it for the first connection.
- Keep TCP port 5432 unless another PostgreSQL instance already uses it.
- Allow roughly 1 GB of free disk space for the programs, then reserve additional space for database data and backups.
Open the PostgreSQL website: Go to the official
PostgreSQL website and click Download on the home page:
Open PostgreSQL.org and select Download.
Choose Windows: On the download page, select Windows to see the supported packages and installer options.
Choose Windows on the PostgreSQL download page
Open the EDB installer page: Click Download the installer. The link opens the PostgreSQL installer page maintained by EnterpriseDB.
Continue to the Windows installer download
Download the 64 bit installer: Locate PostgreSQL 19 and click the download icon in the Windows x86-64 column. If the website lists a newer major version, choose the version required by your project or use the current supported release for a new learning environment.
Download PostgreSQL 19 for Windows x86-64

Wait for the PostgreSQL installer download to finish
Launch the setup program: Open the downloaded executable. Approve the Windows security prompt if one appears, then click
Next on the welcome screen.

Start the PostgreSQL setup wizard
Choose the installation directory: The default location under
C:\Program Files is appropriate for most users. This directory contains PostgreSQL executables and supporting files; it is separate from the directory that stores your databases.

Keep or change the PostgreSQL installation directory
Select the components: Keep PostgreSQL Server, pgAdmin 4, Stack Builder, and Command Line Tools selected. The server is required. pgAdmin is the graphical administration tool, while the command-line tools are useful for scripting and backups.

Select the PostgreSQL components to install
Choose the data directory: The data directory holds the database cluster: configuration files, transaction logs, and all databases managed by this server instance. Use a local disk with enough free space and do not treat this directory like an ordinary folder of editable files.

Choose where PostgreSQL will store the database cluster
Set the postgres password: Enter a strong password for the postgres database superuser. This is a PostgreSQL credential, not necessarily your Windows password. You will use it when pgAdmin connects for the first time.

Set the password for the postgres superuser
Keep port 5432: PostgreSQL listens on TCP port 5432 by default. Keeping the standard port makes examples and development tools easier to configure. Change it only if the port is already in use or your environment requires a different value.

Use the default PostgreSQL port 5432
Select the locale: The locale affects collation and character classification in the new cluster. The default locale is suitable for many learning environments. Production systems should choose deliberately because changing a cluster's locale later usually requires creating a new cluster and migrating data.

Select the locale for the database cluster
Review the installation summary: Check the program directory, data directory, port, superuser name, and Windows service details. Click Next when the values are correct, then click Next again to begin installation.

Review the PostgreSQL preinstallation summary
Wait while the cluster is initialized: The installer copies the program files, creates a Windows service, initializes the database cluster, and starts the server. Initialization creates the system catalogs and template databases required by PostgreSQL.

PostgreSQL installation in progress

The installer initializes the PostgreSQL database cluster
pgAdmin is the graphical client used in the rest of this tutorial. Depending on the installer build, its setup may run as a separate wizard. Choose Yes when the PostgreSQL installer asks whether to install it.

Allow the installer to set up pgAdmin 4

The PostgreSQL setup starts the pgAdmin installer
Continue from the welcome page: Click
Next in the pgAdmin setup wizard.

Start the pgAdmin 4 setup wizard
Accept the license agreement: Review the license terms, accept the agreement, and continue.

Accept the pgAdmin license agreement
Choose the destination and Start menu folder: The default destination under
C:\Program Files and the default pgAdmin Start menu folder are convenient for most installations.

Choose the pgAdmin installation directory

Choose the pgAdmin Start menu folder
Install pgAdmin: Review the settings, click
Install, and wait for the wizard to copy the application files.

Confirm that pgAdmin is ready to install

pgAdmin installation in progress

Finish the pgAdmin setup wizard
The PostgreSQL installer also creates an uninstaller so the installed components can be changed or removed later.

The setup program creates the PostgreSQL uninstaller
Finish PostgreSQL setup: When the main setup wizard completes, clear
Launch Stack Builder if you do not need optional drivers or extensions now, then click
Finish. Stack Builder can be opened later from the Start menu.

Finish setup without launching Stack Builder
Before creating a database, verify that the PostgreSQL Windows service is running. A successful program installation is not enough; clients can connect only while the service is active.
Check the service in Task Manager: Open Task Manager, select the
Services tab, and find the PostgreSQL service. Its status should be Running.

Verify that the PostgreSQL service is running
Open the Services console: Right-click the PostgreSQL service name (
postgresql-x64-19) and choose
Open Services. This opens the Windows Services management console, where you can inspect and control the service.

Open the PostgreSQL service in the Windows Services console
Inspect service properties: The service properties show its executable path, startup type, and current status. Automatic startup is convenient on a development machine because PostgreSQL starts with Windows. Use Start, Stop, or Restart only when no important database operation is running.

PostgreSQL Windows service properties
Quick command line check If you prefer a terminal, open PowerShell and run the following command. The exact service name includes the installed major version.
Get-Service -Name "postgresql*"
Launch pgAdmin 4: Open the Start menu, type
pgadmin, and select pgAdmin 4.

Launch pgAdmin 4 from the Windows Start menu
Wait for pgAdmin 4 to start
Connect to PostgreSQL 19: In the
Object Explorer, expand
Servers and select
PostgreSQL 19. Enter the postgres password that you set during installation. Enable
Save Password if this is a private development computer and you accept the local credential storage risk.

Enter the postgres superuser password
Confirm the server connection: After pgAdmin connects, expand
Databases. The postgres maintenance database appears by default. The template databases are system templates and should not be used for ordinary application data.

The connected PostgreSQL server in pgAdmin Object Explorer
Open the Create Database dialog: Right-click
Databases, point to
Create, and choose
Database.

Create a database from the Databases context menu
Name the database: Enter
schooldbas the database name. Leave postgres as the owner for this local exercise, then click
Save.

Create a database named schooldb
Verify the new database: The
schooldbdatabase should appear under
Databases. If it does not appear immediately, right-click
Databases and choose
Refresh.

The schooldb database appears in Object Explorer
SQL equivalent You can create the same database from a Query Tool connected to another database, such as postgres:
CREATE DATABASE schooldb;
A PostgreSQL server contains databases, and each database contains schemas. A schema is a namespace that groups tables and other objects. New databases normally include a public schema, so the fully qualified table name in this tutorial is public.students. Qualifying the schema makes SQL clearer and avoids surprises when an application changes its search path. Open the Create Table dialog: Expand
schooldb, Schemas, public, and
Tables. Right-click Tables, point to
Create, and choose
Table.

Create a table in the public schema
Enter the table name: On the General tab, enter
studentsas the table name. Confirm that the schema is public.

Name the new table students
Define the columns: Open the Columns tab and add the three columns shown below. Turn on
Primary key for
student_id. The serial type creates an integer column backed by a sequence, so PostgreSQL can generate an identifier when you leave the field at its default value.
| Column | Data type | Purpose |
| student_id | serial | Primary key whose value is generated from a sequence |
| name | character varying 50 | Student name with a maximum length of 50 characters |
| age | smallint | Small integer value for the student's age |
Define the students table columns and primary key
Save the table: Click
Save. Expand
Tables to verify that
public.studentsexists. You can right-click the table and choose
Properties later to inspect or change its definition.

The students table in the public schema
SQL equivalent CREATE TABLE public.students (
student_id serial PRIMARY KEY,
name varchar(50),
age smallint
);
For new production schemas, many teams prefer a generated identity column instead of serial because identity behavior is part of the SQL standard. The pgAdmin steps above intentionally match the supplied example.
CREATE TABLE public.students_identity_example (
student_id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name varchar(50),
age smallint
);
Open all rows: Right-click
public.students, point to
View / Edit Data, and choose
All Rows. pgAdmin opens a Query Tool tab and runs a SELECT statement for the table.

Open the pgAdmin data editor for the
studentstable
The Query Tool and Data Output panes for public.students
Add two rows: Click the Add row button in the
Data Outputtoolbar. Leave
student_idas default so PostgreSQL generates it. Enter
John Doe with age
23 and
Mary Jones with age
30.

Add John Doe and Mary Jones in the data editor
Save the changes: Click
Save Data Changes. The default
student_id values are replaced by generated integers after the rows are stored. Close or refresh the tab, then view all rows again to confirm the records.

The saved students rows with generated primary keys
SQL equivalent INSERT INTO public.students (name, age)
VALUES
('John Doe', 23),
('Mary Jones', 30);
SELECT student_id, name, age
FROM public.students
ORDER BY student_id;
Do not type values into student_id unless you have a specific reason to override the sequence. Letting PostgreSQL generate the key avoids duplicate primary key errors and keeps the sequence synchronized.
Disconnecting pgAdmin closes its session; it does not stop the PostgreSQL Windows service. The server continues running in the background for other applications. Right-click the server, choose
Disconnect from Server, confirm the action, and then close pgAdmin.

Disconnect pgAdmin from the PostgreSQL server
Password rejected Confirm that you are entering the database password created during setup for the postgres role. It may differ from your Windows password.
Connection refused on port 5432 Check that the PostgreSQL service is running and that pgAdmin uses the port selected during installation. If you installed more than one major version, each instance normally needs a different port.
Database or table not visible Refresh the relevant Object Explorer node. Also confirm that you created the table under schooldb and the public schema rather than under the postgres maintenance database.
Stack Builder was skipped That is fine for this tutorial. PostgreSQL Server, pgAdmin, and the command-line tools are already installed. Open Stack Builder later only when you need an optional driver or extension package.
Where to go next
You now have a working local PostgreSQL environment and a small database that you can query. A useful next exercise is to open the Query Tool for schooldb, run the SQL examples from this article, and then practice UPDATE, DELETE, filtering with WHERE, and sorting with ORDER BY. Before using PostgreSQL for an important project, also learn how to create a non-superuser application role and how to back up a database with pg_dump.
About the Author:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on
Facebook and watch
his Java videos on YouTube.