File: pgsql_common.sh

package info (click to toggle)
sysbench 1.0.20%2Bds-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,840 kB
  • sloc: ansic: 11,830; sh: 1,752; xml: 736; makefile: 195
file content (64 lines) | stat: -rw-r--r-- 1,875 bytes parent folder | download | duplicates (4)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
########################################################################
# Common code for PostgreSQL-specific tests
########################################################################
set -eu

if [ -z "${SBTEST_PGSQL_ARGS:-}" ]
then
  exit 80
fi

# Emulate "\d+" output since it is not portable across PostgreSQL major versions
function db_show_table() {
  if ! psql -c "\d+ $1" sbtest > /dev/null
  then
      return
  fi

  echo "                            Table \"public.$1\""
  psql -q sbtest <<EOF
\pset footer off
 SELECT
    f.attname AS "Column",
    pg_catalog.format_type(f.atttypid,f.atttypmod) AS "Type",
    CASE
        WHEN f.attnotnull = 't' OR p.contype = 'p' THEN 'not null '
        ELSE ''
    END ||
    CASE
        WHEN f.atthasdef = 't' THEN 'default ' ||
             pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)
        ELSE ''
    END AS "Modifiers",
    CASE
        WHEN f.attstorage = 'p' THEN 'plain'
        ELSE 'extended'
    END as "Storage",
    CASE
        WHEN f.attstattarget < 0 THEN ''
        ELSE f.attstattarget::text
    END as "Stats target",
    pg_catalog.col_description(f.attrelid, f.attnum) as "Description"
FROM pg_attribute f
    JOIN pg_class c ON c.oid = f.attrelid
    JOIN pg_type t ON t.oid = f.atttypid
    LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum
    LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
    LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey)
    LEFT JOIN pg_class AS g ON p.confrelid = g.oid
WHERE c.relkind = 'r'::char
    AND n.nspname = 'public'
    AND c.relname = '$1'
    AND f.attnum > 0
EOF
  echo "Indexes:"
  psql -qt sbtest <<EOF
 SELECT REPLACE(indexdef, 'public.', '')
FROM pg_catalog.pg_indexes
WHERE schemaname = 'public'
    AND tablename = '$1'
ORDER BY 1
EOF
}

DB_DRIVER_ARGS="--db-driver=pgsql $SBTEST_PGSQL_ARGS"