This project contains an AWS Cloud Development Kit (CDK) based solution that provisions a database using Amazon RDS for PostgreSQL and an EC2 based bastion host that uses pgbench to send transactions periodically to the database.
You can use this project for proofs-of-concept where you need to emulate an application sending regular database transactions or for stress testing existing PostgreSQL installations.
-
PostgreSQL version 11.8 with a single SMALL instance.
-
Logical replication enabled (useful to enable CDC replication)
-
EC2 bastion host of instance size t3.micro accessible through SSM
-
Pgbench runs every minute, during periods of 30 seconds (-T 30), and simulates transactions from 10 clients (-c 10). This is performed with a sequence of SQL statements running against for 4 tables:
- pgbench_branches
- pgbench_tellers
- pgbench_accounts
- pgbench_history
Prerequisites:
- Install CDK in your computer or set up an AWS Cloud 9 environment.
- Configure your AWS credentials locally for programmatic access.
Deployment steps:
-
Clone this repository
-
Install dependencies
sudo pip3 install -r requirements.txt
-
Boootstrap CDK
cdk bootstrap
-
Deploy all the stacks
cdk deploy --require-approval never "*"
If you want to customize the parameters that control the workload generated by pgbench, you can use AWS System Manager Session Manager to log into the instance. The pgbench utility is configured in the operative system scheduler as shown below.
sudo cat /etc/cron.d/pgbench_cron
*/2 * * * * root pgbench -c 10 -T 30 -h your_rds.rds.amazonaws.com -p 5432 -U postgres test
Remove your AWS resources:
cdk destroy "*"