Initialization of the cluster, Creating a graph, and Adding a node (PART 2: Installing Apache and PSQL from source)
hammadsaleemm
Posted on March 3, 2023
Have you ever wanted to use AGE (AgensGraph Extension) with PostgreSQL but struggled with initializing the cluster and adding nodes? In this article, we will walk you through the steps of initializing the cluster, making a graph, and adding nodes to it.
In a previous article, we discussed how to install Apache AGE and PSQL from source on your machine. If you haven't done that yet, you can find the article here.
Initialization
The first step is to initialize the cluster. To do this, open your terminal and enter the following commands:
cd postgresql-11.18/
# intitialization
bin/initdb demo
For now, db name is demo.
Server start
Once the cluster is initialized, you can start the server by running the following commands:
bin/pg_ctl -D demo -l logfile start
bin/createdb demodb
The first command starts the server, and the second command creates a database named "demodb." You can now see the files and the database in your terminal.
Querying Start
Now that the server is up and running, you can connect to the database and start manipulating it. To do this, run the following command:
bin/psql demodb
The last step is to load the extension for AGE by running the following commands:
CREATE EXTENSION age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
Your terminal should now look like this:
You can now try some queries with Cypher commands. For example, you can create a graph, add a node to it, and then display the node. Run the following commands:
SELECT create_graph('demo_graph');
SELECT * FROM cypher('demo_graph', $$ CREATE (n:Person {name : "hammad", bornIn : "Pakistan"}) $$) AS (a agtype);
SELECT * FROM cypher('demo_graph', $$ MATCH (v) RETURN v $$) as (v agtype);
The output of these commands will add the node to the graph, and you should see something like this:
Congratulations! You have now initialized the cluster, created a graph, and added a node to it using AGE and PostgreSQL. In the next article, I will be telling about age-viewer to make graph and nodes easily
Posted on March 3, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.