mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Add enable_plpgsql from Oliver.
This commit is contained in:
parent
2d11676999
commit
26a23e33db
68
src/pl/plpgsql/enable_plpgsql
Normal file
68
src/pl/plpgsql/enable_plpgsql
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Enable the PL procedural language for PostgreSQL in one or more
|
||||||
|
# existing databases.
|
||||||
|
#
|
||||||
|
# This script should be run by the PostgreSQL superuser
|
||||||
|
|
||||||
|
enable_database() {
|
||||||
|
if ! psql -d $1 -qtc "select count(*) from pg_language where lanname='plpgsql'" >$TMPFIL2 2>&1
|
||||||
|
then
|
||||||
|
echo "Cannot connect to $1"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
if [ `cat $TMPFIL2` -eq 0 ]
|
||||||
|
then
|
||||||
|
if ! psql -d $1 <$sqlfile
|
||||||
|
then
|
||||||
|
echo "Failed to add PL to $1"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
echo "PL added to $1"
|
||||||
|
else
|
||||||
|
echo "PL is already enabled in $1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Execution starts here
|
||||||
|
|
||||||
|
TMPFILE=`mktemp /tmp/enable_pgpl.XXXXXX`
|
||||||
|
TMPFIL2=`mktemp /tmp/enable_pgpl.XXXXXX`
|
||||||
|
trap "rm $TMPFILE $TMPFIL2" EXIT
|
||||||
|
|
||||||
|
sqlfile=${PGLIB:=/usr/local/pgsql/lib}/mklang_pl.sql
|
||||||
|
if [ ! -f $sqlfile ]
|
||||||
|
then
|
||||||
|
echo "Cannot find mklang_pl.sql"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$1" ]
|
||||||
|
then
|
||||||
|
echo "Syntax: $0 --all | database ..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $1 = "--all" ]
|
||||||
|
then
|
||||||
|
if ! psql -t -c "select datname from pg_database order by datname" >$TMPFILE
|
||||||
|
then
|
||||||
|
echo Cannot select databases
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
for db in `cat $TMPFILE`
|
||||||
|
do
|
||||||
|
enable_database $db
|
||||||
|
done
|
||||||
|
else
|
||||||
|
while [ -n "$1" ]
|
||||||
|
do
|
||||||
|
db=$1
|
||||||
|
enable_database $db
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user