I'm trying to implement a testing simulation on a postgres database using pgbouncer for pooling and bash script for making requests. The script is intended to simulate multiple users making requests in order to enforce a workload on the database, which I'm doing with the following script:
#!/bin/bash
scriptName="/data/script/insert-call.sh"
insertionMultiplier=2000
numberOfProcess=5
pids=()
for ((i = 0 ; i <= $insertionMultiplier ; i++)); do
for ((j = 0 ; j <= $numberOfProcess ; j++)); do
psql -p 6432 test_db -U postgres -c "call insert_procedure()" &
pids+=("$!")
done
for pid in "${pids[@]}"; do
wait "$pid"
return_code="$?"
echo "PID= $pid; return_code=$return_code"
done
done
The problem is that as the sub processes are created, some of them never finish and the execution keeps hanging in the second nested loop. How can I make these multiple requests succeed ? I already also tried using the bare "wait", but it didn't work neither.