Introduction
AgensGraph is a brand new multi-model database based on PostgreSQL with the capability to support both relational (SQL) and graph-based (NoSQL) data models, all at the same time, allowing for the power of both in the same database, with SQL Queries (Ansi-SQL) and NoSQL (Open Cypher) queries in a single Agensgraph query. It is built for enterprise use and possesses immense capabilities that make it a powerful tool, such as ACID transaction, multi-version concurrency control, triggers, a flexible data model among many more, also possessing the capability to be extended with external modules such as PostGIS
Installation
Agensgraph is available to be downloaded on both Linux and Windows with the ability to download via binary package or compiling from source code.
Linux
***Installation of pre-built packages*
- Download the pre-complied binary from the download page and select your preferred version
- Extract the package into a directory of your choosing and use the Linux command “tar xvf” on the path to complete installation. Installation via source code
- Go to Agensgraph’s Github page and get the source via this link and git clone command
- Install the essential libraries, which differ between different Linux OS, the commands for which are given below: a. For Centos: $ yum install gcc glibc glib-common readline readline-devel zlib zlib-devel b. For Fedora: $ dnf install gcc glibc bison flex readline readline-devel zlib zlib-devel c. For Ubuntu: $ sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison
- At the clone location, run configure on source true while setting prefix to the location where you are to install Agensgraph
- Run the build with make install
- Install the extension module and binary with make install-world Post Installation Setup and Config
- Environment variable setting is optional and can be done by export LD_LIBRARY_PATH=/usr/local/AgensGraph/lib:$LD_LIBRARY_PATH export PATH=/usr/local/AgensGraph/bin:$PATH export AGDATA=/path/to/make/db_cluster
- To create a database cluster: initdb [-D /path/to/make/db_cluster]
- To start the server, use: ag_ctl start [-D /path/created/by/initdb]
- To create a database: createdb [dbname]. If DB name is not specified, it is set to user name, by default
- To execute the interactive interminal: agens [dbname]. If cluster directory is not specified with -D option, the environmental variable AGDATA is used
Data Model
As told before, Agensgraph is a multi-model database, supporting both graph as well as relational model
Property Graph Model
The property graph model contains connected entities (called vertices) which can have any number of attributes, which can be categorized into labels used to group vertices. Edges are the connections between two vertices, and can also have attributes and categorized labels. They must also have a start and end vertex. Agensgraph does not allow broken edges, so before deleting a vertex, all its edges must be deleted first. The properties of edges and vertices are represented in a JSON format. Agensgraph stores information as unordered collections of name-value pairs. Agensgraph uses JSONB (JSON-Binary) format, allowing for faster processing in place of slightly slower input time.
Data Objects
In Agensgraph, several databases can have one or more schemas, which are used for relational tables as well as one or more graphs, used for graph data, although their names cannot be same. Users can only use one graph at one time, but can create several in a database.
Labels
Labels are used to group vertices and edges and can be used to provide access control for different users, and also maintain inheritance via label hierarachies. The defauly label for a vertex is ag_vertex while an edge always has one label. Every label inherits one of more labels, just like classes in OOP.
Data Definition Language
Graph
Creating Graph: CREATE GRAPH [IF NOT EXISTS] graphname [AUTHORIZATION role_name];
Several graphs can be created in a database. To specify graph used, session parameter graph_path is used.
IF NOT EXISTS: Do nothing if same name exists
AUTHORIZATION: Role name of user who will own the new graph
Show Current Graph Path: SHOW graph_path;
If graph_path is not set, the graph created is made to be graph_path
Setting Graph Path: SET graph_path = graphname;
This is a session variable, so it must be set before querying the graph and querying over multiple graph paths is not allowed.
Drop: DROP GRAPH graphname CASCADE;
Initial labels for vertices and edges cannot be deleted, so CASCADE option is used.
Labels
Create
Vertices: CREATE VLABEL v1;
CREATE VLABEL v2 inherits (v1);
Edges: CREATE ELABEL e1;
CREATE ELABEL e2;
CREATE ELABEL e3 inherits (e1, e2);
VLABEL can only inherit VLABEL (same for ELABEL) and multiple inheritance is possible for creation of complex labels.
Drop
DROP VLABEL v2;
DROP VLABEL v1;
v2 inherits v1, so it must be dropped first before v1 can be dropped
DROP e1 knows CASCADE;
Option CASCADE can be used to drop all dependencies as well
Top comments (0)