File: parallel_conn.sh

package info (click to toggle)
pgtap 1.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,792 kB
  • sloc: sql: 25,795; sh: 790; makefile: 287; perl: 175
file content (35 lines) | stat: -rwxr-xr-x 1,033 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh

# Find the maximum safe connections for parallel execution

error () {
    echo $@ 1>&2
}
die () {
    error $@
    exit 1
}

[ $# -le 1 ] || die "$0: Invalid number of arguments"

PARALLEL_CONN=$1

if [ -n "$PARALLEL_CONN" ]; then
    [ $PARALLEL_CONN -ge 1 ] 2>/dev/null || die "Invalid value for PARALLEL_CONN ($PARALLEL_CONN)"
    echo $PARALLEL_CONN
    exit
fi

COMMAND="SELECT greatest(1, current_setting('max_connections')::int - current_setting('superuser_reserved_connections')::int - (SELECT count(*) FROM pg_stat_activity) - 2)"

if PARALLEL_CONN=`psql -d ${PGDATABASE:-postgres} -P pager=off -P tuples_only=true -qAXtc "$COMMAND" 2> /dev/null`; then
    if [ $PARALLEL_CONN -ge 1 ] 2>/dev/null; then
        # We know it's a number at this point
        [ $PARALLEL_CONN -eq 1 ] && error "NOTICE: unable to run tests in parallel; not enough connections"
        echo $PARALLEL_CONN
        exit
    fi
fi

error "Problems encountered determining maximum parallel test connections; forcing serial mode"
echo 1