How to install AGE extension of postgresql from source code in ubuntu?

259 Views Asked by At

As I want to try out Apache Age of postgresql, I got lost when reading the documentation.

Is there any easy solutions ?

3

There are 3 best solutions below

1
On

Download source PostgreSQL package.

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

Go in PostgreSQL folder.

cd postgresql-11.18

configure by setting flags.

./configure --enable-debug --enable-cassert --prefix=$(pwd) CFLAGS="-ggdb -Og -fno-omit-frame-pointer"

Now install.

make install

Go back.

cd ../

*** CLONING AGE ***

git clone https://github.com/apache/age.git

Go in AGE cloned repo

cd age/

Install

sudo make PG_CONFIG=/home/postgresql-11.18/bin/pg_config install

Install check

make PG_CONFIG=/home/postgresql-11.18/bin/pg_config installcheck

Go in Postgresql file

cd postgresql-11.18/

initialization of db named demo

bin/initdb demo

Open File demo/postgresql.conf

nano demo/postgresql.conf

In postgresql.conf file update

shared_preload_libraries = 'age' search_path = 'ag_catalog, "$user", public'

Starting db demo which we initialized earlier

bin/pg_ctl -D demo -l logfile start
bin/createdb demo

Age in added to pg successfuly now we can test it, opens pg console

bin/psql demo

0
On

PostgreSQL versions 11 & 12 are supported for AGE extension. After installing postgresql from source code make sure bin and lib folder are in your environment variable. If not you can set it as below in cmd.

export PATH="$PATH:/home/pg/dist/postgresql-11.18/bin/"
export LD_LIBRARY_PATH="/home/pg/dist/postgresql-11.18/lib/"
export PG_CONFIG="/home/pg/dist/postgresql-11.18/bin/pg_config"

Just replace the path with your installation directory

After that clone the age in your ubuntu. Go to the directory and run

sudo make install

From now on you can run AGE extension after running pgsql as follow :

CREATE EXTENSION age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
0
On

Here is a step-by-step guide on how to install PostgreSQL and age extension for postgres from source.

Prerequisite: Ubuntu must be installed in the Virtual Machine or dual boot alongside windows. You should have ample space in your ubuntu software. You should have already installed git. If not you can take help from here Install Git.

Install some Dependencies:

mkdir age_installation
cd age_installation
mkdir pg
cd pg

Remember below commands might vary according to the operating systems.

sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison

Installation of Components from Source: For now, age only supports Postgres 11 and 12. So downloading the required version of PostgreSQL.

Download the files in the folder age-installation/pg

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

Installing PG: Now we will move toward installing PG

cd postgresql-11.18

Configure by setting flags

./configure --enable-debug --enable-cassert --prefix=$(path) CFLAGS="-ggdb -Og -fno-omit-frame-pointer"

Now install

make install

Go back

cd ../../

In the above command, the prefix flag will contain the path where you would like to install the PSQL. Replace your path with the path in the parenthesis.

AGE: Downloading: Download the age from the GitHub repository. i.e. clone it in the age_installation directory.

git clone https://github.com/apache/age.git

Installing: Configure age with PostgreSQL.

cd age/
sudo make PG_CONFIG=/home/talhastinyasylum/Desktop/age_installation/pg/postgresql-11.18/bin/pg_config install

make PG_CONFIG=/home/talhastinyasylum/Desktop/age_installation/pg/postgresql-8/bin/pg_config installcheck

Database initialization:

cd postgresql-11.18/

Intitialization

bin/initdb sample

When you will execute the command the success message will be shown with the command to start the server.

Start server:

bin/pg_ctl -D sample -l logfile start

The command will return a message saying that the server has started.

Create Database: The name of the Database is SampleDatabase

bin/createdb SampleDatabase

Start querying Database: Now that AGE has been added to pg successfully. Now we can start testing using pg_sql console.

bin/psql SampleDatabase


CREATE EXTENSION age; 
Load 'age';

The above command will load the extension and we also need to set the search path and other variables.

SET search_path = ag_catalog, "$user", public;

Try below queries using cypher commands:

SELECT create_graph('demo_graph');

It will create a graph named demo_graph.

SELECT * FROM cypher('demo_graph', $$ CREATE (n:Person {name : "james", bornIn : "US"}) $$) AS (a agtype);
SELECT * FROM cypher('demo_graph', $$ CREATE (n:Person {name : "Talha", bornIn : "Lahore"}) $$) AS (a agtype)
SELECT * FROM cypher('demo_graph', $$ MATCH (n) RETURN n $$) as (a agtype);
Copy

The last command will return the rows in the database sample image of the output