Database data sources

更新时间:
复制 MD 格式

Performance Testing Service (PTS) connects to your database through Java Database Connectivity (JDBC), runs a SQL query, and maps the returned columns to named parameters. Virtual users consume these parameters during stress testing, so each request carries production-like data instead of static values.

PTS supports the following ApsaraDB RDS database types:

  • ApsaraDB RDS for MySQL

  • ApsaraDB RDS for PostgreSQL

  • ApsaraDB RDS for MariaDB

  • ApsaraDB RDS for SQL Server

JDBC URL format

The JDBC URL specifies the location of your database. The format varies by database type:

Database typeJDBC URL formatExample
MySQLjdbc:mysql://<host>:<port>/<database>jdbc:mysql://rm-bp1xxxxx.mysql.rds.aliyuncs.com:3306/testdb
PostgreSQLjdbc:postgresql://<host>:<port>/<database>jdbc:postgresql://rm-bp1xxxxx.pg.rds.aliyuncs.com:5432/testdb
MariaDBjdbc:mariadb://<host>:<port>/<database>jdbc:mariadb://rm-bp1xxxxx.mariadb.rds.aliyuncs.com:3306/testdb
SQL Serverjdbc:sqlserver://<host>:<port>;databaseName=<database>jdbc:sqlserver://rm-bp1xxxxx.sqlserver.rds.aliyuncs.com:1433;databaseName=testdb
PlaceholderDescriptionExample
<host>The endpoint of your ApsaraDB RDS instancerm-bp1xxxxx.mysql.rds.aliyuncs.com
<port>The port number of your RDS instance3306
<database>The name of the database to connect totestdb

Create a database data source parameter

Before you begin, make sure that:

  • Your ApsaraDB RDS instance is running

  • You have a database account with read permissions on the target tables

  • You have the JDBC URL, username, and password for your database

To create a database data source parameter, perform the following steps:

  1. Log on to the PTS console. In the left-side navigation pane, choose Performance Test > Create Scenario, and then click PTS.

  2. Click Data Sources. On the Databases tab, click + Add Data Source. Configure the database connection:

    SettingDescription
    Database typeThe type of your ApsaraDB RDS database. Select MySQL, PostgreSQL, MariaDB, or SQL Server.
    Database URLThe JDBC URL of your database. See the JDBC URL format section for the correct syntax.
    UsernameThe username of the database account.
    PasswordThe password of the database account.
    Query statementA SQL statement that starts with Select. This query retrieves the test data that PTS injects into your scenario parameters. Example: Select user_id, email FROM users LIMIT 10000.
  3. Click Add Parameter. Configure the parameter mapping, and then click Save: To map multiple columns, repeat this step for each column you need.

    SettingDescription
    Parameter nameA name for the parameter. Use this name to reference the parameter in your stress testing scenario.
    Column indexThe column position in the SQL result set to map to this parameter.
    Data sourceThe database data source you configured in the previous step.

Write efficient queries

Select only the columns your test needs. Avoid Select * queries, which return unnecessary data and slow down the preparation phase.

  • Add a LIMIT clause to control the result set size. Example: Select user_id, email FROM users LIMIT 10000.

  • Use WHERE clauses to filter for relevant test data instead of returning the entire table.

The full result set loads during the preparation phase before stress testing starts. Large result sets slow down this phase and increase memory usage. Return only the columns and rows your test scenarios require.

Secure database access

  • Use a dedicated database account with read-only permissions. Do not use an admin or root account.

  • Restrict the account to only the tables required for testing.

Limits

  • SQL statements must start with Select. PTS does not support INSERT, UPDATE, DELETE, or other write operations.

  • The full result set loads into memory before the stress test starts. Larger result sets increase preparation time and memory usage.