Using a Remote GSQL Client
You can use the GSQL client to access a GSQL server on a different machine, including on a TigerGraph Cloud instance.
Prerequisites
-
The machine running the GSQL client needs to have Java 7.0 or later.
-
The server machine allows the client machine to access port 14240.
-
OpenSSL is needed on the client machine to get an SSL certificate from a TigerGraph Cloud solution.
Connect to a remote server
Download the GSQL client
As an alternative to downloading, you can also copy the file gsql_client.jar
from an existing installation to the client 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/
on an existing TigerGraph installation.
Connect to the server
To connect to a remote server, your must provide the following to the GSQL client:
-
The IP address of the GSQL server.
-
Your TigerGraph user credentials.
-
If you are running GSQL commands, the user you are logged in as must have the privileges to run them.
-
If SSL/TLS encryption (e.g., HTTPS) is enabled on the server, you must provide the server’s SSL certificate.
Run the following command to connect to the remote server:
java -jar <path_to_client> \ (1)
[--cacert <path_to_certificate>|--ssl] \ (2)
--ip <ip_address> \ (3)
-u <username> -p <password> (4)
1 | Replace <path_to_client> with the file path to the GSQL client. |
2 | If you have the SSL certificate of the remote server, you can replace <path_to_certificate> with the path to your SSL certificate (most common).
Otherwise, you can use --ssl instead to use the default certificate. Note that --ssl will be overridden by --cacert option.
If the remote server doesn’t have SSL/TLS encryption enabled, you can omit these flags. |
3 | Replace <ip_address> with the IP address of your remote server.
You can also specify the IP address in a file and omit this flag. |
4 | Replace <username> and <password> with the username and password of the TigerGraph user you want to be logged in as.
If you don’t provide a <username> , the client uses the default user tigergraph . |
Obtain SSL certificate from remote server
To obtain the SSL certificate from the remote server, you can copy it from the path: $(gadmin config get System.DataRoot)/configs/nginx/conf/ssl.cert
.
Specify server IP address in file
You can 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.
When there is a gsql_server_up_config
file in the same directory where you run the GSQL client, the GSQL client uses IP address stored in the file.
You won’t need to specify the IP address in the command.
Connect to TigerGraph Cloud instance
Since TigerGraph Cloud uses a different authentication scheme from TigerGraph Server, the steps for using the GSQL client for a cloud solution are slightly different.
Obtain SSL certificate
Run the following command, replacing <domain>
with the domain of your Cloud solution and replace <path_to_certificate>
with the local path to place the certificate file.
Find the domain of a Cloud solution by clicking on it in the solution view under "My Solutions."
You need to install openssl
on your client machine to run this command.
echo | openssl s_client -connect <domain>:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > <path_to_certificate>
Generate a secret
Use Admin Portal to generate a secret for your user account: User Management
Connect to the cloud instance
Modify and run this command to connect to the TigerGraph Cloud instance:
java -jar <path_to_client> \ (1)
--cacert <path_to_certificate> \ (2)
--ip <domain>:443 \ (3)
-u __GSQL__secret -p <secret> (4)
1 | Replace <path_to_client> with the file path to the GSQL client. |
2 | Replace <path_to_certificate> with the file path to the local SSL certificate that you downloaded. |
3 | Replace <domain> with the domain of your Cloud solution. |
4 | Replace <secret> with the generated secret from the Admin Portal. |
Filepath 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.
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 GSQL commands use absolute paths only when run remotely. |
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 the following:
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 ofgsql
, 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 folders, one for each example, which 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. For example,/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 soft links 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)'