Unable to access to created graph on AgensGraph - agens-graph

Unalbe to access on graph after re-login.
$ agens
agens (AgensGraph 1.3, based on PostgreSQL 10.3)
Type "help" for help.
agens=# create graph graph;
CREATE GRAPH
agens=# match (n) return n;
n
---
(0 rows)
agens=# \q
$ agens
agens (AgensGraph 1.3, based on PostgreSQL 10.3)
Type "help" for help.
agens=# match (n) return n;
ERROR: graph_path is NULL
HINT: Use SET graph_path
agens=# \q
How can I access to created graph?
How can I call "set graph_path" on login automatically?

Use "set graph_path" command for search on your graph.
agens (AgensGraph 1.3, based on PostgreSQL 10.3)
Type "help" for help.
agens=# set graph_path to graph;
SET
agens=# match (n) return n;
n
---
(0 rows)
agens=# \q
$ agens
agens (AgensGraph 1.3, based on PostgreSQL 10.3)
Type "help" for help.
agens=# match (n) return n;
ERROR: graph_path is NULL
HINT: Use SET graph_path
agens=# \q
But, You must set graph_path everytime on login.
For avoid inconvenience, You can set graph_path on your account.
$ agens
agens (AgensGraph 1.3, based on PostgreSQL 10.3)
Type "help" for help.
agens=# alter user agens set graph_path to graph;
ALTER ROLE
agens=# \q
$ agens
agens (AgensGraph 1.3, based on PostgreSQL 10.3)
Type "help" for help.
agens=# match (n) return n;
n
---
(0 rows)
agens=# \q
Use "alter user" for set graph_path of user.

Related

How to find all property names of label on AgensGraph?

I want to find all property names of specific label on AgensGraph.
Which command am I use?
There is no command to find property names.
But, you can use function "jsonb_object_keys" for it.
agens=# create (:v1{key:1,value:2});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# create (:v1{id:1,text:'value'});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# match (n:v1) return distinct jsonb_object_keys( properties(n) );
jsonb_object_keys
-------------------
"text"
"id"
"value"
"key"
(4 rows)

Unable to access graph after re-login

I created graph on AgensGraph.
$ agens
agens (AgensGraph 2.1.0, based on PostgreSQL 10.4)
Type "help" for help.
agens=# create graph g;
CREATE GRAPH
agens=# create (:v{id:1});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# \q
$ agens
agens (AgensGraph 2.1.0, based on PostgreSQL 10.4)
Type "help" for help.
agens=# match (n) return n;
ERROR: graph_path is NULL
HINT: Use SET graph_path
agens=# \q
But, unable to access graph after re-login.
How to access graph after re-login
Use "ALTER USER ... SET GRAPH_PATH TO ..." statement for set default graph on login.
$ agens
agens (AgensGraph 2.1.0, based on PostgreSQL 10.4)
Type "help" for help.
agens=# create graph g;
CREATE GRAPH
agens=# alter user agens set graph_path to g;
ALTER ROLE
agens=# create (:v{id:1});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# \quit
After changing "GRAPH_PATH", You can access to your graph.
$ agens
agens (AgensGraph 2.1.0, based on PostgreSQL 10.4)
Type "help" for help.
agens=# match (n) return n;
n
-----------------
v[3.1]{"id": 1}
(1 row)

How to find lock-wait queries on AgentGraph?

I'm suffering from slow transaction of AgensGraph.
CPU Usage is extremely low.
I'm guessing that lock-wait situation.
How to find lock-wait queries?
You can try lock-wait log of AgensGraph.
First, change parameters on "postgresql.conf"
log_lock_waits = on
deadlock_timeout = 1s
Second, restart AgensGraph.
$ ag_ctl stop
waiting for server to shut down.... done
server stopped
$ ag_ctl start
server starting
Finally, run queries and check log file.
[Session1 : block tran]
agens=# begin;
BEGIN
agens=# create (:n{id:1});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
agens=# rollback;
ROLLBACK
agens=#
[Session2 : lock-wait transaction ]
agens=# create (:n{id:1});
GRAPH WRITE (INSERT VERTEX 1, INSERT EDGE 0)
Check log from log file.
LOG: process 3908 still waiting for ShareLock on transaction 1586 after 1001.058 ms
DETAIL: Process holding the lock: 3906. Wait queue: 3908.
CONTEXT: while inserting index tuple (0,7) in relation "n_id_idx"
STATEMENT: create (:n{id:1});
LOG: process 3908 acquired ShareLock on transaction 1586 after 4639.630 ms
CONTEXT: while inserting index tuple (0,7) in relation "n_id_idx"
STATEMENT: create (:n{id:1});

How to load file on AgensGraph?

I tried to load comma separated file on agensgraph.
But agensgraph does not have load utility on package.
How can I load file on agensgraph?
You can use "Foreign Data Wrapper", Instead of utility.
First, create file few extension.
agens=# CREATE EXTENSION file_fdw;
CREATE EXTENSION
Second, create server object.
agens =# CREATE SERVER graph_import FOREIGN DATA WRAPPER file_fdw;
CREATE SERVER
Next, create foreign table with file.
agens =# CREATE FOREIGN TABLE fdwSample
agens-# (
agens(# id INT8,
agens(# name VARCHAR(256)
agens(# )
agens-# SERVER graph_import
agens-# OPTIONS
agens-# (
agens(# FORMAT 'csv',
agens(# HEADER 'false',
agens(# DELIMITER ',',
agens(# NULL '',
agens(# FILENAME 'sample.dat'
agens(# );
CREATE FOREIGN TABLE
Last, load file use "LOAD" clause.
agens=# LOAD FROM fdwSample AS sample
agens-# CREATE (:node {id:sample.id,name:sample.name});
GRAPH WRITE (INSERT VERTEX 2, INSERT EDGE 0)
After all, you can find loaded data.
agens =# MATCH (n:node) RETURN n;
n
-------------------------------------
node[3.1]{"id": 1, "name": "steve"}
node[3.2]{"id": 2, "name": "bill"}
(2 rows)
Good luck.

Unaccent issue when restoring a Postgres database

I want to restore a particular database under another database name to another server as well. So far, so good.
I used this command :
pg_dump -U postgres -F c -O -b -f maindb.dump maindb
to dump the main database on the production server. The I use this command :
pg_restore --verbose -O -l -d restoredb maindb.dump
to restore the database in another database on our test server. It restore mostly ok, but there are some errors, like :
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3595; 1259 213452 INDEX idx_clientnomclient maindbuser
pg_restore: [archiver (db)] could not execute query: ERROR: function unaccent(text) does not exist
LINE 1: SELECT unaccent(lower($1));
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT unaccent(lower($1));
CONTEXT: SQL function "cyunaccent" during inlining
Command was: CREATE INDEX idx_clientnomclient ON client USING btree (public.cyunaccent((lower((nomclient)::text))::character varying));
cyunaccent is a function that is in the public shcema and does gets created with the restore.
After the restore, I am able to re-create those indexs perfecly with the same sql, without any errors.
I've also tried to restore with the -i option of pg_restore to do a single transaction, but it doesn't help.
What am I doing wrong ?
I just found the problem, and I was able to narrow it down to a simple test-case.
CREATE SCHEMA intranet;
CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;
SET search_path = public, pg_catalog;
CREATE FUNCTION cyunaccent(character varying) RETURNS character varying
LANGUAGE sql IMMUTABLE
AS $_$ SELECT unaccent(lower($1)); $_$;
SET search_path = intranet, pg_catalog;
CREATE TABLE intranet.client (
codeclient character varying(10) NOT NULL,
noclient character varying(7),
nomclient character varying(200) COLLATE pg_catalog."fr_CA"
);
ALTER TABLE ONLY client ADD CONSTRAINT client_pkey PRIMARY KEY (codeclient);
CREATE INDEX idx_clientnomclient ON client USING btree (public.cyunaccent((lower((nomclient)::text))::character varying));
This test case is from a pg_dump done in plain text.
As you can see, the cyunaccent function is created in the public shcema, as it's later used by other tables in other schema.
psql/pg_restore won't re-create the index, as it cannot find the function, despite the fact that the shcema name is specified to reference it. The problem lies in the
SET search_path = intranet, pg_catalog;
call. Changing it to
SET search_path = intranet, public, pg_catalog;
solves the problem. I've submitted a bug report to postgres about this, not yet in the queue.

Resources