test_exclusivelock_on_insert.sh

application/x-shellscript

Filename: test_exclusivelock_on_insert.sh
Type: application/x-shellscript
Part: 0
Message: Process waiting for ExclusiveLock on INSERT
#!/bin/sh
# $ grep -Ev '^\s*(#.*)?$' $PGDATA/postgresql.conf 
# max_connections = 100			# (change requires restart)
# shared_buffers = 24MB			# min 128kB
# wal_buffers = 16			# min 32kB, -1 sets based on shared_buffers
# checkpoint_segments = 64		# in logfile segments, min 1, 16MB each
# log_lock_waits = on			# log lock waits >= deadlock_timeout
# deadlock_timeout = 100ms

DB="test"
NUMBACKENDS=97
NUMINSERTS=10
TESTFILE="test_file"

dropdb $DB
createdb $DB
psql -Atc "create table test (i bigserial, t text)" $DB

B=0
while test $B -lt $NUMBACKENDS
do
    B=$((B+1))
    (
        for i in $(seq 1 $NUMINSERTS); do
            psql -Atc "insert into test select i, md5(i::text) from generate_series(1,1000) AS i" $DB > /dev/null
        done
        echo "$B: KTHXBYE"
    ) &
done

# hammering a bit more...
while test $(pgrep -f $0| wc -l) -gt 2; do
    echo "hammering...(current process: $(pgrep -f $0| wc -l))"
    dd if=/dev/zero of="./$TESTFILE" bs=8192 count=300000 conv=fdatasync
done
rm ./$TESTFILE