Evaluating Postgresql DB with Apache JMeter

Bringup Postgresql in Docker
$ mkdir -p $HOME/docker/volumes/postgres
$ docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
Login to Postgres Docker
$ sudo docker exec -it pg-docker bash
Connect to User [User: postgres] (Inside Docker)
$ psql -U postgres
List all Databases [Inside Postgresql]
postgres-# \l
Use database
postgres-# \c postgres
You are now connected to database "postgres" as user "postgres".
Create a Sample Table
postgres=# CREATE TABLE tbl_student (
roll_no serial,
name VARCHAR(20) NOT NULL,
age INTEGER NOT NULL,
PRIMARY KEY(roll_no)
);
List all tables
postgres=# \d
Describe table
postgres=# \d tbl_student
Insert values to Table
postgres=# INSERT INTO tbl_student (name, age) VALUES('Raj', 33);
Install JDK (8/9)
$ sudo apt-get install openjdk-8-jre -y
Download and start JMeter
$ cd ~/Downloads
$ wget https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.4.3.tgz
$ tar -zxvf apache-jmeter-5.4.3.tgz
$ cd apache-jmeter-5.4.3/bin
$ ./jmeter
Download Postgres JDBC Driver
$ mkdir -p ~/Downloads/Drivers
$ cd ~/Downloads/Drivers
$ wget https://jdbc.postgresql.org/download/postgresql-42.3.1.jar
File -> New -> Test Plan -> Name [Postgres_Test_Plan] -> SavePostgres_Test_Plan [Right click] -> Add -> Config Element -> JDBC Connection Configuration 
-> Variable Name for created Pool [pg_pool], Validation Query [select 1], Database URL [jdbc:postgresql://127.0.0.1:5432/postgres], JDBC Driver Class [org.postgresql.Driver], Username [postgres], Password [docker]
-> Save

Postgres_Test_Plan [Click] -> Add directory or jar to classpath -> Browse -> [Navigate to postgresql driver jar] -> Save
Add Thread Group
Postgres_Test_Plan [Right Click] -> Add -> Threads -> Thread Group -> Number of Threads [10], Forever [10] -> Save
Create Sampler
Thread Group [Right Click] -> Add -> Sampler -> JDBC request ->
-> Variable Name of pool [pg_pool] -> Query Type [Select Statement]
-> select * from <Table Name> -> Save

Create a Listener to store results
Thread Group > JDBC request [Right Click] -> Add -> Listener -> View Result Tree -> Clear -> run [Play]
alias run-jmeter-cli="cd ~/Downloads/apache-jmeter-5.4.3/bin && rm -rf /tmp/results.jtl && rm -rf /tmp/report && mkdir -p /tmp/report && ./jmeter -n -t Postgres_Test_Plan.jmx -l /tmp/results.jtl -e -o /tmp/report && firefox /tmp/report/index.html &"$ run-jmeter-cli

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prince Pereira

Prince Pereira

31 Followers

Software Engineer II - Microsoft | SDN | Java | Golang | DS & Algo | Microservices | Kubernetes | Docker | gRPC & Protocol Buffer