DEV Community

hammadsaleemm
hammadsaleemm

Posted on

2

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.

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
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:

CREATE EXTENSION age;
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

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry πŸ•’

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more β†’

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay