---
title: "PostgreSQL on Windows: Discover a MySQL Alternative and Learn Effectively"
description: "Dive into PostgreSQL on Windows—a MySQL alternative—for seamless integration, scalability, and robust data management solutions."
canonical: "https://adamtheautomator.com/postgresql-on-windows/"
---

# PostgreSQL on Windows: Discover a MySQL Alternative and Learn Effectively

> Dive into PostgreSQL on Windows—a MySQL alternative—for seamless integration, scalability, and robust data management solutions.

Source: https://adamtheautomator.com/postgresql-on-windows/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![A MySQL Alternative: Learning PostgreSQL on Windows](https://adamtheautomator.com/wp-content/uploads/2024/02/postgresql-on-windows.jpg)

# A MySQL Alternative: Learning PostgreSQL on Windows

[![](https://secure.gravatar.com/avatar/1bc5e1d52466fc3739f550c8d78be310684747bf1466a98d698320627ea243e2?s=192&d=mm&r=g)Michael Nguyen Tu](https://adamtheautomator.com/author/michael-nguyen-tu/)9 February 20247 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PostgreSQL](/tag/postgresql/)[Windows](/tag/windows/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing PostgreSQL on Windows](#installing-postgresql-on-windows)
*   [Mastering PostgreSQL Database Management with pgAdmin 4](#mastering-postgresql-database-management-with-pgadmin-4)
*   [Harnessing PowerShell for Effective PostgreSQL Management](#harnessing-powershell-for-effective-postgresql-management)
*   [Conclusion](#conclusion)

Database management can feel limited on your Windows system at some point. If you’re considering a switch from MySQL or just looking to expand your database expertise, it’s your lucky day. PostgreSQL on Windows offers a promising alternative!

This tutorial ushers you into the world of PostgreSQL and guides you through installation steps, fundamental operations, and essential commands.

Master PostgreSQL on Windows as your ticket to database stardom!

## Prerequisites

Get ready for a hands-on experience in this tutorial. To join in, make sure you’ve got the following in place:

*   A machine running Windows 7 or higher – This tutorial uses a Windows 10 64-bit machine.
*   PowerShell 5+ or later installed on your machine – This tutorial uses PowerShell v7.

Related:[PowerShell 7 Upgrade: A Comprehensive Walkthrough](https://adamtheautomator.com/powershell-7-upgrade/)

## **Installing PostgreSQL on Windows**

Before you embark on your PostgreSQL journey and delve into the nitty-gritty of PostgreSQL, you’ll first install PostgreSQL on your Windows system. PostgreSQL is a celebrated open-source [relational database management system (RDBMS)](https://www.oracle.com/ph/database/what-is-a-relational-database/) that stands out.

PostgreSQL’s stability, reliability, and advanced features distinguish itself from alternatives like MySQL. This RDBMS supports complex data types, offers the capacity to define custom functions, and enables the use of stored procedures.

To get started with PostgreSQL, you first need to install it on your Windows system as follows:

1\. Open your preferred web browser, visit the [official PostgreSQL website](https://www.postgresql.org/download/windows/), and download the Windows installer. This tutorial uses PostgreSQL version 16.2, the latest as of the time of this writing.

![Downloading the latest PostgreSQL installer for Windows](https://adamtheautomator.com/wp-content/uploads/2024/02/image-103.png)

Downloading the latest PostgreSQL installer for Windows

2\. Next, open the downloaded installer to launch the installation wizard.

3\. On the setup wizard, click **Next** to continue with the installation.

![Continuing with the PostgreSQL installation](https://adamtheautomator.com/wp-content/uploads/2024/02/image-102.png)

Continuing with the PostgreSQL installation

4\. Now, choose a destination folder for the PostgreSQL installation (or retain the default setting), then click **Next** to proceed.

![Choose a destination folder for the PostgreSQL installation](https://adamtheautomator.com/wp-content/uploads/2024/02/image-101.png)

Choose a destination folder for the PostgreSQL installation

5\. Select the components you wish to install below, and click **Next** to confirm.

*   **PostgreSQL Server** – The core database engine for storing and managing data.
*   **pgAdmin 4** – A graphical administration tool for managing PostgreSQL databases.
*   **Stack Builder** – A utility for installing additional tools, drivers, and extensions for PostgreSQL.
*   **Command Line Tools** – Essential for executing PostgreSQL commands and scripts directly from a command line interface (CLI).

![Selecting components to install](https://adamtheautomator.com/wp-content/uploads/2024/02/image-100.png)

Selecting components to install

6\. Subsequently, specify the **Data Directory** for PostgreSQL’s data files storage (or accept the default location), and click **Next** to continue.

![Specifying the data directory for PostgreSQL's data files storage](https://adamtheautomator.com/wp-content/uploads/2024/02/image-99.png)

Specifying the data directory for PostgreSQL’s data files storage

7\. Provide and confirm a strong password for the database superuser (**postgres**) account, and Click **Next** to proceed.

Store this password securely, as you will require it for future access.

Related:[Keep End Users Secure with Strong Passwords](https://adamtheautomator.com/strong-passwords/)

![Providing a secure password for the database superuser](https://adamtheautomator.com/wp-content/uploads/2024/02/image-98.png)

Providing a secure password for the database superuser

8\. Assign a port number for PostgreSQL (keeps the default port **5432**) to listen on for connections, and click **Next**.

![Assigning a port number for PostgreSQL](https://adamtheautomator.com/wp-content/uploads/2024/02/image-97.png)

Assigning a port number for PostgreSQL

9\. Now, select the desired locale for PostgreSQL to use from the dropdown, and click **Next** to confirm. This tutorial sticks with the preselected default option (**Default locale**).

In PostgreSQL, a locale is a set of rules and data that the database server uses to determine the following:

*   How text data is sorted and compared.
*   How dates and times are formatted.
*   How numbers are represented.
*   And other behaviors that may vary depending on the geographic or linguistic context of the users.

![Selecting the desired locale for PostgreSQL](https://adamtheautomator.com/wp-content/uploads/2024/02/image-96.png)

Selecting the desired locale for PostgreSQL

10\. Review the installation summary (modify settings as needed), and click **Next** to confirm.

![Reviewing and confirming the selected settings](https://adamtheautomator.com/wp-content/uploads/2024/02/image-95.png)

Reviewing and confirming the selected settings

11\. Click **Next** once more to proceed with installing PostgreSQL on your system.

![Proceeding with the PostgreSQL installation](https://adamtheautomator.com/wp-content/uploads/2024/02/image-94.png)

Proceeding with the PostgreSQL installation

12\. Lastly, untick the **Launch Stack Builder** box once the installation is complete, and click **Finish** to close the wizard.

![Finishing the PostgreSQL installation](https://adamtheautomator.com/wp-content/uploads/2024/02/image-93.png)

Finishing the PostgreSQL installation

## Mastering PostgreSQL Database Management with pgAdmin 4

Now that PostgreSQL’s all set up on your Windows, you dive into database management. Folks love PostgreSQL’s strength and flexibility, especially in Linux setups where it’s CLI-friendly. How about a graphical user interface (GUI) instead?

Say hello to pgAdmin 4, a tool designed to accommodate the management of PostgreSQL databases on Windows systems.

To master PostgreSQL database management in pgAdmin 4, you’ll create and administer databases, tables, and records with the following steps:

1\. Launch **pgAdmin 4** from the Windows Start menu.

![Launching pgAdmin 4 from the Start menu](https://adamtheautomator.com/wp-content/uploads/2024/02/image-114.png)

Launching pgAdmin 4 from the Start menu

2\. When pgAdmin 4 opens, expand **Servers** (left pane) and access the PostgreSQL 16 server.

![Accessing the PostgreSQL 16 server](https://adamtheautomator.com/wp-content/uploads/2024/02/image-113.png)

Accessing the PostgreSQL 16 server

3\. When prompted, enter your password for the database superuser (postgres) and click **OK** to authenticate the server connection.

Optionally, tick the **Save Password** box to save the password to bypass this authentication process in future sessions.

![Authenticate connection to the server](https://adamtheautomator.com/wp-content/uploads/2024/02/image-112.png)

Authenticate connection to the server

4\. Upon successful login, expand **Databases** and select **postgres** (left pane) to access the default database and its associated objects.

![Viewing the default postgres database](https://adamtheautomator.com/wp-content/uploads/2024/02/image-111.png)

Viewing the default postgres database

5\. Now, click the **Tools** menu and choose **Query Tool** to open an SQL editor for executing commands.

![Accessing the Query Tool for executing commands](https://adamtheautomator.com/wp-content/uploads/2024/02/image-110.png)

Accessing the Query Tool for executing commands

6\. Type the following command in the query editor, then press F5 or click the play button to `CREATE` a new `DATABASE` called `mydatabase` (arbitrary).

```sql
CREATE DATABASE mydatabase;
```

A confirmation message appears in the **Messages** tab to signal a successful creation.

![Creating a new database via the Query Tool](https://adamtheautomator.com/wp-content/uploads/2024/02/image-109.png)

Creating a new database via the Query Tool

7\. Once created, open a Query Tool session for the new database in the left pane (i.e., **mydatabase**) as you did in step five.

![Opening a Query Tool session with the new database](https://adamtheautomator.com/wp-content/uploads/2024/02/image-108.png)

Opening a Query Tool session with the new database

8\. Execute the following SQL statement to `CREATE` a new `TABLE` called `mytable` (arbitrary) in your database. This table has four columns, specifying the data type for each column and whether or not the column can contain `NULL` values.

The `id` column is set to automatically increment with each new record, providing a unique identifier for each row.

```sql
-- Create a new table named 'mytable'
CREATE TABLE mytable (
    -- Define a column 'id' which:
    -- - Is of type SERIAL (auto-incrementing integer)
    -- - Acts as the primary key for the table
    id SERIAL PRIMARY KEY,

    -- Define a column 'name' which:
    -- - Is of type VARCHAR with a maximum length of 50 characters
    -- - Cannot be NULL (must have a value)
    name VARCHAR(50) NOT NULL,

    -- Define a column 'age' which:
    -- - Is of type INT (integer)
    -- - Can be NULL (it's optional to have a value)
    age INT,

    -- Define a column 'email' which:
    -- - Is of type VARCHAR with a maximum length of 100 characters
    -- - Can be NULL (it's optional to have a value)
    email VARCHAR(100)
);
```

![Creating a table in the new database](https://adamtheautomator.com/wp-content/uploads/2024/02/image-107.png)

Creating a table in the new database

9\. Expand **Schemas** (left pane) **→ Tables →** your new table (**mytable**), and replace and execute the statement with the following. This statement lets you `INSERT` data `INTO` your table (`mytable`) in three columns: `name`, `age`, and `email`.

```sql
INSERT INTO mytable (name, age, email) VALUES
    ('John Doe', 28, 'john.doe@example.com'),
    ('Jane Smith', 32, 'jane.smith@example.com'),
    ('Jim Brown', 40, 'jim.brown@example.com');
```

![Inserting data into the new table](https://adamtheautomator.com/wp-content/uploads/2024/02/image-104.png)

Inserting data into the new table

10\. Lastly, right-click on your table (**mytable**), hover **View/Edit Data,** and choose **All Rows** to automatically executes a query to retrieve data from your table.

Notice your table’s data populates in a table format under the **Data Output** tab, giving you a clear view of the records, as shown below.

![Viewing the newly inserted data](https://adamtheautomator.com/wp-content/uploads/2024/02/image-105.png)

Viewing the newly inserted data

## Harnessing PowerShell for Effective PostgreSQL Management

While pgAdmin 4 offers convenience with its GUI, CLI in different environments brings a new efficiency level. Whether automating backups, configuring user permissions, or executing SQL queries, PowerShell stands ready to streamline these tasks seamlessly.

PowerShell’s integration with PostgreSQL via specialized modules makes PowerShell a powerful ally in database administration.

To leverage PowerShell for managing your PostgreSQL databases, proceed with the following:

1\. Open [PowerShell as an administrator](https://adamtheautomator.com/powershell-run-as-administrator/) and execute the [`Install-Module`](https://learn.microsoft.com/en-us/powershell/module/powershellget/install-module) command to install the PostgreSQL module (`PostgreSQLCmdlets`) from the PowerShell Gallery.

```powershell
Install-Module -Name PostgreSQLCmdlets
```

![Installing the PostgreSQL module](https://adamtheautomator.com/wp-content/uploads/2024/02/image-117.png)

Installing the PostgreSQL module

Related:[Getting Started with PowerShell Gallery](https://adamtheautomator.com/powershell-gallery/)

2\. Once installed, run the [`Import-Module`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module) command below to [import the module](https://adamtheautomator.com/import-powershell-modules/) (`PostgreSQLCmdlets`) into your current session.

```powershell
Import-Module PostgreSQLCmdlets
```

Related:[How to Import PowerShell Modules Like a Boss](https://adamtheautomator.com/import-powershell-modules/)

3\. Run each variable assignment below, which provides no output, but set up your database connection parameters.

Ensure you replace the placeholders accordingly, but the password placeholder should be the one you set during the PostgreSQL installation.

```powershell
# Define the server where the database is hosted
$Server = 'localhost'

# Specify the port number for the database connection (PostgreSQL default: 5432)
$Port = '5432'

# Set the name of the database you want to connect to
$Database = 'mydatabase'

# Provide the username for database authentication
$User = 'postgres'

# Assign the password for the specified user
$Password = 'your_password_here'
```

4\. Now, run the following command, which uses your variable assignments in step three to establish a connection (`Connect-PostgreSQL`) to your PostgreSQL database.

```powershell
$connection  = Connect-PostgreSQL  -User "$User" -Password "$Password" -Server "$Server" -Database "$Database" -Port "$Port"
```

Activate a trial license as follows:

*   Input **Y**, then press Enter to confirm using a trial license.
*   Enter your **Email** address and **Name.**
*   Type in trial **TRIAL** as the **Product Key** and hit Enter.

Once connected, you can now carry out SQL operations.

![Connecting to the PostgreSQL server and activating a trial](https://adamtheautomator.com/wp-content/uploads/2024/02/image-116.png)

Connecting to the PostgreSQL server and activating a trial

5\. Execute the following query and PowerShell command (`Invoke-PostgreSql`) to retrieve all data (`SELECT *`) `FROM` your table (`mytable`).

The following lines produce no output on the console, but you’ll verify the retrieved data later.

```powershell
# Define the SQL query to select all records from the table named "mytable"
$query = "SELECT * FROM mytable;"

# Run the SQL query against the PostgreSQL database
# -Connection specifies the database connection to use
# -Query specifies the SQL query to execute
# The result of the query is assigned to the $result variable
$result = Invoke-PostgreSql -Connection $connection -Query $query
```

6\. Finally, execute the following command to view the retrieved data (`$result`) in a human-readable format (`Format-Table`).

`$result | Format-Table -AutoSize`

```powershell
$result | Format-Table -AutoSize
```

![Viewing the retrieved data in a table format](https://adamtheautomator.com/wp-content/uploads/2024/02/image-115.png)

Viewing the retrieved data in a table format

Related:[PowerShell Format-Table: Organize Output in Columns](https://adamtheautomator.com/powershell-format-table/)

## Conclusion

PostgreSQL on Windows is not merely an alternative to MySQL but a robust, enterprise-level database solution. In this tutorial, you’ve learned how to integrate tools like pgAdmin 4 and PowerShell to transform database management on Windows into a streamlined and efficient process.

You’ve just dipped your toes into PostgreSQL, but there’s a whole ocean of possibilities ahead. Why not dive in and [explore diverse data types](https://www.postgresql.org/docs/current/datatype.html), [set up database roles](https://www.postgresql.org/docs/current/user-manag.html), and [define user role memberships](https://www.postgresql.org/docs/current/role-membership.html)? PostgreSQL is full of surprises—take your time to uncover its full potential!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpostgresql-on-windows%2F&text=A%20MySQL%20Alternative%3A%20Learning%20PostgreSQL%20on%20Windows)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpostgresql-on-windows%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpostgresql-on-windows%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2024/04/idfix.jpg)

### [Solve Azure AD Connect Errors via the Microsoft IdFix Tool](/idfix/)

Fix Azure AD Connect errors fast with the Microsoft IdFix tool—your go-to solution for seamless synchronization and efficient directory management!

![](https://adamtheautomator.com/wp-content/uploads/2024/04/sandboxie.jpg)

### [How to Install Sandboxie on Windows](/sandboxie/)

Secure your Windows system with Sandboxie. Learn how to install this tool hassle-free and safeguard your digital activities!

![](https://adamtheautomator.com/wp-content/uploads/2022/11/How-to-Install-NitroShare-for-Cross-Platform-File-Transfer.jpg)

### [Install NitroShare and Streamline Your File Transfers Today](/nitroshare/)

Simplify cross-platform file transfers with NitroShare. This tutorial guides you through installation and use for fast, effortless file sharing between different operating systems.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
