Introduction
PostgreSQL is an open-source, object-based relational database management system. It is well-known for its robustness, SQL compliance, and extensibility.
In this tutorial, we will go over the step-by-step process of installing PostgreSQL on Windows 10. We will also show different ways to connect to a PostgreSQL database and verify the installation.
Prerequisites
- A system running Windows 10
- Access to a user account with administrator privileges
Download PostgreSQL Installer
Before installing PostgreSQL, you need to download the installation file from the EDB website.
Find the Windows x86-64 category for the latest version of PostgreSQL and click the Download button.
Note: For more information on installing PostgreSQL on other operating systems, check out our guide to installing PostgreSQL on Ubuntu.
Install PostgreSQL on Windows
Follow the steps below to install PostgreSQL on Windows:
1. Open the PostgreSQL install file to start the installation wizard. Click Next to continue.
2. Choose an install location for PostgreSQL and click Next to proceed.
3. Select which software components you want to install:
- PostgreSQL Server: Installs the PostgreSQL database server.
- pgAdmin 4: Provides a graphical interface for managing PostgreSQL databases.
- Stack Builder: Allows you to download and install additional tools to use with PostgreSQL.
- Command Line Tools: Installs the command line tool and client libraries. Required when installing PostgreSQL Server or pgAdmin 4.
Once you check the boxes next to the components you want to install, click Next to continue.
4. Choose a database directory to store data and click Next to continue.
5. Enter and retype the password for the database superuser. Click Next to proceed.
Note: PostgreSQL runs as a background process under a service called postgres. If you already have a service named postgres running, enter the password for that service account when prompted.
6. Enter the port number for the PostgreSQL server to listen on and click Next to continue.
Note: The default port number for the PostgreSQL server is 5432. When entering a custom port number, make sure no other applications are using the port.
7. Choose the locale for the database to use. Selecting the [Default locale] option uses the locale settings for your operating system. Once you have chosen a locale, click Next to continue.
8. The last step offers a summary of the installation settings. Click Back if you want to change any of the settings you made, or click Next to proceed.
9. The setup wizard informs you it is ready to start the installation process. Click Next to begin installing PostgreSQL.
Connect to the PostgreSQL Database
You can verify the new PostgreSQL installation by connecting to the database using the SQL shell or the pgAdmin tool:
Connect to the PostgreSQL Database Using the SQL Shell (psql)
1. Open the SQL Shell (psql) in the PostgreSQL folder in the Start menu.
2. Enter the information for your database as defined during the setup process. Pressing Enter applies the default value, as shown in the square brackets.
3. Verify the new database by using the command:
select version();
Note: For more details on PostgreSQL version commands, check out our article on how to check PostgreSQL version.
Connect to the PostgreSQL Database Using pgAdmin
1. Open the pgAdmin 4 tool from the PostgreSQL folder in the Start menu.
Note: pgAdmin requires you to set a master password at first launch.
2. Right-click the Servers icon on the left-hand side. Select Create > Server to set up a new database server.
3. In the General tab, enter the name for the new database. In this example, we are using PostgreSQL as the database name.
4. In the Connection tab, enter the hostname (default is localhost) and password selected during the setup process. Click Save to create the new database.
5. Expand the server display by clicking on the Servers > PostgreSQL icons on the left-hand side. Select the default postgres database.
6. In the Tools drop-down menu, click Query Tool to open the query editor.
7. Verify the database in the query editor by entering the following command and clicking the Execute button:
select version();
If the database is working properly, the current version of the database will appear in the Data Output section.
Conclusion
After following this tutorial, you should have PostgreSQL installed and working on your Windows system. You should also have your first PostgreSQL database set up and ready to use.