Build Graph Server Container (23.4)

Ryota Yamanaka
6 min readNov 13, 2023

(The procedure below was tested with Graph Server 23.4.0 and Oracle Database 23.3.0.)

In a previous article, I explained how to run Oracle Database 23c Free on a container and use it as a graph database. There are various ways to use it in this environment alone, such as converting table data to graphs, creating views, and even combining it with JSON.

However, in this article, I will explain how to add a Graph Server container. Graph Server efficiently deploys graphs in memory, which accelerates graph traversal operations and graph algorithms.

In the following architecture diagram, it is assumed that the Database container has already been created, and we will now add a Graph Server container.

Prepare Docker/Podman

Graph Server is supported on RedHat Linux 7/8 and Oracle Linux 7/8.

This article assumes that the container host is also a RedHat-based Linux, whose default container management is Podman. So we will build the Graph Server on an Oracle Linux 8 container managed with Podman.

Installing the “podman-docker” package along with “podman” allows you to use the docker command as an alias for the podman command. Here, we will use this package and denote sample scripts using docker.

sudo yum update
sudo yum install -y podman podman-docker

This article is intended for those who want to quickly try out Graph Server. Please contact Oracle directly regarding the support of each container environment for production use.

Prepare Database 23c

In this case, we will use Database 23c. The steps to launch a container for Database 23c are written in the following article. Since Docker and Podman use the commands in a similar manner, please interpret them accordingly.

To use the Graph Server, database users need extra permissions. Here, we will grant the “graph_developer” role and an additional privilege (to publish graphs) to “graphuser”.

docker exec -it database-23c sqlplus sys/password123@freepdb1 as sysdba
GRANT graph_developer TO graphuser;
GRANT pgx_session_add_published_graph TO graphuser;

Download packages

Download the RPM package that contains Graph Server from this site. When you select the packages below, you will be asked to agree to the license and log in with your Oracle account.

Select “Oracle Graph Server” and proceed to download it.

Oracle Download Manager will appear and begin the download.

In addition, download JDK 11 (Linux x64 RPM Package) from this site. There is no license fee for personal or development use.

Build an image

Place these RPM packages and the Dockerfile below in the same directory.

  • oracle-graph-23.4.0.x86_64.rpm
  • jdk-11.0.21_linux-x64_bin.rpm
vi Dockerfile

This is a sample Dockerfile.

FROM oraclelinux:8

ARG VERSION_JDK
ARG VERSION_OPG
ARG JDBC_URL

COPY ./jdk-${VERSION_JDK}_linux-x64_bin.rpm /tmp
COPY ./oracle-graph-${VERSION_OPG}.x86_64.rpm /tmp

RUN yum install -y unzip numactl gcc libgfortran python3.8 \
&& yum clean all \
&& rm -rf /var/cache/yum/* \
&& rpm -ivh /tmp/jdk-${VERSION_JDK}_linux-x64_bin.rpm \
&& rpm -ivh /tmp/oracle-graph-${VERSION_OPG}.x86_64.rpm \
&& rm -f /usr/bin/python3 /usr/bin/pip3 \
&& ln /usr/bin/python3.8 /usr/bin/python3 \
&& ln /usr/bin/pip3.8 /usr/bin/pip3 \
&& pip3 install oracle-graph-client==23.4.0

ENV JAVA_HOME=/usr/lib/jvm/jdk-11-oracle-x64
ENV PATH=$PATH:/opt/oracle/graph/bin
ENV SSL_CERT_FILE=/etc/oracle/graph/ca_certificate.pem
ENV PGX_SERVER_KEYSTORE_PASSWORD=changeit

RUN keytool -importkeystore \
-srckeystore /etc/oracle/graph/server_keystore.jks \
-destkeystore $JAVA_HOME/lib/security/cacerts \
-deststorepass changeit \
-srcstorepass changeit \
-noprompt

RUN sed -i "s|<REPLACE-WITH-DATABASE-URL-TO-USE-FOR-AUTHENTICATION>|${JDBC_URL}|" /etc/oracle/graph/pgx.conf

EXPOSE 7007

WORKDIR /opt/oracle/graph/bin

CMD ["sh", "/opt/oracle/graph/pgx/bin/start-server"]

Build the image, replacing the JDK version <version_of_JDK> with the proper version number, such as 11.0.21. Also, host.containers.internal refers to the container’s host in Podman (or host.docker.internal if using Docker).

docker build . \
-f Dockerfile \
--tag graph-server:23.4.0 \
--build-arg VERSION_OPG=23.4.0 \
--build-arg VERSION_JDK=11.0.21 \
--build-arg JDBC_URL=jdbc:oracle:thin:@host.containers.internal:1521/freepdb1

Create a container

Once the image is built, create a container.

docker run \
--name graph-server \
--publish 7007:7007 \
--env JAVA_TOOL_OPTIONS="-Xms1G -Xmx2G" \
--detach \
graph-server:23.4.0

Launch a Python shell.

docker exec -it graph-server python3

Log in to the Graph Server with the database user “graphuser”.

from opg4py import graph_server
from pypgx import setloglevel
setloglevel("ROOT", "WARN")
base_url = "https://localhost:7007"
username = "graphuser"
password = "********"
instance = graph_server.get_instance(base_url, username, password)
session = instance.create_session("test")

Load an existing graph (BANK_GRAPH) into the Graph Server

graph = session.read_graph_by_name('BANK_GRAPH', 'pg_sql')
print(graph)
PgxGraph(name: BANK_GRAPH, v: 360, e: 6230, directed: True, memory(Mb): 0)

Execute a query on the in-memory graph on the Graph Server.

session.query_pgql("""
SELECT * FROM GRAPH_TABLE (bank_graph
MATCH (c IS customer)-[e IS owns]->(a IS account)
WHERE c.cst_id = 10
COLUMNS (c.cst_id, c.first_name, a.acc_id)
)
""").print()
+------------------------------+
| cst_id | first_name | acc_id |
+------------------------------+
| 10.0 | Laura | 10.0 |
| 10.0 | Laura | 90.0 |
+------------------------------+

Publish the graph to make the graph accessible from different sessions (such as a visualization application in the following section).

graph.publish()

Log in to Graph Visualization UI

Log in to Graph Visualization from your web browser.

You will see a security warning because of the self-signed certificate. So you have to proceed with:

  • Chrome: Advanced > Proceed to <ip-address> (unsafe)
  • Firefox: Advanced > Accept the risk and continue

Log in as the database user you created before.

Visualize query results

Once logged in, select the ‘Graph Server’ tab and execute the same query as before.

SELECT * FROM GRAPH_TABLE (bank_graph
MATCH (c IS customer)-[e IS owns]->(a IS account)
WHERE c.cst_id = 10
COLUMNS (c.cst_id, c.first_name, a.acc_id)
)

The results will be displayed as a graph, though only nodes will be shown this time. If you upload the design setting file, settings.json (right-click to save), colors and icons will be set.

Switching to ‘Table mode’ will display the query results in a table format.

By returning any properties of edges, the edges are visualized too.

SELECT * FROM GRAPH_TABLE (bank_graph
MATCH (c IS customer)-[e IS owns]->(a IS account)
WHERE c.cst_id = 10
COLUMNS (c.cst_id, e.cst_id AS e, a.acc_id)
)

We successfully created a Graph Server container. Let’s use this environment to discuss various use cases for graph databases!

Please learn more about Oracle Graph from:

--

--