head	1.28;
access;
symbols
	REL7_0_PATCHES:1.27.0.2
	REL7_0:1.26
	REL6_5_PATCHES:1.18.0.2
	REL6_5:1.18
	REL6_4:1.17.0.2
	release-6-3:1.14;
locks; strict;
comment	@# @;


1.28
date	2000.07.03.16.35.39;	author petere;	state dead;
branches;
next	1.27;

1.27
date	2000.05.25.20.18.15;	author tgl;	state Exp;
branches;
next	1.26;

1.26
date	2000.05.05.17.50.38;	author tgl;	state Exp;
branches;
next	1.25;

1.25
date	2000.05.05.03.04.00;	author tgl;	state Exp;
branches;
next	1.24;

1.24
date	2000.03.22.05.25.06;	author momjian;	state Exp;
branches;
next	1.23;

1.23
date	2000.03.22.05.10.22;	author momjian;	state Exp;
branches;
next	1.22;

1.22
date	2000.03.19.02.19.43;	author momjian;	state Exp;
branches;
next	1.21;

1.21
date	2000.03.07.23.09.34;	author momjian;	state Exp;
branches;
next	1.20;

1.20
date	2000.01.19.20.10.27;	author momjian;	state Exp;
branches;
next	1.19;

1.19
date	2000.01.06.21.16.18;	author momjian;	state Exp;
branches;
next	1.18;

1.18
date	98.12.12.22.04.09;	author momjian;	state Exp;
branches;
next	1.17;

1.17
date	98.08.24.01.14.06;	author momjian;	state Exp;
branches
	1.17.2.1;
next	1.16;

1.16
date	98.07.09.03.35.39;	author scrappy;	state Exp;
branches;
next	1.15;

1.15
date	98.03.06.17.25.51;	author momjian;	state Exp;
branches;
next	1.14;

1.14
date	97.09.03.16.48.59;	author momjian;	state Exp;
branches;
next	1.13;

1.13
date	97.08.21.02.28.48;	author momjian;	state Exp;
branches;
next	1.12;

1.12
date	97.08.20.15.06.48;	author momjian;	state Exp;
branches;
next	1.11;

1.11
date	97.07.12.15.57.31;	author momjian;	state Exp;
branches;
next	1.10;

1.10
date	97.06.25.21.24.57;	author momjian;	state Exp;
branches;
next	1.9;

1.9
date	97.06.21.16.08.17;	author momjian;	state Exp;
branches;
next	1.8;

1.8
date	97.06.20.16.37.10;	author momjian;	state Exp;
branches;
next	1.7;

1.7
date	97.05.21.03.11.56;	author momjian;	state Exp;
branches;
next	1.6;

1.6
date	97.05.20.03.38.33;	author momjian;	state Exp;
branches;
next	1.5;

1.5
date	97.05.14.19.49.34;	author momjian;	state Exp;
branches;
next	1.4;

1.4
date	97.01.19.10.15.59;	author momjian;	state Exp;
branches;
next	1.3;

1.3
date	97.01.18.03.26.08;	author momjian;	state Exp;
branches;
next	1.2;

1.2
date	97.01.17.23.48.50;	author momjian;	state Exp;
branches;
next	1.1;

1.1
date	97.01.16.15.28.24;	author momjian;	state Exp;
branches;
next	;

1.17.2.1
date	98.12.12.22.04.33;	author momjian;	state Exp;
branches;
next	;


desc
@@


1.28
log
@Have pg_dumpall write CREATE USER and CREATE GROUP commands instead of raw
COPYs of pg_shadow and pg_group.

It also turns out that pg_dumpall was all but broken for multiple servers
running at non-standard port numbers. You might get the users and groups
from one server and the databases from another. Fixed that.

A little user interface and code cleanup along with that. This also takes
care of the portability bug discussed in "[BUGS] pg_dumpall" in March 2000.
@
text
@#!/bin/sh
#
# pg_dumpall [pg_dump parameters]
# dumps all databases to standard output
# It also dumps the pg_shadow and pg_group tables, which belong to the
# whole installation rather than any one individual database.
#
# $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/pg_dump/pg_dumpall,v 1.27 2000/05/25 20:18:15 tgl Exp $
#
# to adapt to System V vs. BSD 'echo'
if echo '\\' | grep '\\\\' >/dev/null 2>&1
then	
	BS='\'			# BSD
else
	BS='\\'			# System V
fi
#
# Dump everyone but the postgres user
# initdb creates him
#
# get the postgres user id
#
POSTGRES_SUPER_USER_ID="`echo \" \
			select datdba \
			from pg_database \
			where datname = 'template1'; \" | \
			psql -A -q -t template1`"
echo "${BS}connect template1"
#
# delete all users in case they run this twice
#
# we don't use POSTGRES_SUPER_USER_ID because the postgres super user id
# could be different on the two installations
#
echo "select datdba into table tmp_pg_shadow \
      from pg_database where datname = 'template1';"
echo "delete from pg_shadow where usesysid <> tmp_pg_shadow.datdba;"
echo "drop table tmp_pg_shadow;"
#
# load all the non-postgres users
# XXX this breaks badly if the layout of pg_shadow ever changes.
# It'd be better to convert the data into CREATE USER commands.
#
echo "copy pg_shadow from stdin;"
psql -q template1 <<END
select pg_shadow.* 
into table tmp_pg_shadow
from pg_shadow
where usesysid <> $POSTGRES_SUPER_USER_ID;
copy tmp_pg_shadow to stdout;
drop table tmp_pg_shadow;
END
echo "${BS}."
#
# copy the pg_group table too
# XXX this breaks badly if the layout of pg_group ever changes.
# It'd be better to convert the data into CREATE GROUP commands.
#
echo "delete from pg_group;"
echo "copy pg_group from stdin;"
psql -q template1 <<END
copy pg_group to stdout;
END
echo "${BS}."
#
# For each database, run pg_dump to dump the contents of that database.
#
psql -A -q -t -c "select datname,datdba,encoding from pg_database" template1 | grep '|' | tr '|' ' ' | \
grep -v '^template1 ' | \
while read DATABASE DBUSERID ENCODING
do
	DBUSERNAME="`echo \" \
		select usename \
		from pg_user \
		where usesysid = $DBUSERID; \" | \
		psql -A -q -t template1`"

	echo "${BS}connect template1 $DBUSERNAME"

	if sh -c "pg_encoding $ENCODING" >/dev/null 2>&1
	then
		echo "create database \"$DATABASE\" with encoding='`pg_encoding $ENCODING`';"
	else
		echo "create database \"$DATABASE\";"
	fi

	echo "${BS}connect $DATABASE $DBUSERNAME"
	pg_dump ${1+"$@@"} "$DATABASE"
	if [ "$?" -ne 0 ]
	then	echo "pg_dump failed on $DATABASE, exiting" 1>&2
		exit 1
	fi
done

exit 0
@


1.27
log
@Quote database name so that not-all-lowercase names are handled safely.
@
text
@d8 1
a8 1
# $Header: /home/projects/pgsql/cvsroot/pgsql/src/bin/pg_dump/pg_dumpall,v 1.26 2000/05/05 17:50:38 tgl Exp $
@


1.26
log
@Forgot that dumpall's output script should 'delete from pg_group' before
loading new data, for consistency with its handling of pg_shadow.
@
text
@d8 1
a8 1
# $Header: /usr/local/cvsroot/pgsql/src/bin/pg_dump/pg_dumpall,v 1.25 2000/05/05 03:04:00 tgl Exp $
d68 1
a68 1
psql -A -q -t -c "select * from pg_database" template1 | grep '|' | tr '|' ' ' | \
d70 1
a70 1
while read DATABASE DBUSERID ENCODING DATAPATH
d82 1
a82 1
		echo "create database $DATABASE with encoding='`pg_encoding $ENCODING`';"
d84 1
a84 1
		echo "create database $DATABASE;"
d87 2
a88 2
	echo "${BS}connect $DATABASE $POSTGRES_USER"
	pg_dump ${1+"$@@"} $DATABASE
@


1.25
log
@Dump contents of pg_group along with pg_shadow.
@
text
@d8 1
a8 1
# $Header$
d59 1
@


1.24
log
@Update pg_dumpall again.
@
text
@d5 4
a8 1
# It also dumps the pg_shadow table
a10 1
#set -x
d41 2
d54 13
d93 2
@


1.23
log
@Fix pg_dumpall for new psql output.
@
text
@d54 5
a58 1
	echo "${BS}connect template1 $DBUSERID"
d60 3
a62 1
	if pg_encoding $ENCODING >/dev/null 2>&1
@


1.22
log
@it seems in the beta2 release DBUSERID in pg_dumpall is the _name_ of the
user, so it doesn't need to be translated from the number to the name.

also ``create database ...'' does not take numbers for the encoding, so
the ENCODING variable does not need to be translated to a number, but left
as the text representation.  a patch is supplied to make the changes i
have found to work.  i was successful dumping and reloading my database
after these changes.
-

John M. Flinchbaugh
@
text
@d50 1
a50 1
psql -l -A -q -t | grep '|' | tr '|' ' ' | \
d58 1
a58 1
		echo "create database $DATABASE with encoding='$ENCODING';"
@


1.21
log
@Fix problems with pg_upgrade found by Kardos, Dr. Andrea
@
text
@d54 1
a54 6
	POSTGRES_USER="`echo \" \
		select usename \
		from pg_shadow \
		where usename = $DBUSERID; \" | \
		psql -A -q -t template1`"
	echo "${BS}connect template1 $POSTGRES_USER"
d58 1
a58 1
		echo "create database $DATABASE with encoding='`pg_encoding $ENCODING`';"
@


1.20
log
@Update pg_dumpall.
@
text
@d57 1
a57 1
		where usesysid = $DBUSERID; \" | \
d61 1
a61 1
	if createdb -help|grep encoding >/dev/null
@


1.19
log
@Update pg_dumpall for new psql format.
@
text
@d50 1
a50 1
psql -l -A -q -t | grep '|' | tr '|' ' ' | sed -n '2,$p' | \
@


1.18
log
@Included patches should fix following problems in the muti-byte
enabled PostgreSQL 6.4.

o binary cursor does not work
o pg_dumpall produces incorrect create database statemnt

Tatsuo Ishii
t-ishii@@sra.co.jp
@
text
@d50 2
a51 1
psql -l -A -q -t| tr '|' ' ' | grep -v '^template1 ' | \
@


1.17
log
@o note that now pg_database has a new attribuite "encoding" even
if MULTIBYTE is not enabled. So be sure to run initdb.

o these patches are made against the latest source tree (after
Bruce's massive patch, I think) BTW, I noticed that after running
regression, the oid field of pg_type seems disappeared.

	regression=> select oid from pg_type; ERROR:  attribute
	'oid' not found

this happens after the constraints test. This occures with/without
my patches. strange...

o pg_database_mb.h, pg_class_mb.h, pg_attribute_mb.h are no longer
used, and shoud be removed.

o GetDatabaseInfo() in utils/misc/database.c removed (actually in
#ifdef 0). seems nobody uses.

t-ishii@@sra.co.jp
@
text
@d62 1
a62 1
		echo "create database with encoding='`pg_encoding $ENCODING`' $DATABASE;"
@


1.17.2.1
log
@Included patches should fix following problems in the muti-byte
enabled PostgreSQL 6.4.

o binary cursor does not work
o pg_dumpall produces incorrect create database statemnt

Tatsuo Ishii
t-ishii@@sra.co.jp
@
text
@d62 1
a62 1
		echo "create database $DATABASE with encoding='`pg_encoding $ENCODING`';"
@


1.16
log
@
From: Tom Lane <tgl@@sss.pgh.pa.us>

I see someone missed an ancient bit of shell-scripting lore:
on some older shells, if your script's argument list is empty,
then "$@@" generates an empty-string word rather than no word
at all.  You need to write ${1+"$@@"} to get the latter behavior.
(Read your shell man page to see exactly how that works,
but it does the Right Thing on every Bourne shell.)

In particular, pg_dumpall fails when invoked without any switches
on HPUX 9.*, because pg_dump gets an empty-string argument that it
thinks is the name of the database to dump.  I expect this bug
also affects some other OSes, but couldn't tell you just which ones.
Patch attached.
@
text
@d51 1
a51 1
while read DATABASE DBUSERID DATAPATH
d59 8
a66 1
	echo "create database $DATABASE;"
@


1.15
log
@Rename pg_user to pg_shadow.
@
text
@d61 1
a61 1
	pg_dump "$@@" $DATABASE
@


1.14
log
@Fix syntax error.
@
text
@d5 1
a5 1
# It also dumps the pg_user table
d33 1
a33 1
echo "select datdba into table tmp_pguser \
d35 2
a36 2
echo "delete from pg_user where usesysid <> tmp_pguser.datdba;"
echo "drop table tmp_pguser;"
d40 1
a40 1
echo "copy pg_user from stdin;"
d42 3
a44 3
select pg_user.* 
into table tmp_pg_user
from pg_user
d46 2
a47 2
copy tmp_pg_user to stdout;
drop table tmp_pg_user;
d55 1
a55 1
		from pg_user \
@


1.13
log
@Change pg_attribute.attnvals to float4, change #ifdef 0 to #if 0, fix aix call to strNcpy, fix pg_super_user_id in pg_dumpall, change pg_database.dtadba from oid to int4.
@
text
@d33 1
a33 1
echo "select datdba into tmp_pguser \
@


1.12
log
@Portability fix for pg_dumpall.
@
text
@d30 7
a36 2
echo "delete from pg_user"
echo "where usesysid <> $POSTGRES_SUPER_USER_ID;"
d42 2
a43 1
select pg_user.* into table tmp_pg_user
d51 1
a51 1
while read DATABASE PGUSERID DATAPATH
d56 1
a56 1
		where usesysid = $PGUSERID; \" | \
@


1.11
log
@Have pg_dumpall return proper status on exit
@
text
@d21 5
a25 5
POSTGRES_SUPER_USER_ID="`psql -A -q -t template1 <<END
select datdba
from pg_database
where datname = 'template1';
END`"
@


1.10
log
@Small pg_dumpall cleanup.
@
text
@d55 5
a59 1
	pg_dump "$@@" $DATABASE || echo "pg_dump failed on $DATABASE" 1>&2
@


1.9
log
@pg_dump, pg_dumpall cleanups.
@
text
@a56 1
# done
@


1.8
log
@Check pgdump return request.
@
text
@d47 5
a51 6
	POSTGRES_USER="`psql -A -q -t template1 <<END
select usename
from pg_user
where usesysid = $PGUSERID;
END`"

@


1.7
log
@Updated pg_dumpall and psql to preserve database owners.
@
text
@d56 1
a56 1
	pg_dump "$@@" $DATABASE
@


1.6
log
@Added fcvt() prot for bsdi.
Made PQsetdb() and PQfnumber() case-insensitive.
Removed attempt to set table ownership via pg_dumpall.
@
text
@a14 10
psql -l -A -q -t| tr '|' ' ' | grep -v '^template1 ' | \
while read DATABASE USERID USER
do
	echo "${BS}connect template1"
	echo "create database $DATABASE;"
	echo "${BS}connect $DATABASE"
	pg_dump "$@@" $DATABASE
done
echo "${BS}connect template1"
echo "copy pg_user from stdin;"
d19 2
d22 1
a22 1
select datdba 
d26 10
d44 15
@


1.5
log
@Allow pg_dumpall to preserve database ownership.
@
text
@d15 2
a16 2
psql -l -A -q -t|cut -d"|" -f1-2 | tr '|' ' ' | grep -v '^template1 ' | \
while read DATABASE USER
a19 1
	echo "update pg_database set datdba = $USER where datname = '$DATABASE';"
@


1.4
log
@Update handling of backslashes, and pg_user dump.
@
text
@d8 1
a8 1
set -x
d15 2
a16 2
psql -l -A -q -t|cut -d"|" -f1 | grep -v '^template1$' | \
while read DATABASE
d20 1
@


1.3
log
@Remove blank lines.
@
text
@d7 8
d18 3
a20 3
	/bin/echo '\connect template1'
	/bin/echo "create database $DATABASE;"
	/bin/echo '\connect' "$DATABASE"
d23 2
a24 2
/bin/echo '\connect template1'
/bin/echo 'copy pg_user from stdin;'
d29 1
a29 2
POSTGRES_SUPER_USER_ID="`psql -q template1 <<END
\\t
d41 1
a41 1
/bin/echo '\.'
@


1.2
log
@Removed unneeded custom shell script call.
@
text
@a34 2


@


1.1
log
@Added pg_dumpall to source tree.
@
text
@d7 1
a7 1
psql -l -A -q -t|unesc|cut -d"|" -f1 | grep -v '^template1$' | \
@
