DEV Community


Posted on

Initialization of the cluster, Creating a graph, and Adding a node (PART 2: Installing Apache and PSQL from source)

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.


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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.
Image description

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
Enter fullscreen mode Exit fullscreen mode

The last step is to load the extension for AGE by running the following commands:

LOAD 'age';
SET search_path = ag_catalog, "$user", public;
Enter fullscreen mode Exit fullscreen mode

Your terminal should now look like this:
Image description

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);
Enter fullscreen mode Exit fullscreen mode

The output of these commands will add the node to the graph, and you should see something like this:

Image description

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

Top comments (0)