mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
Fix pg_upgrade to handle dbnames, user/group names with spaces.
This commit is contained in:
parent
25f050d90d
commit
3f6299df6c
@ -6,7 +6,7 @@
|
|||||||
# and "pg_group" tables, which belong to the whole installation rather
|
# and "pg_group" tables, which belong to the whole installation rather
|
||||||
# than any one individual database.
|
# than any one individual database.
|
||||||
#
|
#
|
||||||
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_dumpall.sh,v 1.17 2002/04/11 04:56:21 momjian Exp $
|
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_dumpall.sh,v 1.18 2002/04/11 19:23:36 momjian Exp $
|
||||||
|
|
||||||
CMDNAME="`basename $0`"
|
CMDNAME="`basename $0`"
|
||||||
|
|
||||||
@ -24,7 +24,8 @@ if echo "$0" | grep '/' > /dev/null 2>&1 ; then
|
|||||||
PGPATH=`echo "$0" | sed 's,/[^/]*$,,'` # (dirname command is not portable)
|
PGPATH=`echo "$0" | sed 's,/[^/]*$,,'` # (dirname command is not portable)
|
||||||
else
|
else
|
||||||
# look for it in PATH ('which' command is not portable)
|
# look for it in PATH ('which' command is not portable)
|
||||||
for dir in `echo "$PATH" | sed 's/:/ /g'` ; do
|
echo "$PATH" | sed 's/:/\
|
||||||
|
/g' | while read dir; do
|
||||||
# empty entry in path means current dir
|
# empty entry in path means current dir
|
||||||
[ x"$dir" = x ] && dir='.'
|
[ x"$dir" = x ] && dir='.'
|
||||||
if [ -f "$dir/$CMDNAME" ] ; then
|
if [ -f "$dir/$CMDNAME" ] ; then
|
||||||
@ -193,18 +194,20 @@ echo
|
|||||||
echo "DELETE FROM pg_group;"
|
echo "DELETE FROM pg_group;"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
$PSQL -d template1 -At -F ' ' \
|
|
||||||
-c 'SELECT groname,grosysid,grolist FROM pg_group;' | \
|
$PSQL -d template1 -At -F '
|
||||||
while read GRONAME GROSYSID GROLIST ; do
|
' -c 'SELECT groname,grosysid,grolist FROM pg_group;' | \
|
||||||
|
while read GRONAME ; do
|
||||||
|
read GROSYSID
|
||||||
|
read GROLIST
|
||||||
echo "CREATE GROUP \"$GRONAME\" WITH SYSID ${GROSYSID};"
|
echo "CREATE GROUP \"$GRONAME\" WITH SYSID ${GROSYSID};"
|
||||||
raw_grolist=`echo "$GROLIST" | sed 's/^{\(.*\)}$/\1/' | tr ',' ' '`
|
echo "$GROLIST" | sed 's/^{\(.*\)}$/\1/' | tr ',' '\n' |
|
||||||
for userid in $raw_grolist ; do
|
while read userid; do
|
||||||
username=`$PSQL -d template1 -At -c "SELECT usename FROM pg_shadow WHERE usesysid = ${userid};"`
|
username="`$PSQL -d template1 -At -c \"SELECT usename FROM pg_shadow WHERE usesysid = ${userid};\"`"
|
||||||
echo " ALTER GROUP \"$GRONAME\" ADD USER \"$username\";"
|
echo " ALTER GROUP \"$GRONAME\" ADD USER \"$username\";"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
test "$globals_only" = yes && exit 0
|
test "$globals_only" = yes && exit 0
|
||||||
|
|
||||||
|
|
||||||
@ -218,10 +221,13 @@ exec 4<&0
|
|||||||
# We skip databases marked not datallowconn, since we'd be unable to
|
# We skip databases marked not datallowconn, since we'd be unable to
|
||||||
# connect to them anyway (and besides, we don't want to dump template0).
|
# connect to them anyway (and besides, we don't want to dump template0).
|
||||||
|
|
||||||
$PSQL -d template1 -At -F ' ' \
|
$PSQL -d template1 -At -F '
|
||||||
-c "SELECT datname, coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), pg_encoding_to_char(d.encoding), datistemplate, datpath FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) WHERE datallowconn ORDER BY 1;" | \
|
' -c "SELECT datname, coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), pg_encoding_to_char(d.encoding), datistemplate, datpath FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) WHERE datallowconn ORDER BY 1;" | \
|
||||||
while read DATABASE DBOWNER ENCODING ISTEMPLATE DBPATH; do
|
while read DATABASE ; do
|
||||||
|
read DBOWNER
|
||||||
|
read ENCODING
|
||||||
|
read ISTEMPLATE
|
||||||
|
read DBPATH
|
||||||
if [ "$DATABASE" != template1 ] ; then
|
if [ "$DATABASE" != template1 ] ; then
|
||||||
echo
|
echo
|
||||||
|
|
||||||
@ -243,8 +249,8 @@ while read DATABASE DBOWNER ENCODING ISTEMPLATE DBPATH; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
$PSQL -d template1 -At -F ' ' \
|
$PSQL -d template1 -At -F '
|
||||||
-c "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;" | \
|
' -c "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;" | \
|
||||||
while read DATABASE; do
|
while read DATABASE; do
|
||||||
echo "dumping database \"$DATABASE\"..." 1>&2
|
echo "dumping database \"$DATABASE\"..." 1>&2
|
||||||
echo
|
echo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user