During the previous parts, we set up our Linux terminal, and install PostgreSQL version 11 ( PG11 ) and now we are ready to install and Plug the AGE extension and start using it.
we start our blog from this point
- have access to a Linux terminal ( Linux OS or WSL tool for Windows).
- have already installed PostgreSQL version 11 ( PG11 ) correctly.
so if you are ready with both let's go!
4. AGE installation ( Advanced Graph Extension )
Note
- As instructed in the repository for AGE installation we need to run this command before working through this, which installs essential libraries needed. ( for each distro we have specific commands the following used for the Ubuntu distro )
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison
Then let's focus on AGE itself,
First we go to the desired directory where we need to download AGE and clone the age repository from GitHub as,
git clone <repository link>
,
in this case
git clone https://github.com/apache/age/
,
now we have the AGE source repository with the "master" branch as default, if we need to change it to another branch to work through just go to the repo directory and do,
git checkout <desired branch name>
,
for example, to switch to the branching supporting PG12 we do it as
git checkout AGE_PG12.1.0_ALPHA
but in our case, we will keep it as it's ( since as we mention the master branch supports PG11 and that's the version we already using )
Second after cloning the repository we make install the AGE script from the cloned repo with the desired branch already checked out.
we do the installation by changing the directory to the age repo directory and applying this command,
make install
but if the PostgreSQL is not in the PATH variable we have to do it as,
make PG_CONFIG=<path to postgres version>/bin/pg_config install
for me it was,
make PG_CONFIG=/usr/lib/postgresql/11/bin/pg_config install
Note
- Here you may face an error on this step as "ERROR: 'postgres.h' file not found" , and after some search I solve it by this command ,
sudo apt install postgresql-server-dev-XX
( where XX is the major version, for our case it's 11 Major version)
and then apply the make PG_CONFIG=/usr/lib/postgresql/11/bin/pg_config install
command again and finally AGE is installed successfully!
5. How to use AGE
- After the installation, open a connection to a running instance of your database and run the CREATE EXTENSION command to have AGE be installed on the server.
CREATE EXTENSION age;
- For every connection of AGE you start you will need to load the AGE extension.
LOAD 'age';
Note
it's important to add ag_catalog to your search_path , to simplify your queries and documentation assumes you have already done that.
it's done as ,
SET search_path = ag_catalog, "$user", public;
- Allow non-superusers to use Apache AGE
sudo ln -s /usr/lib/postgresql/11/lib/age.so /usr/lib/postgresql/11/lib/plugins/age.so
Also, you can check the documentation for more details and try some interesting examples to test the extension.
Hope to be a useful Tutorial and if you have any questions or comments I am totally happy to hear from you!
References :
- https://www.postgresql.org/download/linux/ubuntu/
- https://wiki.postgresql.org/wiki/Apt
- https://stackoverflow.com/questions/53434849/cannot-install-postgres-on-ubuntu-e-unable-to-locate-package-postgresql
- https://www.cherryservers.com/blog/how-to-install-and-setup-postgresql-server-on-ubuntu-20-04
- https://github.com/apache/age/
- https://stackoverflow.com/questions/56724622/how-to-fix-postgres-h-file-not-found-problem
- https://age.apache.org/age-manual/master/intro/overview.html
Top comments (0)