All Products
Search
Document Center

PolarDB:Graph applications

Last Updated:Jun 21, 2026

Traditional SQL is cumbersome and inefficient for modeling and querying data with complex relationships, such as those in social networks, fraud detection, and knowledge graphs. 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 to efficiently store, query, and analyze graph data for scenarios involving complex relationships.

Compatibility

The following PolarDB for PostgreSQL versions are compatible:

  • 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 of a cluster in the console or run the SHOW polardb_version; statement. If your cluster does not meet the requirements, 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 the application in one of the following two ways:

    • Go to the PolarDB console, click PolarDB AI in the left-side navigation pane, and then click Create AI Application.

    • Go to the PolarDB console. In the left-side navigation pane, click Clusters. Find the target cluster that meets the requirements and go to the cluster details page. In the left-side navigation pane, click AI Capability > AI Application, and then click Create AI Application.

  2. On the application purchase page, select the appropriate configurations based on your requirements:

    Parameter

    Description

    Billing Method

    • subscription: A prepaid billing method where you pay for resources for a fixed period. This method is suitable for long-term, stable business scenarios. Longer subscriptions offer greater discounts.

    • pay-as-you-go: A postpaid billing method that bills you based on your actual usage. This method is ideal for scenarios with flexible resource requirements.

    Database Engine

    Fixed to Apsara PolarDB.

    Region

    Select the geographic location for the application.

    Note
    • The region cannot be changed after the application is purchased.

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

    • For optimal performance, create the application in the same region as the ECS instance it will connect to. Otherwise, they must communicate over the slower public network instead of the private network.

    Architecture

    Select AI Application.

    Ecosystem

    The system automatically populates this field with the database ecosystem of the source PolarDB cluster. You do not need to configure it.

    Source PolarDB Cluster

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

    Edition

    The system automatically populates this field with the database version of the source PolarDB cluster. You do not need to configure it.

    AI Application

    Select Graph Management.

    Component Set

    Customize the number and specifications of the Backend Components based on your business requirements.

    AI Application Name

    Enter a custom name for the application.

    Note

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

    Network Type

    Fixed to VPC.

    VPC

    The system automatically populates this field with the VPC of the source PolarDB cluster. You do not need to configure it.

    Zone and vSwitch

    For optimal network performance, select a vSwitch in the same primary zone as the PolarDB for PostgreSQL cluster.

    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.

    Subscription Duration

    Select the subscription duration for the application.

    Note

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

    Auto-renewal

    Specifies whether to enable auto-renewal. To prevent service interruptions caused by an overdue payment, we recommend that you enable this feature.

    Note

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

  3. After purchasing, return to the AI Applications page of the cluster to view your new application.

    Note

    Application creation takes 3 to 5 minutes.

Step 2: Connect to the graph application

  • Configure the application whitelist: On the AI Applications list page, click the Application ID of your application to go to the application details page. On the Whitelist tab, 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, go to the Instance Details page of the ECS instance to view its IP address and add the IP address 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 the CIDR block of its VPC.

      • 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 to which the ECS instance belongs.

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

  • Get the endpoint: On the AI Applications list page, click the Application ID of your application to go to the application details page. On the Basic Information tab, view the Private Endpoint in the Topology section.

    Note
    • A public endpoint must be requested separately. Click the Apply button to apply for one.

    • The public endpoint provides only an IP address and port, not a domain name. If you require a domain name, you must bind it yourself.

Step 3: Create extension and set up database

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

    Note

    The age extension cannot be created manually. To use this feature, submit a ticket.

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

    Note

    You may encounter compatibility issues when you use the Data Management Service (DMS) client to set search_path. You can use PolarDB-Tools to execute the statements.

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

    To simplify the workflow, permanently load the extension by setting the database parameters as a privileged account. This avoids running the SET command for each new 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 only has read and write permissions, you must also grant them the CREATE permission to create tables.

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

Step 4: Create a graph and insert data

  1. 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 dataset contains six nodes (three with the Movie label and three with the Person label) and three edges (two with the ACTED_IN label and one with the DIRECTED label). The relationship graph is shown in the following figure:

    image

Step 5: Develop the application

  1. Develop the application: You can access the application directly over the public network. On the AI Applications list page, click Develop Application to go to the public URL of the visualization tool. Alternatively, enter the application's public IP address and port in your browser.

    Note

    Before you proceed, make sure you have added your public IP address to the application whitelist.

  2. On the login page of the visualization tool, enter the following information:

    • Host: Select the endpoint of your PolarDB cluster.

    • Database Name: Enter the name of 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 that the account has the required access permissions on the database.

    • Password: Enter the password for the database account.

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

    • MATCH is used for pattern matching to find content that matches a specified pattern.

    • The RETURN keyword specifies the values or results to return from a 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);

    After you enter the query, click the Run button in the upper-right corner of the editor. If the query is successful, the results area below shows the following: Node Label displays *(6), Movie(3), Person(3); Edge Label displays *(3), ACTED_IN(2), DIRECTED(1); and Properties is empty. In the right-side panel, the Current Graph drop-down list is set to moviedb.

  4. Verification: After the operation is successful, you can see three Person nodes from moviedb in the visualization area below. After you execute the query, the results are displayed graphically in the Graph view. The returned Person nodes, such as Tom Hanks and Keanu Reeves, are displayed as circular nodes.

Step 6: (Optional) Release the graph application

To save costs, release the visualization tool when you no longer need it. In the AI Applications list, find the target graph application, and in the Actions column, click Release Application.

Important

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

How it works

  • Core engine: The PolarDB graph database feature is built 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 data types can be queried separately.

  • Query execution: You do not execute Cypher queries directly. Instead, you pass them as a string parameter 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: A query usually returns result columns of type agtype. This is a custom data type similar to JSONB that encapsulates structured information about graph elements, such as nodes, edges, and paths. In an application, you can typically handle it as a JSON string.

Billing

  • Component fees: You are billed for the backend components of a graph application based on the component specifications (CPU and memory) and the subscription duration you select.

    Pricing Information per Component

    Chinese mainland

    Specification

    CPU and memory

    Subscription (USD/month)

    Pay-as-you-go (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 cores 4 GB

    37.59

    0.0753

    polar.app.g4.medium
    2 cores 8 GB

    40.60

    0.0810

    polar.app.g2.large
    4 cores 8 GB

    71.43

    0.1433

    polar.app.g4.large
    4 cores 16 GB

    94.74

    0.1896

    polar.app.g2.xlarge
    8 cores 16 GB

    150.38

    0.3010

    polar.app.g4.xlarge
    8 cores 32 GB

    186.47

    0.3734

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

    300.75

    0.6035

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

    360.90

    0.7236

    China (Hong Kong)

    Node specification

    CPU and memory

    Subscription (USD/mo)

    Pay-as-you-go (USD/hr)

    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 cores 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 cores 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 cores 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 cores 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 cores 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 cores 32 GB

    298.35

    0.5977

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

    481.20

    0.9653

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

    577.44

    1.1577

    Japan (Tokyo)

    Node specification

    CPU and memory

    Subscription (USD/mo)

    Pay-as-you-go (USD/hr)

    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 cores 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 cores 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 cores 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 cores 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 cores 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 cores 32 GB

    298.35

    0.5977

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

    481.20

    0.9653

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

    577.44

    1.1577

    Korea (Seoul)

    Node specification

    CPU and memory

    Subscription (USD/mo)

    Pay-as-you-go (USD/hr)

    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 cores 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 cores 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 cores 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 cores 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 cores 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 cores 32 GB

    298.35

    0.5977

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

    481.20

    0.9653

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

    577.44

    1.1577

    Singapore

    Node specification

    CPU and memory

    Subscription (USD/mo)

    Pay-as-you-go (USD/hr)

    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 cores 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 cores 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 cores 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 cores 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 cores 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 cores 32 GB

    298.35

    0.5977

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

    481.20

    0.9653

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

    577.44

    1.1577

    Malaysia (Kuala Lumpur)

    Node specification

    CPU and memory

    Subscription (USD/mo)

    Pay-as-you-go (USD/hr)

    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 cores 4 GB

    60.15

    0.1204

    polar.app.g4.medium
    2 cores 8 GB

    64.96

    0.1297

    polar.app.g2.large
    4 cores 8 GB

    114.29

    0.2292

    polar.app.g4.large
    4 cores 16 GB

    151.58

    0.3033

    polar.app.g2.xlarge
    8 cores 16 GB

    240.60

    0.4819

    polar.app.g4.xlarge
    8 cores 32 GB

    298.35

    0.5977

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

    481.20

    0.9653

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

    577.44

    1.1577

    Indonesia (Jakarta)

    Specification

    CPU and memory

    Subscription (USD/month)

    Pay-as-you-go (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 cores 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2 cores 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4 cores 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4 cores 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8 cores 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8 cores 32 GB

    261.05

    0.5224

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

    421.05

    0.8452

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

    505.26

    1.0130

    Philippines (Manila)

    Specification

    CPU and memory

    Subscription (USD/month)

    Pay-as-you-go (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 cores 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2 cores 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4 cores 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4 cores 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8 cores 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8 cores 32 GB

    261.05

    0.5224

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

    421.05

    0.8452

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

    505.26

    1.0130

    Thailand (Bangkok)

    Specification

    CPU and memory

    Subscription (USD/month)

    Pay-as-you-go (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 cores 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2 cores 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4 cores 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4 cores 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8 cores 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8 cores 32 GB

    261.05

    0.5224

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

    421.05

    0.8452

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

    505.26

    1.0130

    Germany (Frankfurt)

    Specification

    CPU and memory

    Subscription (USD/month)

    Pay-as-you-go (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 cores 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2 cores 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4 cores 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4 cores 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8 cores 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8 cores 32 GB

    261.05

    0.5224

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

    421.05

    0.8452

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

    505.26

    1.0130

    UK (London)

    Specification

    CPU and memory

    Subscription (USD/month)

    Pay-as-you-go (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 cores 4 GB

    52.63

    0.1054

    polar.app.g4.medium
    2 cores 8 GB

    56.84

    0.1135

    polar.app.g2.large
    4 cores 8 GB

    100.00

    0.2006

    polar.app.g4.large
    4 cores 16 GB

    132.63

    0.2654

    polar.app.g2.xlarge
    8 cores 16 GB

    210.53

    0.4211

    polar.app.g4.xlarge
    8 cores 32 GB

    261.05

    0.5224

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

    421.05

    0.8452

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

    505.26

    1.0130

    US (Silicon Valley)

    Node type

    CPU and memory

    Subscription (USD/month)

    Pay-as-you-go (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 cores 4 GB

    45.11

    0.0903

    polar.app.g4.medium
    2 cores 8 GB

    48.72

    0.0973

    polar.app.g2.large
    4 cores 8 GB

    85.71

    0.1719

    polar.app.g4.large
    4 cores 16 GB

    113.68

    0.2275

    polar.app.g2.xlarge
    8 cores 16 GB

    180.45

    0.3618

    polar.app.g4.xlarge
    8 cores 32 GB

    223.76

    0.4486

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

    360.90

    0.7236

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

    433.08

    0.8683

    US (Virginia)

    Node type

    CPU and memory

    Subscription (USD/month)

    Pay-as-you-go (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 cores 4 GB

    45.11

    0.0903

    polar.app.g4.medium
    2 cores 8 GB

    48.72

    0.0973

    polar.app.g2.large
    4 cores 8 GB

    85.71

    0.1719

    polar.app.g4.large
    4 cores 16 GB

    113.68

    0.2275

    polar.app.g2.xlarge
    8 cores 16 GB

    180.45

    0.3618

    polar.app.g4.xlarge
    8 cores 32 GB

    223.76

    0.4486

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

    360.90

    0.7236

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

    433.08

    0.8683

  • Storage fees: Data and files generated by graph applications are stored in your PolarDB for PostgreSQL cluster.

  • Traffic and bandwidth: Free.

Related documents