Getting started with PostgreSQL on Windows
I recently joined an organization which spans across all 5 continents. My work primarily consists of building software for the betterment of lives. In my new job role, I would develop a software that facilitates linking lives across Europe with a smooth transition from one place to another.
As I familiarize myself with this new role, there are a few software building tools which I must get hands-on with before I build ‘ship-able’ product releases. So, that is when I had my first practical encounter with PostgreSQL. Having used IBM DB2 so far, I was eager to understand what additional features Postgres had.

I glossed through the internet for more information on Postgres. I began reviewing the tutorials and knowledge bases available and comparing them with other database management systems I am acquainted with. More on the findings in another blog post.
Once I had ground laid in my head for what PostgreSQL is, it was time to set it up on my Windows machine. Here, I gather all the steps needed to do so. This post will be helpful for anyone who is new to setting up Postgres and getting it up and running.
Step 1: Downloading PostgreSQL Installer
There are two applications that will be needed:
- PostgreSQL Installer: This will be needed to install Postgres server on your machine(Windows in my case). You can download this for your specific machine requirement from here.
- pgAdmin tool: This tool will be needed for management of the Postgres database. It is downloaded as part of the Installer if we select so during setup. Or, optionally, can be downloaded from here.
Step 2: Install PostgreSQL
Run the PostgreSQL Installer executable file downloaded. This will start the installation process. The below screenshots will be sufficient for you to know how to proceed step by step.



Next you will be asked to choose the directory in which data stored in the databases will be stored on system.

Please note the password that you provide here for super-user ‘postgres’. It will be used further in all admin operations.

Now, it will ask for port on which you wish to run Postgres server. Make sure there is no other service running on that port. I proceeded with default port.

Go on clicking Next until the installation begins.
Once the installation is complete, you will have to restart your Windows machine.
If you start the pgAdmin tool without restarting the machine, you will see that the options to create Server or Databases are disabled.
Step 3: Creating a new user for Postgres
Now, we are going to create a user for the Postgres. This step can be skipped if you want to operate with superuser only while managing your database.
Open cmd prompt on your Windows machine.
Go to the bin folder of where Postgres is installed.
C:\Program Files\PostgreSQL\10\bin>createuser.exe — createdb username postgres — no-createrole — pwprompt newuser
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y
Password: XXXXXXXXXX
This will create a user named ‘newuser’, using super username we specified during setup i.e. ‘postgres’. Meaning of other options:
— no-createrole: the new user will not be able to create new users
— pwprompt: createuser will ask you the new user’s password
‘newuser’ will have password that you specify.
Note: The password in the last line of above snippet is that of the superuser ‘postgres’ that we used to create this new user. This is the same password we specified during setup.
Step 4: Connecting to PostgreSQL server
Now when you open pgAdmin tool, the options to create database will be enabled.
Below images will explain how you can connect to the Postgres server.


Note: We are now connecting to the Postgres server we started in Step 1. Since we have started it on our local machine, we specify the Host address as localhost and the port is that we specified during setup.
Also, we are using the superuser ‘postgres’. Alternatively, we could also use the user that we created in Step 2.
Maintenance database is the default database name that will be created under this server.
Step 5: Creating a database
Once we have connected to the server, we can additionally create a database under it.
Navigate to Object -> Create Database
And you have Postgres all ready to be used in your application. In this example, the address to the database will be:
localhost:5042/Test
