To install PostgreSQL on Windows, download the interactive installer from the official PostgreSQL website, run it, and follow the prompts to set a superuser password and select a port (default 5432). The installer handles the database server, pgAdmin GUI, and command-line tools, and it adds PostgreSQL to your system PATH so you can run psql from any terminal.
What You Need Before You Start
PostgreSQL runs on all modern Windows versions, but a few prerequisites make the installation smoother:
- Windows 10 or 11 (64-bit) – the official installer is 64-bit only. If you are on 32-bit Windows, you would need to build from source, which is not recommended for most users.
- Administrator rights – the installer needs to create a Windows service and write to
C:\Program Files. Right-click the installer and choose “Run as administrator” if prompted. - At least 1 GB of free disk space – the core installation is about 300 MB, but you will want extra room for databases and logs.
- An internet connection – the installer can download additional components like Stack Builder, which offers extensions and drivers.
If you already have an older PostgreSQL version, the installer will detect it and offer an upgrade path. Back up your databases before upgrading, as the process can change internal data formats.
Downloading the Installer
Go to the official PostgreSQL download page at postgresql.org/download/windows/. You will see two options:
- Interactive installer by EDB – the most common choice. It bundles PostgreSQL, pgAdmin, and the Stack Builder utility.
- ZIP archive – a portable version that does not require installation. You unzip it, run
initdbto create a data directory, and start the server manually. This is useful for testing or if you cannot install software.
For most users, the interactive installer is the right pick. It is a single .exe file (about 250 MB) that handles everything from service setup to PATH configuration.
Step-by-Step Installation
Once the installer downloads, double-click it and follow these steps:
- Choose installation directory – the default is
C:\Program Files\PostgreSQL\<version>. Keep it unless you have a specific reason to change it. - Select components – PostgreSQL Server, pgAdmin 4, Stack Builder, and Command Line Tools are all checked by default. Keep them all unless you want a minimal install.
- Set the data directory – defaults to
C:\Program Files\PostgreSQL\<version>\data. Some users prefer a separate drive for data, but the default is fine for most. - Enter a superuser password – this is the password for the
postgresuser. It is critical: you cannot reset it easily if you forget it. Use a strong password and store it in a password manager. - Choose a port – the default is
5432. If that port is already in use (maybe by another PostgreSQL instance), the installer will warn you. Change it to something like5433in that case. - Select locale – the default is usually the system locale. If you plan to work with multiple languages, consider choosing
English, United Statesto avoid collation issues. - Review and install – the installer shows a summary. Click Next and wait for the installation to finish.
After installation, the installer asks if you want to launch Stack Builder. You can skip this for now—it is used to add tools like PostGIS or replication software later.
Verifying the Installation
To confirm PostgreSQL is working, open a command prompt and run:
psql --version
You should see something like psql (PostgreSQL) 16.4. If you get a “command not found” error, the installer did not add PostgreSQL to your PATH. You can either add C:\Program Files\PostgreSQL\<version>\bin to your PATH manually, or use the full path to psql.
Next, test connecting to the server:
psql -U postgres
It will prompt for the password you set during installation. If you connect successfully, you will see the postgres=# prompt. Type \q to exit.
You can also open pgAdmin 4 from the Start menu. It will ask for the postgres password when you first connect to the local server.
Common Installation Problems
Even with a smooth installer, things can go wrong. Here are the most frequent issues and fixes:
- Port 5432 is already in use – run
netstat -ano | findstr :5432to see which process is using it. If it is another PostgreSQL instance, either stop that service or choose a different port during installation. - “psql is not recognized” – the PATH was not set. Add
C:\Program Files\PostgreSQL\<version>\binto your system PATH via System Properties > Environment Variables. - Service fails to start – check the Windows Event Viewer for error logs. Often this is due to a data directory permission issue. Right-click the data folder, go to Properties > Security, and ensure the
NETWORK SERVICEaccount has full control. - Password forgotten – you can reset it by editing
pg_hba.confto usetrustauthentication for local connections, restarting the service, and then setting a new password. This is a last resort; it temporarily disables security. - Installer hangs – close any antivirus software temporarily, as it can interfere with the service creation step. Also make sure you have enough free disk space.
Post-Installation Configuration
After a successful install, you may want to tweak a few things:
- Enable remote connections – by default PostgreSQL only listens on localhost. To allow remote access, edit
postgresql.confand changelisten_addressesto'*', then add a line inpg_hba.conflikehost all all 0.0.0.0/0 scram-sha-256. Be careful—this exposes your database to the network. - Set a password for the postgres user – if you skipped it or want to change it, run
ALTER USER postgres PASSWORD 'newpassword';in psql. - Create a dedicated user – instead of using the superuser for everything, create a regular user with
CREATE USER myapp WITH PASSWORD 'secret';and grant only the privileges it needs. - Backup your data – use
pg_dumpor the pgAdmin backup wizard. Schedule regular backups if you are using PostgreSQL for production data.
Alternatives to the Interactive Installer
If the standard installer does not fit your needs, consider these options:
- Docker – run PostgreSQL in a container with
docker run --name my-postgres -e POSTGRES_PASSWORD=secret -d postgres. This is great for development and testing, and it avoids polluting your Windows system. - Windows Subsystem for Linux (WSL) – install PostgreSQL inside WSL2 with
sudo apt install postgresql. This gives you a Linux environment and is often easier for developers who use Linux commands. - Portable ZIP archive – as mentioned earlier, this lets you run PostgreSQL without installing. You need to run
initdbandpg_ctlmanually, which is more involved but gives you full control.
Frequently Asked Questions
How do I uninstall PostgreSQL from Windows?
Go to Control Panel > Programs and Features, select PostgreSQL, and click Uninstall. The uninstaller removes the server, tools, and the Windows service. It does not remove your data directory by default—you can delete it manually if you are sure you no longer need the databases.
Can I install multiple PostgreSQL versions on the same machine?
Yes. The installer uses version-specific directories and service names (e.g., postgresql-x64-16). You can install 15 and 16 side by side, but they must use different ports. The default port for the second installation will need to be changed to 5433 or similar.
How do I start and stop the PostgreSQL service?
Open the Services app (services.msc), find the service named postgresql-x64-<version>, and right-click to start, stop, or restart it. You can also use the command line: net start postgresql-x64-16 or net stop postgresql-x64-16 as Administrator.
Why is pgAdmin asking for a password every time?
pgAdmin stores passwords in its own vault. If you close the connection and reconnect, it may prompt again. To save the password, right-click the server in pgAdmin, choose Properties, and under the Connection tab check “Save password.”
What is the default superuser name and password?
The default superuser is postgres. The password is the one you set during installation. There is no default password—if you left it blank, you may have an insecure setup. Reset it immediately with ALTER USER postgres PASSWORD 'newstrongpassword';.
How do I change the port after installation?
Edit postgresql.conf in your data directory and change the port line to a new number. Then restart the service. If you are using a firewall, update the rule to allow the new port.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Set Up UPI Payments Through WhatsApp
- Pair Oppo Enco Earbuds with Android, iPhone & Windows
- Fix Administrator Account Disabled Error in Windows 11
- How to Play Kodi on Smart TV from PC
- Hogwarts Legacy Microsoft Visual C Runtime Error Fix
- Factory Reset on Samsung Galaxy: What It Erases