All Products
Search
Document Center

PolarDB:Graph applications

Last Updated:Mar 26, 2026

Modeling and querying data with complex relationships, such as in social networks, fraud detection, or knowledge graphs, is cumbersome and inefficient with traditional SQL. PolarDB for PostgreSQL integrates the open source graph engine Apache AGE. This integration lets you use both standard SQL and the industry-standard openCypher graph query language in the same cluster, enabling you to efficiently store, query, and analyze graph data for complex relationship scenarios.

Applicability

The following versions of PolarDB for PostgreSQL are supported:

  • PostgreSQL 16 (minor engine version 2.0.16.8.3.0 and later)

  • PostgreSQL 15 (minor engine version 2.0.15.12.4.0 and later)

  • PostgreSQL 14 (minor engine version 2.0.14.12.24.0 and later)

Note

You can view the minor engine version in the console or by running the SHOW polardb_version; statement. For more information, see View the minor engine version of a cluster. If your cluster does not meet the minor engine version requirements, you can upgrade the minor engine version.

Visualization tool

You can create a visual graph management tool, based on Apache AGE Viewer, in the console to interact with your graph data through a web interface.

Step 1: Create a graph application

  1. You can create it in one of two ways:

    • Go to the PolarDB console. In the navigation pane on the left, click PolarDB AI, and then click Create AI Application.image

    • Go to the PolarDB console. In the navigation pane on the left, click Clusters. Find the destination cluster that meets the applicability requirements and navigate to the cluster details page. In the navigation pane on the left, choose AI Capabilities > AI Applications, and then click Create AI Application.image

  2. On the application purchase page, select the appropriate configurations as needed:

    Configuration item

    Description

    Billing Method

    • Subscription: Pay upfront for a fixed duration. Longer subscriptions offer larger discounts. Best for stable, long-term workloads.

    • Pay-as-you-go: Billed by actual usage duration with no upfront payment. Best for flexible or short-term workloads.

    Engine

    Fixed to PolarDB.

    Region

    Select the geographic location where the application is located.

    Note
    • The region cannot be changed after purchase.

    • The application must be in the same region as your PolarDB for PostgreSQL cluster. Select the same region as the PolarDB for PostgreSQL cluster.

    • We recommend that you create the application in the same region as the ECS instance you want to connect to. Otherwise, they can only communicate over the public network, which may affect performance.

    Architecture

    Select AI Application.

    Ecosystem

    Automatically populated based on the source PolarDB cluster.

    Source PolarDB Cluster

    Select the PolarDB cluster for which you want to create the application.

    Version

    Automatically populated based on the source PolarDB cluster.

    AI Application

    Select Graph Management.

    Component Set

    Customize the number and specifications of Backend Components as needed.

    AI Application Name

    You can enter a custom application name.

    Note

    The name cannot start with http:// or https:// and must be 2 to 256 characters in length.

    Network Type

    Fixed to VPC.

    VPC

    Automatically populated based on the source PolarDB cluster.

    Zone and vSwitch

    Configure the vSwitch for the VPC. We recommend that you select a vSwitch in the same primary zone as the PolarDB for PostgreSQL cluster for optimal network performance.

    If the existing vSwitches do not meet your requirements, you can create a vSwitch.

    Security Group

    Configure the security group for the application.

    Quantity

    Select the number of applications to purchase.

    Note
    • You can purchase only one AI application of the same type for each PolarDB for PostgreSQL cluster.

    • This parameter is available only when Billing Method is set to Subscription.

    Duration

    Select the subscription duration for the application.

    Note

    This parameter is available only when Billing Method is set to Subscription.

    Auto-renewal

    We recommend enabling auto-renewal to prevent service interruptions.

    Note

    This parameter is available only when Billing Method is set to Subscription.

  3. After the purchase is complete, return to the AI Applications page of the cluster to view the new application.

    Note

    The application takes 3 to 5 minutes to create.

Step 2: Connect to the graph application

  • Configure the application whitelist: On the AI Applications list page, click your Application ID to navigate to the application details page. On the Whitelist tab, you can Add Whitelist, Select Security Groups, or Configure an existing whitelist group.

    Note
    • The application whitelist is independent of the cluster whitelist and must be configured separately.

    • If your ECS instance needs to access the application, you can view the IP address of the ECS instance on the ECS Instance Details page and add it to the IP whitelist.

      • If your ECS instance and the application are in the same VPC, you can add the private IP address of the ECS instance or its VPC CIDR block.

      • If your ECS instance and the application are not in the same VPC, you can add the public IP address of the ECS instance or the security group where the ECS instance is located.

    • If your on-premises server, computer, or other cloud server needs to access the application, add its public IP address to the IP whitelist.

    image

  • Obtain the endpoint: On the AI Applications list page, click your Application ID to navigate to the application details page. On the Basic Information tab, you can view the Private Endpoint in the Topology section.

    Note
    • You must request a public endpoint separately. Click the Request button to submit a request.

    • The public endpoint provides only an IP address and a port, not a domain name. If you need a domain name, you can bind one yourself.

    image

Step 3: Create the extension and configure the database

  1. Create the extension: Run the following statement using a privileged account.

    Note

    The age extension does not currently support manual creation. To use this feature, submit a ticket to request its creation.

    CREATE EXTENSION age;
  2. Configure the database: For each connection, you must add ag_catalog to the search_path to simplify queries and load the extension using the get_cypher_keywords function:

    Note

    When you use a Data Management Service (DMS) client to set the search_path, compatibility issues may occur. You can use PolarDB-Tools to run the relevant statements.

    SET search_path = ag_catalog, "$user", public;

    Use a privileged account to set the database parameters to permanently load the extension. This simplifies the process because you do not need to repeat the preceding operations for each connection.

    ALTER DATABASE <dbname> SET search_path = "$user", public, ag_catalog;
    ALTER DATABASE <dbname> SET session_preload_libraries TO 'age';
  3. (Optional) Allow regular users to use AGE: Grant the USAGE permission to regular users in the ag_catalog schema.

    GRANT USAGE ON SCHEMA ag_catalog TO <username>;

    If a regular user has only read and write permissions, you must also grant the CREATE permission to create tables.

    GRANT CREATE ON DATABASE <dbname> TO <username>;

Step 4: Create a graph and insert data

  1. Create a graph: You must create a graph before you can use it. To do this, use the create_graph function in the ag_catalog namespace.

    Syntax:

    SELECT create_graph('<graph_name>');

    Example:

    SELECT ag_catalog.create_graph('moviedb');
  2. Insert data: Use the following SQL statement to insert sample data into the moviedb graph:

    SELECT * FROM cypher('moviedb', $$
      CREATE (matrix:Movie {title: 'The Matrix', released: 1997})
      CREATE (cloudAtlas:Movie {title: 'Cloud Atlas', released: 2012})
      CREATE (forrestGump:Movie {title: 'Forrest Gump', released: 1994})
      CREATE (keanu:Person {name: 'Keanu Reeves', born: 1964})
      CREATE (robert:Person {name: 'Robert Zemeckis', born: 1951})
      CREATE (tom:Person {name: 'Tom Hanks', born: 1956})
      CREATE (tom)-[:ACTED_IN {roles: ['Forrest']}]->(forrestGump)
      CREATE (tom)-[:ACTED_IN {roles: ['Zachry']}]->(cloudAtlas)
      CREATE (robert)-[:DIRECTED]->(forrestGump)
    $$) AS (result1 agtype);

    This includes six nodes, three with the label Movie and three with the label Person. It also includes three edges, two with the label ACTED_IN and one with the label DIRECTED. The relationship graph is shown below:

    image

Step 5: Develop the application

  1. Develop the application: You can access the application directly over the Internet. On the AI Applications list page, click Develop Application to open the public endpoint of the graph application's visualization tool. Alternatively, you can enter the public IP address and port of the application in your browser's address bar to access the visualization tool.

    Note

    First, add your public IP address to the application whitelist.

    image

  2. On the visualization tool's logon page, enter the following information:

    • host: Select the endpoint of your PolarDB cluster.

    • Database Name: Enter a database within the cluster. If you do not have a suitable database, return to the cluster details page to create a database.

    • User name: Enter a database account within the cluster. Make sure it has the necessary access permissions for the database.

    • password: Enter the password for the database account.

    image

  3. Query data: In Cypher, use the MATCH and RETURN keywords to query data.

    • MATCH performs pattern matching to find content that matches the specified pattern.

    • The RETURN keyword specifies the values or results you want to return from the Cypher query.

    Syntax:

    SELECT * FROM cypher('graph_name', $$
      MATCH <patterns>RETURN <variables>
    $$) AS (result1 agtype);

    Example: Enter the following Cypher query statement at the top of the visualization tool:

    SELECT * FROM cypher('moviedb', $$
      MATCH (m:Person)
      RETURN m
    $$) AS (result1 agtype);

    image

  4. Verification: After the statement is successfully executed, the three Person nodes of the moviedb graph appear in the visualization area below.image

Step 6: (Optional) Release the graph application

When the visualization tool is no longer needed, you can release it to save costs. In the AI Applications list, find the destination graph application, and in the Actions column, click Release Application.

Important

Releasing a graph application only deletes the visualization tool that provides the web interface. It does not delete any graph data stored in your PolarDB cluster. After the application is released, its configurations, such as the public endpoint, are lost and cannot be recovered.

How it works

  • Core engine: The PolarDB graph database feature is implemented based on the PostgreSQL age extension, which is provided by the Apache AGE project and is compatible with the OpenCypher query syntax.

  • Hybrid query: The age extension lets you manage both relational data (standard tables) and graph data in the same database. These two types of data can coexist and be queried separately.

  • Query execution: Cypher queries are not executed directly. Instead, they are passed as string parameters to a PostgreSQL function named cypher(). PolarDB parses this string, executes the Cypher command in the specified graph, and returns the results as a standard SQL row set.

  • Data type: The result columns returned by a query are usually of the agtype type. This is a custom data type similar to JSONB that is used to encapsulate structured information of graph elements, such as nodes, edges, and paths. In an application, you can typically handle it as a JSON string.

Billing

  • Component fees: Graph applications are charged for backend components. The fees are calculated based on the component specifications (CPU and memory) and the subscription duration you select.

    Component pricing

    The Chinese mainland

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1-core 1 GB

    1.65

    0.0029

    polar.app.g2.small
    1-core 2 GB

    2.71

    0.0058

    polar.app.g2.medium
    2-core 4 GB

    37.59

    0.0753

    polar.app.g4.medium
    2-core 8 GB

    40.60

    0.0810

    polar.app.g2.large
    4-core 8 GB

    71.43

    0.1433

    polar.app.g4.large
    4-core 16 GB

    94.74

    0.1896

    polar.app.g2.xlarge
    8-core 16 GB

    150.38

    0.3010

    polar.app.g4.xlarge
    8-core 32 GB

    186.47

    0.3734

    polar.app.g2.2xlarge
    16-core 32 GB

    300.75

    0.6035

    polar.app.g4.2xlarge
    16-core 64 GB

    360.90

    0.7236

    China (Hong Kong)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1 core 1 GB

    2.65

    0.0046

    polar.app.g2.small
    1 core 2 GB

    4.33

    0.0093

    polar.app.g2.medium
    2 core 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 core 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 core 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 core 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 core 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 core 32 GB

    298.35

    0.5977

    polar.app.g2.2xlarge
    16 core 32 GB

    481.20

    0.9653

    polar.app.g4.2xlarge
    16 core 64 GB

    577.44

    1.1577

    Japan (Tokyo)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1 core 1 GB

    2.65

    0.0046

    polar.app.g2.small
    1 core 2 GB

    4.33

    0.0093

    polar.app.g2.medium
    2 core 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 core 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 core 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 core 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 core 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 core 32 GB

    298.35

    0.5977

    polar.app.g2.2xlarge
    16 core 32 GB

    481.20

    0.9653

    polar.app.g4.2xlarge
    16 core 64 GB

    577.44

    1.1577

    South Korea

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1 core 1 GB

    2.65

    0.0046

    polar.app.g2.small
    1 core 2 GB

    4.33

    0.0093

    polar.app.g2.medium
    2 core 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 core 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 core 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 core 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 core 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 core 32 GB

    298.35

    0.5977

    polar.app.g2.2xlarge
    16 core 32 GB

    481.20

    0.9653

    polar.app.g4.2xlarge
    16 core 64 GB

    577.44

    1.1577

    Singapore

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1 core 1 GB

    2.65

    0.0046

    polar.app.g2.small
    1 core 2 GB

    4.33

    0.0093

    polar.app.g2.medium
    2 core 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 core 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 core 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 core 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 core 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 core 32 GB

    298.35

    0.5977

    polar.app.g2.2xlarge
    16 core 32 GB

    481.20

    0.9653

    polar.app.g4.2xlarge
    16 core 64 GB

    577.44

    1.1577

    Malaysia (Kuala Lumpur)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1 core 1 GB

    2.65

    0.0046

    polar.app.g2.small
    1 core 2 GB

    4.33

    0.0093

    polar.app.g2.medium
    2 core 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 core 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 core 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 core 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 core 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 core 32 GB

    298.35

    0.5977

    polar.app.g2.2xlarge
    16 core 32 GB

    481.20

    0.9653

    polar.app.g4.2xlarge
    16 core 64 GB

    577.44

    1.1577

    Indonesia (Jakarta)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1-core 1 GB

    2.32

    0.0041

    polar.app.g2.small
    1-core 2 GB

    3.79

    0.0081

    polar.app.g2.medium
    2-core 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2-core 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4-core 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4-core 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8-core 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8-core 32 GB

    261.05

    0.5224

    polar.app.g2.2xlarge
    16-core 32 GB

    421.05

    0.8452

    polar.app.g4.2xlarge
    16-core 64 GB

    505.26

    1.0130

    Philippines

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1-core 1 GB

    2.32

    0.0041

    polar.app.g2.small
    1-core 2 GB

    3.79

    0.0081

    polar.app.g2.medium
    2-core 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2-core 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4-core 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4-core 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8-core 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8-core 32 GB

    261.05

    0.5224

    polar.app.g2.2xlarge
    16-core 32 GB

    421.05

    0.8452

    polar.app.g4.2xlarge
    16-core 64 GB

    505.26

    1.0130

    Thailand (Bangkok)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1-core 1 GB

    2.32

    0.0041

    polar.app.g2.small
    1-core 2 GB

    3.79

    0.0081

    polar.app.g2.medium
    2-core 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2-core 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4-core 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4-core 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8-core 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8-core 32 GB

    261.05

    0.5224

    polar.app.g2.2xlarge
    16-core 32 GB

    421.05

    0.8452

    polar.app.g4.2xlarge
    16-core 64 GB

    505.26

    1.0130

    Germany (Frankfurt)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1-core 1 GB

    2.32

    0.0041

    polar.app.g2.small
    1-core 2 GB

    3.79

    0.0081

    polar.app.g2.medium
    2-core 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2-core 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4-core 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4-core 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8-core 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8-core 32 GB

    261.05

    0.5224

    polar.app.g2.2xlarge
    16-core 32 GB

    421.05

    0.8452

    polar.app.g4.2xlarge
    16-core 64 GB

    505.26

    1.0130

    UK (London)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1-core 1 GB

    2.32

    0.0041

    polar.app.g2.small
    1-core 2 GB

    3.79

    0.0081

    polar.app.g2.medium
    2-core 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2-core 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4-core 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4-core 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8-core 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8-core 32 GB

    261.05

    0.5224

    polar.app.g2.2xlarge
    16-core 32 GB

    421.05

    0.8452

    polar.app.g4.2xlarge
    16-core 64 GB

    505.26

    1.0130

    US (Silicon Valley)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1-core 1 GB

    1.98

    0.0035

    polar.app.g2.small
    1-core 2 GB

    3.25

    0.0069

    polar.app.g2.medium
    2-core 4 GB

    45.11

    0.0903

    polar.app.g4.medium
    2-core 8 GB

    48.72

    0.0973

    polar.app.g2.large
    4-core 8 GB

    85.71

    0.1719

    polar.app.g4.large
    4-core 16 GB

    113.68

    0.2275

    polar.app.g2.xlarge
    8-core 16 GB

    180.45

    0.3618

    polar.app.g4.xlarge
    8-core 32 GB

    223.76

    0.4486

    polar.app.g2.2xlarge
    16-core 32 GB

    360.90

    0.7236

    polar.app.g4.2xlarge
    16-core 64 GB

    433.08

    0.8683

    US (Virginia)

    Node specification code

    CPU and memory

    Price (USD/month)

    Price (USD/hour)

    polar.app.g1.tiny
    1-core 1 GB

    1.98

    0.0035

    polar.app.g2.small
    1-core 2 GB

    3.25

    0.0069

    polar.app.g2.medium
    2-core 4 GB

    45.11

    0.0903

    polar.app.g4.medium
    2-core 8 GB

    48.72

    0.0973

    polar.app.g2.large
    4-core 8 GB

    85.71

    0.1719

    polar.app.g4.large
    4-core 16 GB

    113.68

    0.2275

    polar.app.g2.xlarge
    8-core 16 GB

    180.45

    0.3618

    polar.app.g4.xlarge
    8-core 32 GB

    223.76

    0.4486

    polar.app.g2.2xlarge
    16-core 32 GB

    360.90

    0.7236

    polar.app.g4.2xlarge
    16-core 64 GB

    433.08

    0.8683

  • Storage fees: Data and files generated by graph applications are stored in the storage space of the PolarDB for PostgreSQL cluster.

  • Traffic and bandwidth: No fees are charged.

References