A unified database client tool for accessing various databases in KubeBlocks and other environments. DBClient provides a comprehensive command-line interface named DBClient that supports basic operations and advanced testing capabilities including connection stress tests, benchmarks, and query execution.
- 30+ Database Support: Supports a wide range of databases including MySQL, PostgreSQL, Oracle, MongoDB, Redis, Kafka, Elasticsearch, ClickHouse, and many more
- Multiple Test Types: Query execution, connection stress testing, benchmarking, and execution loops
- Flexible Network Access: Works with ClusterIP, NodePort, LoadBalancer, and headless services in Kubernetes
- Unified Interface: Single command-line tool for all supported databases
- Advanced Testing: Connection pool stress tests, concurrent query execution, and performance benchmarking
- MySQL (including MySQL 5.1)
- PostgreSQL
- Oracle
- SQL Server
- MariaDB
- TiDB
- OceanBase
- GaussDB
- MogDB
- OpenGauss
- KingBase
- Dameng (DM)
- Vastbase
- GBase 8c
- YashanDB
- PolarDB-X
- FoxLake
- GreatSQL
- GreatDB
- MongoDB
- Redis (including Sentinel mode)
- Cassandra
- HBase
- Elasticsearch (v7, v8)
- OpenSearch
- Solr
- InfluxDB
- TDengine
- VictoriaMetrics
- VictoriaLogs
- Loki
- Kafka
- RabbitMQ
- RocketMQ
- Pulsar
- Milvus
- Qdrant
- Nebula
- MinIO
- ZooKeeper
- Etcd
- ClickHouse
- Doris
- StarRocks
- SelectDB
- GreptimeDB
- Hadoop
- Hive
- Vault
# Clone the repository
git clone <repository-url>
cd DBClient
# Build the project
gradle build
# The built JAR file will be available at:
./build/libs/dbclient-1.0-all.jar- Java 11 or higher
- Gradle 8.x or higher
java -jar ./build/libs/dbclient-1.0-all.jar [OPTIONS]| Parameter | Short | Description | Example |
|---|---|---|---|
--host |
-h |
Database host | 127.0.0.1 |
--user |
-u |
Database username | postgres |
--password |
-p |
Database password | mypassword |
--port |
-P |
Database port | 5432 |
--database |
-d |
Database name | mydb |
--dbtype |
-e |
Database type | postgresql |
| Parameter | Short | Description | Default |
|---|---|---|---|
--test |
-t |
Test type (query/connectionstress/benchmark/executionloop) | - |
--query |
-q |
SQL query to execute | - |
--table |
-tb |
Table name | - |
--connections |
-c |
Number of connections | 100 |
--duration |
-s |
Test duration in seconds | 60 |
--interval |
-I |
Statistics report interval (seconds) | 1 |
--iterations |
-i |
Number of iterations for benchmark | - |
--concurrency |
-m |
Concurrency level | 10 |
--accessmode |
-a |
Access mode | mysql |
--org |
-o |
Organization name | - |
--master |
-M |
Redis sentinel master | - |
--sentinelPassword |
-S |
Redis sentinel password | - |
--key |
-k |
Key (for Redis, etc.) | - |
--topic |
-T |
Topic (for Kafka, etc.) | - |
--bucket |
-B |
Bucket (for MinIO, InfluxDB, etc.) | - |
--cluster |
-C |
Cluster name | - |
Execute a query on PostgreSQL:
java -jar ./build/libs/dbclient-1.0-all.jar \
--host=127.0.0.1 \
--user=postgres \
--database=postgres \
--password=mysecretpassword \
--test=query \
--query="SELECT * FROM pg_user LIMIT 1" \
--port=5432 \
--dbtype=postgresqlExample Output:
SLF4J(I): Connected with provider of type [ch.qos.logback.classic.spi.LogbackServiceProvider]
Test Result:
usename usesysid usecreatedb usesuper userepl usebypassrls passwd valuntil useconfig
postgres 10 t t t t ******** null null
Connection Information:
Database Type: postgresql
Host: 127.0.0.1
Port: 5432
Database: postgres
Table: user
User: postgres
Test Type: query
Query: SELECT * FROM pg_user LIMIT 1
Test maximum connections with PostgreSQL:
java -jar ./build/libs/dbclient-1.0-all.jar \
--host=127.0.0.1 \
--user=postgres \
--database=postgres \
--password=mysecretpassword \
--test=connectionstress \
--connections=10 \
--port=5432 \
--dbtype=postgresqlExample Output:
SLF4J(I): Connected with provider of type [ch.qos.logback.classic.spi.LogbackServiceProvider]
Test Result:
null
Connection Information:
Database Type: postgresql
Host: 127.0.0.1
Port: 5432
Database: postgres
Table: user
User: postgres
Test Type: connectionstress
Connection Count: 10
Duration: 60 seconds
Or using Gradle:
gradle runDBClient --args="--password='mysecretpassword' --port=5432 --database=postgres --user=postgres --dbtype=postgresql --test=connectionstress --connections=10"Execute benchmark with concurrent queries:
java -jar ./build/libs/dbclient-1.0-all.jar \
--host=127.0.0.1 \
--user=postgres \
--database=postgres \
--password=mysecretpassword \
--test=benchmark \
--query="SELECT * FROM users WHERE id = 1" \
--iterations=1000 \
--concurrency=10 \
--port=5432 \
--dbtype=postgresqlExample Output:
SLF4J(I): Connected with provider of type [ch.qos.logback.classic.spi.LogbackServiceProvider]
Test Result:
Benchmark completed with 1000 iterations and 10 concurrency
Connection Information:
Database Type: postgresql
Host: 127.0.0.1
Port: 5432
Database: postgres
Table: user
User: postgres
Test Type: benchmark
Iterations: 1000
Concurrency: 10
Query: SELECT * FROM users WHERE id = 1
java -jar ./build/libs/dbclient-1.0-all.jar \
--host=127.0.0.1 \
--user=root \
--database=testdb \
--password=mysqlpassword \
--test=query \
--query="SHOW DATABASES" \
--port=3306 \
--dbtype=mysqljava -jar ./build/libs/dbclient-1.0-all.jar \
--host=127.0.0.1 \
--user=admin \
--database=testdb \
--password=mongopassword \
--test=query \
--query="db.collection.find()" \
--port=27017 \
--dbtype=mongodbjava -jar ./build/libs/dbclient-1.0-all.jar \
--host=127.0.0.1 \
--password=redispassword \
--test=query \
--query="GET mykey" \
--port=6379 \
--dbtype=redisContinuously execute queries with specified duration and interval:
java -jar ./build/libs/dbclient-1.0-all.jar \
--host=127.0.0.1 \
--user=postgres \
--database=postgres \
--password=mysecretpassword \
--test=executionloop \
--query="SELECT COUNT(*) FROM users" \
--duration=300 \
--interval=10 \
--port=5432 \
--dbtype=postgresqlDeploy DBClient as a Kubernetes Pod:
apiVersion: v1
kind: Pod
metadata:
generateName: test-dbclient-
namespace: default
spec:
containers:
- name: test-dbclient
imagePullPolicy: IfNotPresent
image: docker.io/apecloud/dbclient:latest
args:
- "--host"
- "127.0.0.1"
- "--user"
- "postgres"
- "--database"
- "postgres"
- "--port"
- "5432"
- "--password"
- "mysecretpassword"
- "--test"
- "query"
- "--query"
- "SELECT * FROM pg_user LIMIT 1"
- "--dbtype"
- "postgresql"
restartPolicy: NeverApply the configuration:
kubectl apply -f dbclient-pod.yamlBuild and run using Docker:
# Build the Docker image
docker build -t apecloud/dbclient:latest .
# Run the container
docker run --rm apecloud/dbclient:latest \
--host=127.0.0.1 \
--user=postgres \
--database=postgres \
--password=mysecretpassword \
--test=query \
--query="SELECT * FROM pg_user LIMIT 1" \
--port=5432 \
--dbtype=postgresqlExecute a single query and return the results.
Test the database's ability to handle multiple concurrent connections.
- Parameters:
--connections,--duration
Measure query performance under concurrent load.
- Parameters:
--iterations,--concurrency,--query
Continuously execute queries for a specified duration with configurable intervals.
- Parameters:
--duration,--interval,--query
Use these values for the --dbtype parameter:
- MySQL Family:
mysql,mysql 5.1,tidb,mariadb,polardbx,foxlake,greatsql,greatdb,greptime,doris,selectdb,starrocks,sr - PostgreSQL Family:
postgresql,pg,postgres,opentenbase - Oracle:
oracle - SQL Server:
sqlserver,mssql - MongoDB:
mongodb,mongo - Redis:
redis,sentinelredis - Elasticsearch:
elasticsearch,elasticsearch7,elasticsearch8,es,elastic - OpenSearch:
opensearch - ClickHouse:
clickhouse,ck - Dameng:
dameng,dm,dmdb,damengdb - InfluxDB:
influxdb,influx - TDengine:
tdengine,td,taos - VictoriaMetrics:
victoriametrics,vm,victoria-metrics - VictoriaLogs:
victorialogs,victoria-logs - Kafka:
kafka - RabbitMQ:
rabbitmq - RocketMQ:
rocketmq - Pulsar:
pulsar - ZooKeeper:
zookeeper,zk - Etcd:
etcd - MinIO:
minio - Milvus:
milvus - Qdrant:
qdrant - Nebula:
nebula - GaussDB:
gaussdb - OpenGauss:
opengauss - MogDB:
mogdb - KingBase:
kingbase - Vastbase:
vastbase - GBase8c:
gbase8c,gbase - Hadoop:
hadoop - Hive:
hive - Loki:
loki - Vault:
vault
When your applications run in the same Kubernetes cluster as KubeBlocks:
- Use ClusterIP for internal access
- Use headless services for direct pod access
- Use service DNS names for discovery
When accessing databases from different clusters or external environments:
- Use NodePort for simple external access
- Use LoadBalancer for production-grade access
- Configure proper firewall rules and security groups
-
Connection Refused
- Verify the database is running
- Check host and port settings
- Ensure network connectivity
-
Authentication Failed
- Verify username and password
- Check user permissions
- For Redis Sentinel, ensure correct master name and password
-
Driver Not Found
- Ensure all dependencies are included in the JAR
- Check if the database type is supported
-
Query Timeout
- Increase timeout settings if applicable
- Optimize query performance
- Check database load
DBClient/
├── src/main/java/
│ ├── DBClient.java # Main entry point
│ └── com/apecloud/dbtester/
│ ├── commons/ # Common utilities and interfaces
│ │ ├── DBConfig.java
│ │ ├── DatabaseTester.java
│ │ ├── TesterFactory.java
│ │ └── ...
│ └── tester/ # Database-specific testers
│ ├── MySQLTester.java
│ ├── PostgreSQLTester.java
│ └── ...
├── build.gradle # Build configuration
├── docker/ # Docker configuration
└── README.md # This file
To add support for a new database:
- Create a new Tester class in
src/main/java/com/apecloud/dbtester/tester/ - Register the tester in
TesterFactory.java - Add JDBC driver or client library to
build.gradle - Update
DBConfig.javato recognize the new database type - Update
DatabaseConnectionFactory.javawith connection logic
This project is licensed under the Apache License 2.0.
Contributions are welcome! Please feel free to submit pull requests or open issues for bug reports and feature requests.