port=5432
client_num=2
run_times=20

run()
{
    for i in $(seq 1 ${run_times})
    do
        psql -p$port -d postgres -c "UPDATE tbl SET body = upper(body);"
    done
}


pg_ctl -D data_test stop
rm -rf data_test test.log

initdb -D data_test -U postgres

cat << EOF >> data_test/postgresql.conf
port = $port
EOF

pg_ctl -D data_test start -l test.log

psql -p$port  -d postgres -c "create table tbl (body text);"


# prepare date
for i in $(seq 1 1000)
do
    psql -p$port -d postgres -c "INSERT INTO tbl VALUES (repeat('abcdefg',10000));" >/dev/null
done

# UPDATE with multple clients
for i in $(seq 1 ${client_num})
do
    run  &
done


