DEV Community

Zainab-Saad
Zainab-Saad

Posted on • Updated on

Install PostgreSQL and AGE from Source Code

What is Apache AGE

AGE is an acronym for A Graph Extension - an extension built on the top of already existing object relational database management system (ORDBMS)PostgreSQL. AGE is a multi-model database which means that it supports the following

  • graph database and cypher queries

  • relational database and SQL queries

  • JSON

  • Key value database

  • SQL and/or cypher Hybrid Querying

In this article we will look into the following

  1. Installation of PostgreSQL 11.18 from source code

  2. Installation of AGE from source code

Prerequisites

This article uses the commands for Linux Operating System. You should have Linux installed either on the virtual machine or dual boot alongside Windows/MacOS

  • For Windows users: here

  • For MacOS users: here

You should also have git installed on your system. To check if git is installed, type into terminal
git --version
If it returns the version of git, you are good to go else see the installation guide on Git Doc

Installing postgres

Step 1 Make a directory and a subdirectory where you will install postgres

mkdir postgres_age
cd postgres_age
mkdir postgres
cd postgres
Enter fullscreen mode Exit fullscreen mode

Step 2 Install the Linux libraries before the actual installation. The commands may vary for different OS. Check this link out if you are not Ubuntu.
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison

Step 3 Install the development files for postres from postgresql-server-dev-xx package. This command will vary according to the version of Linux. Check out the compatible command for your version here. Note: Install postgres 11 or 12 as these are the versions AGE is compatible with. I am on Jammy(22.04 LTS), so I use the following command
sudo apt install postgresql-server-dev-all

Step 4 Download the tar file to install postgres which will extract to the directory /postgres_age/postgres
wget https://ftp.postgresql.org/pub/source/v11.18/postgresql-11.18.tar.gz && tar -xvf postgresql-11.18.tar.gz && rm -f postgresql-11.18.tar.gz

Step 5 Installing psql. While running ./configure, enable debugging flag. To read more on the flags, read Doc. pwd will install postgres in the current directory

cd postgresql-11.18
./configure --enable-debug --enable-cassert --prefix=$(pwd) CFLAGS="-ggdb -Og -fno-omit-frame-pointer"
make install
cd ../../
Enter fullscreen mode Exit fullscreen mode

Installing AGE

Step 6 Clone the AGE GitHub Repository
git clone https://github.com/apache/age.git

Step 7 Installing and configuring AGE with psql

cd age
sudo make PG_CONFIG=/home/zainab/postgres_age/postgres/postgresql-11.18/bin/pg_config install
make PG_CONFIG=/home/zainab/postgres_age/postgres/postgresql-11.18/bin/pg_config installcheck
Enter fullscreen mode Exit fullscreen mode

If you see that all the tests have passed as shown in the image below, then AGE is installed successfully

If you see that all the tests have passed as shown in the image, then AGE is installed successfully

Database Initialization

Step 8 Initialize a database cluster. You can think of database cluster as The collection of databases which will be managed by single instance of running server.

cd ..
cd postgres/postgresql-11.18
bin/initdb pg_age
Enter fullscreen mode Exit fullscreen mode

Step 9 Start server
bin/pg_ctl -D pg_age -l logfile start
Now create a database named practicedb
bin/createdb practicedb

Step 10 Launch the postgres command line client psql
bin/psql practicedb

Create and Load AGE

Step 11 Create and Load AGE extension in order to start using it

CREATE EXTENSION age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
Enter fullscreen mode Exit fullscreen mode

Step 12 Start querying using cypher commands

SELECT create_graph('people');
SELECT * FROM cypher('people', $$ CREATE (n: Person {name : "Zainab", bornIn : "Pakistan"}) $$ ) AS (a agtype);
SELECT * FROM cypher ('people', $$ CREATE (n : Person {name : "John", bornIn : "US"}) $$ ) AS (a agtype);
SELECT * FROM cypher('people', $$ MATCH (v) RETURN v $$) as (v agtype);
Enter fullscreen mode Exit fullscreen mode

The output is shown below

Output screenshot

To get more information about Apache AGE, explore the website

References

If you find any ambiguity or incorrect statement, let me know in comment section

Happy learning!

Top comments (0)