Using a Remote GSQL Client
Installation
When the TigerGraph platform is installed, the GSQL client and server are on the same machine. The client is packaged as a Java jar file, gsql_client.jar
located in the folder <TigerGraph_root_dir>/app/<VERSION_NUM>/dev/gdk/gsql/lib/
. Installation consists of copying the file gsql_client.jar
to the client machine and storing it anywhere the user finds appropriate. The client machine needs to have Java 7.0 or higher.
Running the Client
To run the client, execute the jar file each time that you would run gsql if you were local to the GSQL server. That is, the command
java -jar <path>gsql_client.jar
takes the place of gsql. For example, the commands
gsql DROP ALL
gsql create_my_schema.gsql
gsql LS
would become
java -jar gsql_client.jar DROP ALL
java -jar gsql_client.jar create_my_schema.gsql
java -jar gsql_client.jar LS
Therefore, it may be useful to define a Unix alias:
alias gsql="java -jar <path>/gsql_client.jar"
The java operation alone is not sufficient, however, because it does not tell the client where to find the GSQL server. In addition, the client needs to satisfy three conditions:
-
It must know the IP address of the GSQL server.
-
It must have the authorization to access the server in general and to execute the requested GSQL commands in particular.
-
If a SSL/TLS encrypted connection (e.g., HTTPS) is used, then it must provide the certificate chain.
Specifying Server IP Address
There are two ways to provide the IP address of the GSQL Server.
-
Method 1: Store the address in a file. Create a one-line file called gsql_server_ip_config containing the ip address of the GSQL server. This file needs to be in the same directory where you run GSQL.
-
Method 2 : Every time you run the client jar, provide the ip address on the command line, e.g., " gsql -ip 192.168.55.46 "
Client Authorization and Authentication
The GSQL server applies the same user authentication procedures to remote GSQL users that it applies to local GSQL users. That is, if user authentication has been enabled, then each gsql command line must include valid user credentials.
The client addresses the server at server port 14240. You need to make sure your security policy allows the access to this port.
It is strongly recommended that you enable user authentication. See the document Enabling User Authentication for more details. |
HTTPS Connection
If SSL/TLS is enabled for TigerGraph, to connect a GSQL remote client to the GSQL server, each GSQL command line should provide the certificate chain file via the -cacert option. This certificate file should be exactly the same as the file of entry Nginx.SSL.Cert setting SSL for Nginx. See Encrypting Connections: Step 2. Configure SSL with gadmin. For example:
gsql -cacert /path/to/certificate -ip hostname:port
File Path Semantics
Data loading jobs always specify an input file location; logically the data should be on the server side, not on the client side. Because the command request comes from one machine and the target data file is on another machine, it no longer makes sense to use a relative path.
Rule: If a remote GSQL client invokes an instruction containing a relative path, the GSQL server considers the starting point of the path to be It is strongly recommended that remotely-run GSQL commands use absolute paths only. |
For example, if the data file cf_data.csv is in the folder /home/tigergraph/example/cf/, then the command to run the loading job might look like this:
java -jar gsql_client.jar 'RUN JOB load_cf USING FILENAME="/home/tigergraph/example/cf/cf_data.csv", SEPARATOR=",", EOL="\n"
Example: Modifying a Bash Script for a Remote GSQL Client
The GSQL Tutorials employ both GSQL and bash scripts to run the examples. Typically, each example case contains 3 GSQL command files (for schema creation, data loading, and querying) and one bash script to run all the parts together and to display status information. Below is a simplified version of the Collaborative Filtering (cf) bash script:
#!/bin/bash
test='cf'
###
gsql 'DROP ALL'
gsql ../${test}/${test}_model.gsql
gsql 'CREATE GRAPH gsql_demo(*)'
# Loading
gsql -g gsql_demo ../${test}/${test}_load.gsql
## loading script contains this line:
## RUN JOB load_cf USING FILENAME="../cf/data/cf_data.csv", SEPARATOR=",", EOL="\n"
# Querying
gsql -g gsql_demo ../${test}/${test}_query.gsql
gsql -g gsql_demo INSTALL QUERY ALL
gsql -g gsql_demo 'RUN QUERY topCoLiked("id1", 10)'
The bash script will not run from a remote GSQL client unless a few changes are made:
-
We need to invoke "java -jar gsql_client.jar" instead of "gsql", and need to specify the server ip address.
-
If we use the gsql_server_ip_config file, this file must be in the same folder as the command file.
The GSQL Tutorial has several different folders, one for each example, so that suggests making several config files.
Below is an approach that minimizes the changes required and maximizes standardization.
-
Do initial client setup. This is done only once.
-
Store gsql_client.jar in a standard location, say ~/gsql_client/gsql_client.jar (e.g,, /home/tigergraph/gsql_client/ gsql_client.jar )
-
Create a file called gsql_server_ip_config containing the GSQL server’s IP address, and store it a standard location, say ~/gsql_client/gsql_server_ip_config .
Sample config file:/home/tigergraph/gsql_client/gsql_server_ip_config123.45.67.255
-
In the .bashrc file in your home directory, add an alias for gsql which points to the standard location:
alias gsql='java -jar ~/gsql_client/gsql_client.jar'
-
-
Add a standard header to each bash script.
Standard which makes 'gsql' work on remote clientsalias gsql='java -jar gsql_client.jar' shopt -s expand_aliases ln -s ~/gsql_client/gsql_client.jar gsql_client.jar ln -s ~/gsql_client/gsql_server_ip_config gsql_server_ip_config
This header does the following:
-
Repeat the alias definition for the gsql command. The definition in .bashrc may not be visible here.
-
By default, bash scripts ignore aliases. Instruct the script to use aliases.
-
Define softlinks from the current folder to the locations of the client jar and config file.
-
-
Change any relative paths to absolute paths. This is the only step that must be customized for each script.
Here is the resulting script. Four standard lines were added to the beginning, and one line was edited in the cf_load.gsql file.
#!/bin/bash
alias gsql='java -jar gsql_client.jar'
shopt -s expand_aliases
ln -s ~/gsql_client/gsql_client.jar gsql_client.jar
ln -s ~/gsql_client/gsql_server_ip_config gsql_server_ip_config
test='cf'
###
gsql 'DROP ALL'
gsql ../${test}/${test}_model.gsql
gsql 'CREATE GRAPH gsql_demo(*)'
# Loading
gsql -g gsql_demo ../${test}/${test}_load.gsql
## loading script contains this line:
## RUN JOB load_cf USING FILENAME="/home/tigergraph/tigergraph/document/examples/tutorial_real_life/cf/data/cf_load.csv", SEPARATOR=",", EOL="\n"
# Querying
gsql -g gsql_demo ../${test}/${test}_query.gsql
gsql -g gsql_demo INSTALL QUERY ALL
gsql -g gsql_demo 'RUN QUERY topCoLiked("id1", 10)'