Easy Guide to Install PostgreSQL from Source code on Windows
Tags: postgres, apacheage, database
Published: 2023-03-16 09:44:57

As promised in my earlier post, I stated that I would be sharing a lot about my internship experience, AGE project and how to effectively utilize it. Firstly, this post covers the installation of PostgreSQL which is the foundation on which AGE is built and to be used.

**WHAT IS POSTGRESQL?**
PostgreSQL is a very powerful open-source relational database management system (RDBMS) known for its robustness, reliability, and extensibility. It supports a wide range of SQL features and data types and provides advanced functionality such as support for geographical information systems, full-text search, and JSON data. It also supports transaction processing, multi-version concurrency control, and can be run on a variety of operating systems, including Windows, Linux, and macOS.
These characteristics has made it a popular choice for a wide range of applications, from small-scale projects to large enterprise systems. For more information, click [here](https://postgresql.org).

**INSTALLATION** 
Apache AGE cannot be installed on Windows yet but it is still possible to use it by installing Windows Subsystem for Linux (WSL). PostgreSQL can be installed on Windows but for this setup, it is advisable to install both PostgreSQL and AGE through WSL.

**1. Installing WSL**
Open the command prompt and enter the following commands.
```
wsl –install
wsl –update
```
This will install the Linux system. After the installation of WSL, you can make use of it in the command prompt by entering the command.
```
bash
```
Upon running for the first time, a username and password will be requested.

**2. Installing PostgreSQL**
You should install either versions 11 or 12 of PostgreSQL as they are the versions currently compatible with Apache AGE. To successfully install PostgreSQL, some dependencies are very important and should be within the system.
Install the dependencies.
```
sudo apt install git libreadline-dev zlib1g-dev bison flex build-essential
```
Create a directory to clone the PostgreSQL repository.
```
mkdir postgres-age
cd postgres-age
git clone https://git.postgresql.org/git/postgresql.git
```
Move into the cloned repository and change the branch to any of the compatible versions (version 12 in this case).
```
cd postgresql
git checkout REL_12_STABLE
```
Compile the code by passing the directory where resulting binaries from the compilation will be installed. The compilation process would take some time.
```
./configure –prefix=/usr/local/pgsql-12 
make
```
When compilation is completed, add permissions to the binaries directory and then install PostgreSQL.
```
sudo mkdir /usr/local/pgsql-12
sudo chown [user] /usr/local/pgsql-12
make install
```
Add the path to the PostgreSQL’s bin and data directories to environment variables.
```
export PATH=/usr/local/pgsql-12/bin/:$PATH
export PGDATA=/usr/local/pgsql-12/bin/data
```
PostgreSQL is successfully installed. To make use of it, a cluster has to be initialized first using the following command:
```
initdb 
```
The above command initializes a default cluster. To initialize another cluster, you would have to add the name after the command, for example:
```
initdb test
```
After initializing a cluster, start the server and create a database.
```
pg_ctl -D test –l logfile start
createdb test
```
To execute the above, you must have moved into the bin directory where PostgreSQL was installed.

Start PostgreSQL with the following command.
```
psql test
```
To exit PostgreSQL.
```
\q
```
Stop the server.
```
pg_ctl -D test –l logfile stop
```

To learn more about the installation of PostgreSQL 12, you can click [here](https://postgresql.org/docs/12/installation.html)

**CONCLUSION**
So that’s how to successfully install the compatible version of PostgreSQL for Apache AGE. If you have challenges or questions relating to the installation process, you can reach out to me.
In the next post, I will show you easy steps on how to install AGE. I had some challenges doing that and I would not want anyone else to face that.


**Contribute to Apache AGE**
Website: https://age.apache.org
Github: https://github.com/apache/age