Introduction
In this article i'll be walking you through the installation of the Apache AGE PostgreSQL extension and then in my upcoming articles we'll try out some cool stuffs with the extension together. But before we go into the installation process I'd assume you know what a database is? and also you know what SQL is? and finally you know about PostgreSQL. If you don't, you can get started with some of these:
Quick introduction to SQL
Getting started with PostgreSQL
What then is Apache AGE?
Apache AGE is an open-source graph database management system that provides a powerful and scalable solution for storing, managing and analyzing large-scale graph data. It is built as an extension of PostgreSQL and supports complex graph queries and provides fast query response times, making it an excellent choice over traditional relational database management systems. With Apache AGE, users can gain deeper insights into data and make more informed decisions. So we can simply say Apache AGE gives you the super power of expressing your database graphically.
Cool? 😉
Before we get to play around with it let's get started with installing it on our local machine.
Setting up
Like i said earlier Apache AGE is a PostgreSQL extension so to use it we need to get PostgreSQL installed on your machine. Apache AGE is only compatible with 3 versions of PostgreSQL (11, 12, 13(only compatible with the newest release)). For this article series we'll be working with the version 11/12, we'll talk about the new Apache AGE release that's compatible with the PostgreSQL 13 later when we are comfortable with the previous versions. Before we start installing postgres we'll need to install some dependencies on our machine for Apache AGE to work on your local machine. It is important to know that Apache AGE would only work on a Linux Operating System distribution. If you use Windows OS consider installing a virtual machine or try out
wsl
Run the following command to install the aforementioned dependencies
Ubuntu
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison
Fedora
dnf install gcc glibc bison flex readline readline-devel zlib zlib-devel
Centos
yum install gcc glibc glib-common readline readline-devel zlib zlib-devel flex bison
Now to installing PostgreSQL.
For demonstration I'll be working with PostgreSQL 12, there are more than one ways to install postgres on your computer, one way is by compiling directly from the source code, you can go through this guide to try that.
But I'll be installing via the ubuntu postgresql apt repository
Note:
This only works on an ubuntu machine (Linux) to get it working on other operating systems or distributions you might want to check out the official documentation for your OS and distributions here
for ubuntu >= 18.04:
Run the following code:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-12
After installation (if you get any errors let me know in the comments), you need to add the bin directory path to the PATH
env variable if not already added. By default the installation path is /usr/lib/postgresql/<version>
for version 12 it'll be /usr/lib/postgresql/12/
To add to PATH
you can run export PATH="/usr/lib/postgresql/12/bin/:$PATH"
You might want to consider adding that to your .bash_profile
or .bash_rc
.
Also make sure you confirm that postgres service is running sudo systemctl status postgresql
if it's inactive or not running, you can run sudo systemctl start postgresql
to start it up.
To login to your postgres database for the first time, you need to use the default admin user created by postgres. So to go into postgres you need to run sudo -u postgres psql
ceejay@ceejay:~$ sudo -u postgres psql
psql (12.14 (Ubuntu 12.14-1.pgdg22.04+1))
Type "help" for help.
postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
postgres=#
Let's go ahead and create a database
sudo -u postgres createdb <dbname>
We can also create a user
sudo -u postgres createuser <username>
Create a password for the user
ceejay@ceejay:~$ sudo -u postgres psql
psql (12.14 (Ubuntu 12.14-1.pgdg22.04+1))
Type "help" for help.
postgres-# \password ceejay
Enter new password for user "ceejay":
Enter it again:
postgres-#
For me the user created earlier is ceejay
so for you change it to your the user you created earlier.
Let's check if our database was actually created.
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | en_NG | en_NG |
template0 | postgres | UTF8 | en_NG | en_NG | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_NG | en_NG | =c/postgres +
| | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_NG | en_NG |
(4 rows)
Conclusion
You can do a lot more with postgresql, consider reading the documentation to learn more, for example you can try creating another database with the newly created user, noticed from above we used the default admin postgres
to do that with the sudo -u postgres createdb <db_name>
line, i was able to create it because the admin has all the privileges to do so, so you can consider granting the new user the privileges to create a new database. In the next article of this series we'll go ahead and install the Apache AGE extension on top of our postgres. If you encountered any errors or have any questions leave them in the comment section below.
Next we'll be installing the AGE extension.
Top comments (0)