Initialization and creating a database for testing the installation of Postgres and Age part 2.

talhahahae

Talha Munir 🇵🇸

Posted on February 2, 2023

Initialization and creating a database for testing the installation of Postgres and Age part 2.

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.

Image description

Starting Server

# Start server:
bin/pg_ctl -D sample -l logfile start
Enter fullscreen mode Exit fullscreen mode

The command will return a message saying that the server has started.

Image description

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.

Image description

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

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;

Image description

Try below queries using cypher commands:

SELECT create_graph('demo_graph');

Image description

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);

Enter fullscreen mode Exit fullscreen mode

The output of above command will look like this:

Image description

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

💖 💪 🙅 🚩
talhahahae
Talha Munir 🇵🇸

Posted on February 2, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related