DEV Community

Omar Saad
Omar Saad

Posted on

Step by step guide to install PostgreSQL + Apache AGE on Windows

In this post, we will discuss how to install PostgreSQL and Apache AGE on a Windows machine in a step-by-step manner. By the end of this guide, you'll have a fully functional PostgreSQL database and Apache AGE graph database, ready to use for your data-driven applications.

What is PostgreSQL ?
PostgreSQL is one of the most famous relational databases in the world that is designed to manage and store large amounts of structured data.

PostgreSQL is open-source and it is known for its reliability, robustness, and scalability. It provides a variety of advanced features, including support for transactions, stored procedures, and triggers.

PostgreSQL supports a wide range of data types, including text, numeric, and date/time data, as well as more complex data structures such as arrays, JSON, and XML.

What is Apache AGE ?
Apache AGE is a graph database system that is built on top of PostgreSQL. It allows users to store, manage, and analyze large-scale graph data in a highly performant and scalable way.

Apache AGE combines the benefits of a powerful relational database management system (PostgreSQL) with the flexibility and scalability of a graph database. This means that users can store their data in a relational format and also perform graph-based queries and analyses on the data.

How to install PostgreSQL and Apache Age ?
Currently, Apache AGE does not support Windows. Therefore, in this tutorial, we will use Windows Subsystem for Linux (WSL) as an alternative.

1. Install WSL.
To enable WSL on your computer, follow these steps: First, go to the Control Panel, and then select Programs. Next, select Turn Windows features on or off. From the list of features, enable both Virtual Machine Platform and Windows Subsystem for Linux, as shown in the image

Image description

After enabling WSL, the next step is to install a Linux distribution for Windows. To do this, open the Microsoft Store and search for 'Linux.' You will see several options available, and you can choose the one you prefer. For the purposes of this tutorial, we will be using 'Ubuntu 22.04.2 LTS'.

2. Installing PostgreSQL from source code.
Please note that currently, Apache AGE only supports PostgreSQL versions 11 and 12, so we must install one of these versions. Before proceeding, we need to install some dependencies. To do this, open a bash terminal by navigating to any directory and typing 'bash' in the address bar, and then run the appropriate command.

sudo apt install git libreadline-dev zlib1g-dev bison flex build-essential
Enter fullscreen mode Exit fullscreen mode

Next, create a directory where you want to install PostgreSQL and clone the Postgres repository into it.

mkdir postgres-AGE-project
cd postgres-AGE-project
git clone https://git.postgresql.org/git/postgresql.git
Enter fullscreen mode Exit fullscreen mode

Navigate to the 'postgresql' directory and switch to a compatible version branch. For the purposes of this tutorial, we'll be using version 12.

cd postgresql
git checkout REL_12_STABLE
Enter fullscreen mode Exit fullscreen mode

Compile the source code and specify the directory where you want the binaries to be installed. Note that this process may take some time to complete.

./configure –prefix=/usr/local/pgsql-12
make 
Enter fullscreen mode Exit fullscreen mode

After the compilation process is complete, run the following command to add permissions for the binaries directory and replace user by your username. Once this is done, proceed to install PostgreSQL

sudo mkdir /usr/local/pgsql-12
sudo chown user /usr/local/pgsql-12
make install
Enter fullscreen mode Exit fullscreen mode

To ensure that PostgreSQL can be accessed from anywhere in the terminal, it is necessary to set up the following environment variables
These commands will add the PostgreSQL binaries directory to the system path and set the PGDATA directory to the location of the PostgreSQL data files.

export PATH=/usr/local/pgsql-12/bin/:$PATH
export PGDATA=/usr/local/pgsql-12/bin/data
Enter fullscreen mode Exit fullscreen mode

Now that you have installed PostgreSQL, you can create a new cluster, which is a collection of databases managed by a single instance of the PostgreSQL server. To create a new cluster, run the following command:

initdb
Enter fullscreen mode Exit fullscreen mode

After initializing the cluster, you can start the PostgreSQL server by running the following command:

pg_ctl -D /usr/local/pgsql-12/bin/data -l logfile start
Enter fullscreen mode Exit fullscreen mode

Now you can start PostgreSQL by running the following command:

psql postgres
Enter fullscreen mode Exit fullscreen mode

Congratulations! You have successfully installed and started PostgreSQL.

To exit PostgreSQL run \q

To stop the server run the following command:

pg_ctl -D /usr/local/pgsql-12/bin/data -l logfile stop
Enter fullscreen mode Exit fullscreen mode

If you would like more detailed information about the installation process, you can visit the following link: PostgreSQL documentation

3. Installing Apache AGE from source code.
To install Apache AGE from source code, go to the main directory of the postgres-AGE-project that we created earlier and execute the following command to clone the AGE project.

git clone https://github.com/apache/age.git
Enter fullscreen mode Exit fullscreen mode

To proceed with the installation, navigate to the project directory and switch to the latest stable release, which is version 1.1.0.

cd age
git checkout release/PG12/1.1.0
Enter fullscreen mode Exit fullscreen mode

Set the environment variable PG_CONFIG. we need to set the PG_CONFIG environment variable to specify the location of the PostgreSQL pg_config utility. pg_config is a command-line utility that provides information about the installed version of PostgreSQL, including the location of files and libraries required for compiling and linking programs against PostgreSQL. Apache AGE uses pg_config to determine the location of the PostgreSQL header files and libraries needed to compile the AGE extension.

export PG_CONFIG=/usr/local/pgsql-12/bin/pg_config
Enter fullscreen mode Exit fullscreen mode

Then install AGE extension by running this command:

make install
Enter fullscreen mode Exit fullscreen mode

Now you have AGE installed to add the extension in your postgres server run the following SQL commands:

CREATE EXTENSION age;    
Enter fullscreen mode Exit fullscreen mode

Then every time you want to use AGE you must load the extension.

LOAD 'age';    
Enter fullscreen mode Exit fullscreen mode

Great job! You have successfully installed Apache AGE on your system.

You can find further information on AGE installation and usage on the official Apache AGE documentation at AGE documentation.

References
PostgreSQL
AGE - Installation giude

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

Top comments (0)