File tree 1 file changed +68
-0
lines changed
1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+
3
+ # Enable the PL procedural language for PostgreSQL in one or more
4
+ # existing databases.
5
+ #
6
+ # This script should be run by the PostgreSQL superuser
7
+
8
+ enable_database () {
9
+ if ! psql -d $1 -qtc " select count(*) from pg_language where lanname='plpgsql'" > $TMPFIL2 2>&1
10
+ then
11
+ echo " Cannot connect to $1 "
12
+ exit 2
13
+ fi
14
+ if [ ` cat $TMPFIL2 ` -eq 0 ]
15
+ then
16
+ if ! psql -d $1 < $sqlfile
17
+ then
18
+ echo " Failed to add PL to $1 "
19
+ exit 2
20
+ fi
21
+ echo " PL added to $1 "
22
+ else
23
+ echo " PL is already enabled in $1 "
24
+ fi
25
+
26
+ }
27
+
28
+ # Execution starts here
29
+
30
+ TMPFILE=` mktemp /tmp/enable_pgpl.XXXXXX`
31
+ TMPFIL2=` mktemp /tmp/enable_pgpl.XXXXXX`
32
+ trap " rm $TMPFILE $TMPFIL2 " EXIT
33
+
34
+ sqlfile=${PGLIB:=/ usr/ local/ pgsql/ lib} /mklang_pl.sql
35
+ if [ ! -f $sqlfile ]
36
+ then
37
+ echo " Cannot find mklang_pl.sql"
38
+ exit 2
39
+ fi
40
+
41
+ if [ -z " $1 " ]
42
+ then
43
+ echo " Syntax: $0 --all | database ..."
44
+ exit 1
45
+ fi
46
+
47
+ if [ $1 = " --all" ]
48
+ then
49
+ if ! psql -t -c " select datname from pg_database order by datname" > $TMPFILE
50
+ then
51
+ echo Cannot select databases
52
+ exit 2
53
+ fi
54
+ for db in ` cat $TMPFILE `
55
+ do
56
+ enable_database $db
57
+ done
58
+ else
59
+ while [ -n " $1 " ]
60
+ do
61
+ db=$1
62
+ enable_database $db
63
+ shift
64
+ done
65
+ fi
66
+
67
+
68
+
You can’t perform that action at this time.
0 commit comments