Install PostgreSQL on Windows
Operating environment
- PostgreSQL
-
- PostgreSQL 15
- Windows
-
- Windows Server 2019
Prerequisites
- Windows
-
- Windows Server 2019
- Windows Server 2016
- Other versions may work, but are not officially supported.
download
In a web browser, access the following pages:
Download the installer
link.
Download it by clicking the download link for Windows x86-64
the latest version.
install
Run the downloaded installer.
Click the Next button.
This is the location where you want to install PostgreSQL. Unless otherwise specified, click the "Next" button.
I think that the only one that is unlikely to be used is "Stack Builder", but if there is nothing in particular, you can install everything as it is.
Component | Description |
---|---|
PostgreSQL Server | PostgreSQL database server itself |
pgAdmin 4 | Tools that allow you to manipulate databases with a GUI |
Stack Builder | Tools to install peripheral tools |
Command Line Tool | Tools that allow you to manipulate PostgreSQL databases with commands |
This is the location where you want to store your PostgreSQL data. Unless otherwise specified, click the "Next" button.
Enter the PostgreSQL administrator password. The account name is fixed with "postgres". Since you are an administrator, do not specify an easy password, especially in production operation. You can also change it later.
This is the port to use when connecting from other PC environments. Unless otherwise specified, click the "Next" button. You can specify a different port number for added security, but be aware that it may complicate operation and maintenance.
By default, it is "[Default locale]", but This is a choice that determines the locale according to the locale setting of the Windows running the installer. In this case, select "C", which does not use a locale.
Check the settings so far, and if there are no problems, click the "Next" button.
Click the Next button to start the installation.
「Launch Stack Builder at exit?」 If you click the "Finish" button with the check box checked, the setup by Stack Builder will start as it is, so uncheck it if you do not need it. You can also configure Stack Builder later.
Setting Environment Variables
Setting environment variables is useful because you do not have to specify the path to the executable file when using PostgreSQL commands, for example, at the command prompt.
The procedure to display the environment variable setting screen differs depending on the version of Windows. However, if you type "Edit environment variables" in the start menu, it will be displayed in one shot.
Select "Path" from "System Variables" and click the "Edit" button.
Click the New button.
Enter the path to the "psql.exe" where the command can be executed. The default path for PostgreSQL 15 is as follows, so enter that path. Note that the path varies depending on the version. You do not need to include the EXE file name.
C:\Program Files\PostgreSQL\15\bin
Check if the file actually exists by opening it in File Explorer.
After entering, click the OK button to close all environment variable screens.
Confirmation of operation
Once you've opened the Start menu, cmd
type to open a command prompt.
Enter and execute the following command:
psql --version
If you see the PostgreSQL version, you have successfully set the environment variable.
Miscellaneous
Working with databases in the GUI
Start "PostgreSQL > pdAdmin 4" from the Start menu.
Manipulating databases with commands
Start "PostgreSQL > SQL Shell (psql)" from the start menu.