Testing:
In the previous article we learned how to install PostgreSQL and age from sourcePart 1 here.
Now we will create and test whether the installation was successful or not
Database initialization:
Now we will initialize our database cluster. Let's name it sample.
cd postgresql-11.18/
Intitialization
bin/initdb sample
When you will execute the command the success message will be shown with the command to start the server.
Starting Server
# Start server:
bin/pg_ctl -D sample -l logfile start
The command will return a message saying that the server has started.
Create Database:
The below command will create the database. We name it SampleDatabase.
bin/createdb SampleDatabase
Start querying Database:
Now that AGE has been added to pg successfully. Now we can start testing using pg_sql console.
bin/psql SampleDatabase
The above command will start a console now we will type some commands and see what happens after certain commands.
When we initialize a new Database we have to load age extension in order to start using age. First, we will set the search path if we didn't set them earlier in the postgresql.config file.
CREATE EXTENSION age;
Load 'age';
The above command will load the extension and we also need to set the search path and other variables.
SET search_path = ag_catalog, "$user", public;
Try below queries using cypher commands:
SELECT create_graph('demo_graph');
It will create a graph named demo_graph.
SELECT * FROM cypher('demo_graph', $$ CREATE (n:Person {name : "james", bornIn : "US"}) $$) AS (a agtype);
SELECT * FROM cypher('demo_graph', $$ CREATE (n:Person {name : "Talha", bornIn : "Lahore"}) $$) AS (a agtype)
SELECT * FROM cypher('demo_graph', $$ MATCH (n) RETURN n $$) as (a agtype);
The output of above command will look like this:
The last query returns all the rows in the database.
References:
You can take help from following links they helped me in installing as well:
https://github.com/git-guides/install-git
https://age.apache.org/age-manual/master/intro/setup.html
https://www.postgresql.org/docs/current/install-procedure.html
Top comments (0)