Skip to content

Commit 013c2c6

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
New dump utility script pg_dumpaccounts.
Dumps pg_shadow and pg_group (derived from pg_dumpall). Jan
1 parent 75413f7 commit 013c2c6

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/bin/pg_dump/Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/Makefile.in,v 1.13 2000/05/11 17:46:32 momjian Exp $
10+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/Makefile.in,v 1.13.2.1 2000/11/02 16:54:21 wieck Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

@@ -41,6 +41,7 @@ submake:
4141
install: pg_dump
4242
$(INSTALL) $(INSTL_EXE_OPTS) pg_dump$(X) $(BINDIR)/pg_dump$(X)
4343
$(INSTALL) $(INSTL_EXE_OPTS) pg_dumpall $(BINDIR)/pg_dumpall
44+
$(INSTALL) $(INSTL_EXE_OPTS) pg_dumpaccounts $(BINDIR)/pg_dumpaccounts
4445
$(INSTALL) $(INSTL_EXE_OPTS) pg_upgrade $(BINDIR)/pg_upgrade
4546

4647
depend dep:

src/bin/pg_dump/pg_dumpaccounts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
#
3+
# pg_dumpaccounts
4+
# dumps the pg_shadow and pg_group tables, which belong to the
5+
# whole installation rather than any one individual database.
6+
#
7+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/pg_dumpaccounts,v 1.1.2.1 2000/11/02 16:54:21 wieck Exp $
8+
#
9+
# to adapt to System V vs. BSD 'echo'
10+
if echo '\\' | grep '\\\\' >/dev/null 2>&1
11+
then
12+
BS='\' # BSD
13+
else
14+
BS='\\' # System V
15+
fi
16+
#
17+
# Dump everyone but the postgres user
18+
# initdb creates him
19+
#
20+
# get the postgres user id
21+
#
22+
POSTGRES_SUPER_USER_ID="`echo \" \
23+
select datdba \
24+
from pg_database \
25+
where datname = 'template1'; \" | \
26+
psql -A -q -t template1`"
27+
echo "${BS}connect template1"
28+
#
29+
# delete all users in case they run this twice
30+
#
31+
# we don't use POSTGRES_SUPER_USER_ID because the postgres super user id
32+
# could be different on the two installations
33+
#
34+
echo "select datdba into table tmp_pg_shadow \
35+
from pg_database where datname = 'template1';"
36+
echo "delete from pg_shadow where usesysid <> tmp_pg_shadow.datdba;"
37+
echo "drop table tmp_pg_shadow;"
38+
#
39+
# load all the non-postgres users
40+
# XXX this breaks badly if the layout of pg_shadow ever changes.
41+
# It'd be better to convert the data into CREATE USER commands.
42+
#
43+
echo "copy pg_shadow from stdin;"
44+
psql -q template1 <<END
45+
select pg_shadow.*
46+
into table tmp_pg_shadow
47+
from pg_shadow
48+
where usesysid <> $POSTGRES_SUPER_USER_ID;
49+
copy tmp_pg_shadow to stdout;
50+
drop table tmp_pg_shadow;
51+
END
52+
echo "${BS}."
53+
#
54+
# copy the pg_group table too
55+
# XXX this breaks badly if the layout of pg_group ever changes.
56+
# It'd be better to convert the data into CREATE GROUP commands.
57+
#
58+
echo "delete from pg_group;"
59+
echo "copy pg_group from stdin;"
60+
psql -q template1 <<END
61+
copy pg_group to stdout;
62+
END
63+
echo "${BS}."
64+
65+
exit 0

0 commit comments

Comments
 (0)