Commit 83bad7c0 authored by Bruce Momjian's avatar Bruce Momjian

This is my -- hopefully sufficiently portable -- attempt at cleaning out

initdb. No more obscure dependencies on environment variables or paths.
It
now finds the templates and the right postgres itself (with cmd line
options as fallback). It also no longer depends on $USER (su safe), and
doesn't advertise that --username allows you to install the db as a
different user, since that doesn't work anyway. Also, recovery and
cleanup
on all errors. Consistent options, clearer documentation.

Please take a look at this and adopt it if you feel it's safe enough. I
have simulated all the stupid circumstances I could think of, but you
never know with shell scripts.

Oh yeah, you can give the postgres user a default password now.

--
Peter Eisentraut                  Sernanders väg 10:115
parent 1b22a8cb
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/initdb.sgml,v 1.5 1999/07/22 15:09:12 thomas Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/initdb.sgml,v 1.6 1999/12/17 01:05:29 momjian Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -15,24 +15,26 @@ Postgres documentation ...@@ -15,24 +15,26 @@ Postgres documentation
<application>initdb</application> <application>initdb</application>
</refname> </refname>
<refpurpose> <refpurpose>
Create a new <productname>Postgres</productname> database installation Create a new <productname>PostgreSQL</productname> database installation
</refpurpose> </refpurpose>
</refnamediv> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
<refsynopsisdivinfo> <refsynopsisdivinfo>
<date>1999-07-20</date> <date>1999-12-17</date>
</refsynopsisdivinfo> </refsynopsisdivinfo>
<synopsis> <synopsis>
initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <replaceable class="parameter">dbdir</replaceable> ] initdb [ --pgdata|-D <replaceable class="parameter">dbdir</replaceable> ]
[ --pglib=<replaceable class="parameter">libdir</replaceable> | -l <replaceable class="parameter">libdir</replaceable> ] [ --sysid|-i <replaceable class="parameter">sysid</replaceable> ]
[ --template=<replaceable class="parameter">template</replaceable> | -t <replaceable class="parameter">template</replaceable> ] [ --password|-W <replaceable class="parameter">password</replaceable> ]
[ --username=<replaceable class="parameter">name</replaceable> | -u <replaceable class="parameter">name</replaceable> ] [ --pgencoding|-e <replaceable class="parameter">encoding</replaceable> ]
[ --noclean | -n ] [ --debug | -d ] [ --pglib|-L <replaceable class="parameter">libdir</replaceable> ]
[ --username|-u <replaceable class="parameter">name</replaceable> ]
[ --noclean | -n ] [ --debug | -d ] [ --template | -t ]
</synopsis> </synopsis>
<refsect2 id="R2-APP-INITDB-1"> <refsect2 id="R2-APP-INITDB-1">
<refsect2info> <refsect2info>
<date>1998-10-02</date> <date>1999-11-17</date>
</refsect2info> </refsect2info>
<title> <title>
Inputs Inputs
...@@ -41,62 +43,61 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla ...@@ -41,62 +43,61 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>--pglib=<replaceable class="parameter">libdir</replaceable></term> <term>--pgdata=<replaceable class="parameter">dbdir</replaceable></term>
<term>-l <replaceable class="parameter">libdir</replaceable></term> <term>-D <replaceable class="parameter">dbdir</replaceable></term>
<term><envar>PGLIB</envar></term> <term><envar>PGDATA</envar></term>
<listitem> <listitem>
<para> <para>
Where are the files that make up <productname>Postgres</productname>? This option specifies where in the file system the database should be
Apart from files that stored. This is the only information required by initdb, but you can avoid
have to go in particular directories because of their function, the it by setting the <envar>PGDATA</envar> environment variable, which
files that make up the <productname>Postgres</productname> software can be convenient since the database server (<filename>postmaster</filename>)
were installed in a directory can find the database directory later by the same variable.
called the <replaceable class="parameter">libdir</replaceable> directory.
An example of a file that will be found
there that <application>initdb</application>
needs is <filename>global1.bki.source</filename>,
which contains all the information that goes
into the shared catalog tables.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>--pgdata=<replaceable class="parameter">dbdir</replaceable></term> <term>--sysid=<replaceable class="parameter">sysid</replaceable></term>
<term>-r <replaceable class="parameter">dbdir</replaceable></term> <term>-i <replaceable class="parameter">sysid</replaceable></term>
<term><envar>PGDATA</envar></term>
<listitem> <listitem>
<para> <para>
Where in your Unix filesystem do you want the database data to go? Selects the system id of the database superuser. This defaults to
The top level directory is called the <envar>PGDATA</envar> directory. the effective user id of the user running initdb. It is really
not important what the superuser's sysid is, but one might choose
to start the numbering at some number like 0 or 1.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term>--username=<replaceable class="parameter">name</replaceable></term> <term>--password=<replaceable class="parameter">password</replaceable></term>
<term>-u <replaceable class="parameter">name</replaceable></term> <term>-W <replaceable class="parameter">password</replaceable></term>
<term><envar>PGUSER</envar></term>
<listitem> <listitem>
<para> <para>
Who will be the <productname>Postgres</productname> superuser Sets the password of the database superuser. If you don't plan
for this database system? The on using password authentication, this is not important. If you
<productname>Postgres</productname> superuser is a Unix user do, you can save yourself a trip by specifying it here, but you
who owns all files that store the database can always change it later. The default password is empty.
system and also owns the postmaster and backend processes that access them.
Or just let it default to you (the Unix user who runs
<application>initdb</application>).
</para> </para>
<note>
<para>
Only the Unix superuser (<literal>root</literal>)
can create a database system with an owner
different from the <productname>Postgres</productname> superuser.
</para>
</note>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist>
<varlistentry>
<term>--pgencoding=<replaceable class="parameter">encoding</replaceable></term>
<term>-e <replaceable class="parameter">encoding</replaceable></term>
<listitem>
<para>
Selects the multibyte encoding of the template database. This will also
be the default encoding of any database you create later, unless you
override it there. To use the multibyte encoding feature, you must
specify so at build time, at which time you also select the default
for this option.
</para>
</listitem>
</varlistentry>
</variablelist>
</para> </para>
<para> <para>
...@@ -104,15 +105,46 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla ...@@ -104,15 +105,46 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term>--template=<replaceable class="parameter">template</replaceable></term> <term>--pglib=<replaceable class="parameter">libdir</replaceable></term>
<term>-t <replaceable class="parameter">template</replaceable></term> <term>-l <replaceable class="parameter">libdir</replaceable></term>
<listitem>
<para>
initdb needs a few input files to initialize the database. This option
tells where to find them. You normally don't have to worry about this
since initdb knows about the most common installation layouts and will
find the files itself. You will be told if you need to specify their
location explicitly. If that happens, one of the files is called
<filename>global1.bki.source</filename> and is traditionally installed
along with the others in the library directory (e.g.,
<filename>/usr/local/pgsql/lib</filename>).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>--username=<replaceable class="parameter">name</replaceable></term>
<term>-u <replaceable class="parameter">name</replaceable></term>
<listitem>
<para>
The database system will be initialized with the username that is
running initdb. That is a requirement. If for some unimaginable
reason initdb cannot find out what the current user's name is,
you have to use this option. Normally, this will not be necessary
and initdb will tell you when it is.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>--template</term>
<term>-t</term>
<listitem> <listitem>
<para> <para>
Replace the <literal>template1</literal> Replace the <literal>template1</literal>
database in an existing database system, and don't touch anything else. database in an existing database system, and don't touch anything else.
This is useful when you need to upgrade your <literal>template1</literal> This is useful when you need to upgrade your <literal>template1</literal>
database using <application>initdb</application> database using <application>initdb</application>
from a newer release of <productname>Postgres</productname>, from a newer release of <productname>PostgreSQL</productname>,
or when your <literal>template1</literal> or when your <literal>template1</literal>
database has become corrupted by some system problem. Normally the database has become corrupted by some system problem. Normally the
contents of <literal>template1</literal> contents of <literal>template1</literal>
...@@ -133,8 +165,7 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla ...@@ -133,8 +165,7 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
By default, when <application>initdb</application> By default, when <application>initdb</application>
determines that error prevent it from completely creating the database determines that error prevent it from completely creating the database
system, it removes any files it may have created before determining system, it removes any files it may have created before determining
that it can't finish the job. That includes any core files left by that it can't finish the job. This option inhibits any tidying-up and is
the programs it invokes. This option inhibits any tidying-up and is
thus useful for debugging. thus useful for debugging.
</para> </para>
</listitem> </listitem>
...@@ -145,10 +176,11 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla ...@@ -145,10 +176,11 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
<term>-d</term> <term>-d</term>
<listitem> <listitem>
<para> <para>
Print debugging output from the bootstrap backend. Print debugging output from the bootstrap backend and a few other
messages of lesser interest for the general public.
The bootstrap backend is the program <application>initdb</application> The bootstrap backend is the program <application>initdb</application>
uses to create the catalog tables. This option generates a tremendous uses to create the catalog tables. This option generates a tremendous
amount of output. It also turns off the final vacuuming step. amount of output.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -156,56 +188,17 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla ...@@ -156,56 +188,17 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
</variablelist> </variablelist>
</para> </para>
<para>
Files are also input to <application>initdb</application>:
<variablelist>
<varlistentry>
<term><application>postconfig</application></term>
<listitem>
<para>
If appearing somewhere in the Unix command search path
(defined by the PATH environment variable).
This is a program that specifies defaults for some of the
command options. See below.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename><envar>PGLIB</envar>/global1.bki.source</filename></term>
<listitem>
<para>
Contents for the shared catalog tables in the new database system. This
file is part of the <productname>Postgres</productname> software.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename><envar>PGLIB</envar>/local1_template1.bki.source</filename></term>
<listitem>
<para>
Contents for the template1 tables in the new database system. This
file is part of the <productname>Postgres</productname> software.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2> </refsect2>
<refsect2 id="R2-APP-INITDB-2"> <refsect2 id="R2-APP-INITDB-2">
<refsect2info> <refsect2info>
<date>1998-09-26</date> <date>1999-12-17</date>
</refsect2info> </refsect2info>
<title> <title>
Outputs Outputs
</title> </title>
<para> <para>
<application>initdb</application> will create files in the <application>initdb</application> will create files in the specified
<envar>PGDATA</envar>
data area which are the system tables and framework for a complete data area which are the system tables and framework for a complete
installation. installation.
</para> </para>
...@@ -214,14 +207,14 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla ...@@ -214,14 +207,14 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
<refsect1 id="R1-APP-INITDB-1"> <refsect1 id="R1-APP-INITDB-1">
<refsect1info> <refsect1info>
<date>1998-09-26</date> <date>1999-12-17</date>
</refsect1info> </refsect1info>
<title> <title>
Description Description
</title> </title>
<para> <para>
<application>initdb</application> creates a new <application>initdb</application> creates a new
<productname>Postgres</productname> database system. <productname>PostgreSQL</productname> database system.
A database system is a A database system is a
collection of databases that are all administered by the same Unix user collection of databases that are all administered by the same Unix user
and managed by a single postmaster. and managed by a single postmaster.
...@@ -231,74 +224,37 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla ...@@ -231,74 +224,37 @@ initdb [ --pgdata=<replaceable class="parameter">dbdir</replaceable> | -r <repla
the database data will live, generating the shared catalog tables the database data will live, generating the shared catalog tables
(tables that don't belong to any particular database), and (tables that don't belong to any particular database), and
creating the <literal>template1</literal> creating the <literal>template1</literal>
database. What is the <literal>template1</literal> database. When you create a new database, everything in the
database? When you create a database, <productname>Postgres</productname> <literal>template1</literal> database is copied.
does it by copying It contains catalog tables filled in for things like the
everything from the <literal>template1</literal>
database. It contains catalog tables filled in for things like the
builtin types. builtin types.
</para> </para>
<para>
After <application>initdb</application>
creates the database, it completes the initialization by running
<application>vacuum</application>, which resets some optimization parameters.
</para>
<para>
There are three ways to give parameters to <application>initdb</application>.
<itemizedlist> <para>
<listitem> You must not execute <application>initdb</application> as root. This is
<para> because you cannot run the database server as root either, but the
You can use <application>initdb</application> command options. server needs to have access to the files <application>initdb</application>
</para> creates. Furthermore, during the initialization phase, when there are no
</listitem> users and no access controls installed, postgres will only connect with
<listitem> the name of the current Unix user, so you must log in under the account
<para> that will own the server process.
You can set environment
variables before invoking <application>initdb</application>.
</para>
</listitem>
<listitem>
<para>
You can have a program called <application>postconfig</application>
in your Unix command search path.
<application>initdb</application> invokes that program and that program then writes
<application>initdb</application> parameters to its standard output stream.
This third option is not a common thing to do, however.
</para>
</listitem>
</itemizedlist>
</para> </para>
<para> <para>
Command options always override parameters specified any other way. Although <application>initdb</application> will attempt to create the respective
The values returned by <application>postconfig</application> data directory, chances are that it won't have the permission to do so. Thus
override any environment variables, but your it is a good idea to create the data directory before running <application>initdb</application>
<application>postconfig</application> <emphasis>and</emphasis> to hand over the ownership of it to the database superuser.
program may base its output on the environment variables if you want
their values to be used.
</para> </para>
<para> <para>
The value that <application>postconfig</application> Note that if you use the <option>--username</option> you must give correct
outputs must have the format information about the name of the <emphasis>current</emphasis> user. If you don't
<synopsis> this will usually manifest itself in an error message about <literal>chmod</literal>
<replaceable>var1</replaceable>=<replaceable class="parameter">value1</replaceable> <replaceable class="parameter">var2</replaceable>=<replaceable class="parameter">value2</replaceable> ... failing on a file <filename>pg_pwd</filename>, because the backend silently
</synopsis> refuses to create it.
It can output nothing if it doesn't want to supply any parameters.
The <replaceable>var</replaceable> values are equal to
the corresponding environment variable
names. For example,
<programlisting>
PGDATA=/tmp/postgres_test
</programlisting>
has the
same effect as invoking <application>initdb</application>
with an environment variable called <envar>PGDATA</envar> whose value is
<filename>/tmp/postgres_test</filename>.
</para> </para>
</refsect1> </refsect1>
</refentry> </refentry>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.65 1999/12/16 20:09:56 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.66 1999/12/17 01:05:30 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -291,38 +291,31 @@ umask 077 ...@@ -291,38 +291,31 @@ umask 077
if [ -f "$PGDATA/PG_VERSION" ]; then if [ -f "$PGDATA/PG_VERSION" ]; then
if [ $template_only -eq 0 ]; then if [ $template_only -eq 0 ]; then
echo "$CMDNAME: error: File $PGDATA/PG_VERSION already exists." echo "$CMDNAME: The file $PGDATA/PG_VERSION already exists."
echo "This probably means initdb has already been run and the " echo "This probably means initdb has already been run and the"
echo "database system already exists." echo "database system already exists."
echo echo
echo "If you want to create a new database system, either remove " echo "If you want to create a new database system, either remove"
echo "the directory $PGDATA or run initdb with a --pgdata option " echo "the directory $PGDATA or run initdb with a --pgdata argument"
echo "other than $PGDATA." echo "other than $PGDATA."
exit 1 exit 1
fi fi
else else
if [ ! -d $PGDATA ]; then if [ ! -d $PGDATA ]; then
echo "Creating Postgres database system directory $PGDATA" echo "Creating database system directory $PGDATA"
echo mkdir $PGDATA || exit_nicely
mkdir $PGDATA else
if [ $? -ne 0 ]; then exit 5; fi echo "Fixing permissions on pre-existing data directory $PGDATA"
else chmod go-rwx $PGDATA || exit_nicely
echo "Fixing permissions on pre-existing $PGDATA"
echo
chmod go-rwx $PGDATA
if [ $? -ne 0 ]; then exit 5; fi
fi fi
if [ ! -d $PGDATA/base ]; then if [ ! -d $PGDATA/base ]; then
echo "Creating Postgres database system directory $PGDATA/base" echo "Creating database system directory $PGDATA/base"
echo mkdir $PGDATA/base || exit_nicely
mkdir $PGDATA/base
if [ $? -ne 0 ]; then exit 5; fi
fi fi
if [ ! -d $PGDATA/pg_xlog ]; then if [ ! -d $PGDATA/pg_xlog ]; then
echo "Creating Postgres database XLOG directory $PGDATA/pg_xlog" echo "Creating database XLOG directory $PGDATA/pg_xlog"
echo mkdir $PGDATA/pg_xlog || exit_nicely
mkdir $PGDATA/pg_xlog
if [ $? -ne 0 ]; then exit 5; fi
fi fi
fi fi
...@@ -330,8 +323,8 @@ fi ...@@ -330,8 +323,8 @@ fi
# Create the template1 database # Create the template1 database
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
rm -rf $PGDATA/base/template1 rm -rf $PGDATA/base/template1 || exit_nicely
mkdir $PGDATA/base/template1 mkdir $PGDATA/base/template1 || exit_nicely
if [ "$debug" -eq 1 ]; then if [ "$debug" -eq 1 ]; then
BACKEND_TALK_ARG="-d" BACKEND_TALK_ARG="-d"
...@@ -343,82 +336,51 @@ BACKENDARGS="-boot -C -F -D$PGDATA $BACKEND_TALK_ARG" ...@@ -343,82 +336,51 @@ BACKENDARGS="-boot -C -F -D$PGDATA $BACKEND_TALK_ARG"
FIRSTRUN="-boot -x -C -F -D$PGDATA $BACKEND_TALK_ARG" FIRSTRUN="-boot -x -C -F -D$PGDATA $BACKEND_TALK_ARG"
echo "Creating template database in $PGDATA/base/template1" echo "Creating template database in $PGDATA/base/template1"
[ "$debug" -ne 0 ] && echo "Running: postgres $BACKENDARGS template1" [ "$debug" -ne 0 ] && echo "Running: $PGPATH/postgres $FIRSTRUN template1"
cat $TEMPLATE \ cat $TEMPLATE \
| sed -e "s/postgres PGUID/$POSTGRES_SUPERUSERNAME $POSTGRES_SUPERUID/" \ | sed -e "s/PGUID/$POSTGRES_SUPERUSERID/g" \
-e "s/PGUID/$POSTGRES_SUPERUID/" \ | $PGPATH/postgres $FIRSTRUN template1 \
| postgres $FIRSTRUN template1 || exit_nicely
if [ $? -ne 0 ]; then $PGPATH/pg_version $PGDATA/base/template1 || exit_nicely
echo "$CMDNAME: could not create template database"
if [ $noclean -eq 0 ]; then
echo "$CMDNAME: cleaning up by wiping out $PGDATA/base/template1"
rm -rf $PGDATA/base/template1
else
echo "$CMDNAME: cleanup not done because noclean options was used."
fi
exit 1;
fi
echo
pg_version $PGDATA/base/template1
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Create the global classes, if requested. # Create the global classes, if requested.
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
if [ $template_only -eq 0 ]; then if [ $template_only -eq 0 ]; then
echo "Creating global classes in $PGDATA/base" echo "Creating global relations in $PGDATA/base"
[ "$debug" -ne 0 ] && echo "Running: postgres $BACKENDARGS template1" [ "$debug" -ne 0 ] && echo "Running: $PGPATH/postgres $BACKENDARGS template1"
cat $GLOBAL \ cat $GLOBAL \
| sed -e "s/postgres PGUID/$POSTGRES_SUPERUSERNAME $POSTGRES_SUPERUID/" \ | sed -e "s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \
-e "s/PGUID/$POSTGRES_SUPERUID/" \ -e "s/PGUID/$POSTGRES_SUPERUSERID/g" \
| postgres $BACKENDARGS template1 -e "s/PASSWORD/$Password/g" \
| $PGPATH/postgres $BACKENDARGS template1 \
if (test $? -ne 0) || exit_nicely
then
echo "$CMDNAME: could not create global classes."
if (test $noclean -eq 0); then
echo "$CMDNAME: cleaning up."
rm -rf $PGDATA
else
echo "$CMDNAME: cleanup not done (noclean mode set)."
fi
exit 1;
fi
echo $PGPATH/pg_version $PGDATA || exit_nicely
pg_version $PGDATA
cp $PG_HBA_SAMPLE $PGDATA/pg_hba.conf
cp $PG_GEQO_SAMPLE $PGDATA/pg_geqo.sample
echo "Adding template1 database to pg_database..." cp $PG_HBA_SAMPLE $PGDATA/pg_hba.conf || exit_nicely
cp $PG_GEQO_SAMPLE $PGDATA/pg_geqo.sample || exit_nicely
echo "open pg_database" > /tmp/create.$$ echo "Adding template1 database to pg_database"
echo "insert (template1 $POSTGRES_SUPERUID $MULTIBYTEID template1)" >> /tmp/create.$$
#echo "show" >> /tmp/create.$$
echo "close pg_database" >> /tmp/create.$$
[ "$debug" -ne 0 ] && echo "Running: postgres $BACKENDARGS template1 < /tmp/create.$$" echo "open pg_database" > $TEMPFILE
echo "insert (template1 $POSTGRES_SUPERUSERID $MULTIBYTEID template1)" >> $TEMPFILE
#echo "show" >> $TEMPFILE
echo "close pg_database" >> $TEMPFILE
postgres $BACKENDARGS template1 < /tmp/create.$$ [ "$debug" -ne 0 ] && echo "Running: $PGPATH/postgres $BACKENDARGS template1 < $TEMPFILE"
if [ $? -ne 0 ]; then $PGPATH/postgres $BACKENDARGS template1 < $TEMPFILE
echo "$CMDNAME: could not log template database" # Gotta remove that temp file before exiting on error.
if [ $noclean -eq 0 ]; then retval=$?
echo "$CMDNAME: cleaning up." if [ $noclean -eq 0 ]; then
rm -rf $PGDATA rm -f $TEMPFILE || exit_nicely
else
echo "$CMDNAME: cleanup not done (noclean mode set)."
fi
exit 1;
fi fi
rm -f /tmp/create.$$ [ $retval -ne 0 ] && exit_nicely
fi fi
echo echo
...@@ -427,102 +389,103 @@ PGSQL_OPT="-o /dev/null -O -F -Q -D$PGDATA" ...@@ -427,102 +389,103 @@ PGSQL_OPT="-o /dev/null -O -F -Q -D$PGDATA"
# Create a trigger so that direct updates to pg_shadow will be written # Create a trigger so that direct updates to pg_shadow will be written
# to the flat password file pg_pwd # to the flat password file pg_pwd
echo "CREATE TRIGGER pg_sync_pg_pwd AFTER INSERT OR UPDATE OR DELETE ON pg_shadow FOR EACH ROW EXECUTE PROCEDURE update_pg_pwd()" | postgres $PGSQL_OPT template1 > /dev/null echo "CREATE TRIGGER pg_sync_pg_pwd AFTER INSERT OR UPDATE OR DELETE ON pg_shadow" \
"FOR EACH ROW EXECUTE PROCEDURE update_pg_pwd()" \
| $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
# Create the initial pg_pwd (flat-file copy of pg_shadow) # Create the initial pg_pwd (flat-file copy of pg_shadow)
echo "COPY pg_shadow TO '$PGDATA/pg_pwd' USING DELIMITERS '\\t'" | \ echo "Writing password file."
postgres $PGSQL_OPT template1 > /dev/null echo "COPY pg_shadow TO '$PGDATA/pg_pwd' USING DELIMITERS '\\t'" \
| $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
# An ordinary COPY will leave the file too loosely protected. # An ordinary COPY will leave the file too loosely protected.
chmod go-rw $PGDATA/pg_pwd # Note: If you lied above and specified a --username different from the one
# you really are, this will manifest itself in this command failing because
echo "Creating public pg_user view" # of a missing file, since the COPY command above failed. It would perhaps
echo "CREATE TABLE pg_user ( \ # be better if postgres returned an error code.
usename name, \ chmod go-rw $PGDATA/pg_pwd || exit_nicely
usesysid int4, \
usecreatedb bool, \ echo "Creating view pg_user."
usetrace bool, \ echo "CREATE VIEW pg_user AS
usesuper bool, \ SELECT
usecatupd bool, \ usename,
passwd text, \ usesysid,
valuntil abstime);" | postgres $PGSQL_OPT template1 > /dev/null usecreatedb,
usetrace,
usesuper,
echo "CREATE RULE \"_RETpg_user\" AS ON SELECT TO pg_user DO INSTEAD \ usecatupd,
SELECT usename, usesysid, usecreatedb, usetrace, \ '********'::text as passwd,
usesuper, usecatupd, '********'::text as passwd, \ valuntil
valuntil FROM pg_shadow;" | \ FROM pg_shadow" \
postgres $PGSQL_OPT template1 > /dev/null | $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
echo "REVOKE ALL on pg_shadow FROM public" | \
postgres $PGSQL_OPT template1 > /dev/null echo "REVOKE ALL on pg_shadow FROM public" \
| $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
echo "Creating view pg_rules"
echo "CREATE TABLE pg_rules ( \ echo "Creating view pg_rules."
tablename name, \ echo "CREATE VIEW pg_rules AS
rulename name, \ SELECT
definition text);" | postgres $PGSQL_OPT template1 > /dev/null C.relname AS tablename,
R.rulename AS rulename,
echo "CREATE RULE \"_RETpg_rules\" AS ON SELECT TO pg_rules DO INSTEAD \ pg_get_ruledef(R.rulename) AS definition
SELECT C.relname AS tablename, \ FROM pg_rewrite R, pg_class C
R.rulename AS rulename, \ WHERE R.rulename !~ '^_RET'
pg_get_ruledef(R.rulename) AS definition \ AND C.oid = R.ev_class;" \
FROM pg_rewrite R, pg_class C \ | $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
WHERE R.rulename !~ '^_RET' \
AND C.oid = R.ev_class;" | \ echo "Creating view pg_views."
postgres $PGSQL_OPT template1 > /dev/null echo "CREATE VIEW pg_views AS
SELECT
echo "Creating view pg_views" C.relname AS viewname,
echo "CREATE TABLE pg_views ( \ pg_get_userbyid(C.relowner) AS viewowner,
viewname name, \ pg_get_viewdef(C.relname) AS definition
viewowner name, \ FROM pg_class C
definition text);" | postgres $PGSQL_OPT template1 > /dev/null WHERE C.relhasrules
AND EXISTS (
echo "CREATE RULE \"_RETpg_views\" AS ON SELECT TO pg_views DO INSTEAD \ SELECT rulename FROM pg_rewrite R
SELECT C.relname AS viewname, \ WHERE ev_class = C.oid AND ev_type = '1'
pg_get_userbyid(C.relowner) AS viewowner, \ )" \
pg_get_viewdef(C.relname) AS definition \ | $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
FROM pg_class C WHERE C.relhasrules AND \
EXISTS (SELECT rulename FROM pg_rewrite R \ echo "Creating view pg_tables."
WHERE ev_class = C.oid AND ev_type = '1');" | \ echo "CREATE VIEW pg_tables AS
postgres $PGSQL_OPT template1 > /dev/null SELECT
C.relname AS tablename,
echo "Creating view pg_tables" pg_get_userbyid(C.relowner) AS tableowner,
echo "CREATE TABLE pg_tables ( \ C.relhasindex AS hasindexes,
tablename name, \ C.relhasrules AS hasrules,
tableowner name, \ (C.reltriggers > 0) AS hastriggers
hasindexes bool, \ FROM pg_class C
hasrules bool, \ WHERE C.relkind IN ('r', 's')
hastriggers bool);" | postgres $PGSQL_OPT template1 > /dev/null AND NOT EXISTS (
SELECT rulename FROM pg_rewrite
echo "CREATE RULE \"_RETpg_tables\" AS ON SELECT TO pg_tables DO INSTEAD \ WHERE ev_class = C.oid AND ev_type = '1'
SELECT C.relname AS tablename, \ )" \
pg_get_userbyid(C.relowner) AS tableowner, \ | $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
C.relhasindex AS hasindexes, \
C.relhasrules AS hasrules, \ echo "Creating view pg_indexes."
(C.reltriggers > 0) AS hastriggers \ echo "CREATE VIEW pg_indexes AS
FROM pg_class C WHERE C.relkind IN ('r', 's') \ SELECT
AND NOT EXISTS (SELECT rulename FROM pg_rewrite \ C.relname AS tablename,
WHERE ev_class = C.oid AND ev_type = '1');" | \ I.relname AS indexname,
postgres $PGSQL_OPT template1 > /dev/null pg_get_indexdef(X.indexrelid) AS indexdef
FROM pg_index X, pg_class C, pg_class I
echo "Creating view pg_indexes" WHERE C.oid = X.indrelid
echo "CREATE TABLE pg_indexes ( \ AND I.oid = X.indexrelid" \
tablename name, \ | $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
indexname name, \
indexdef text);" | postgres $PGSQL_OPT template1 > /dev/null echo "Loading pg_description."
echo "COPY pg_description FROM '$TEMPLATE_DESCR'" \
echo "CREATE RULE \"_RETpg_indexes\" AS ON SELECT TO pg_indexes DO INSTEAD \ | $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
SELECT C.relname AS tablename, \ echo "COPY pg_description FROM '$GLOBAL_DESCR'" \
I.relname AS indexname, \ | $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
pg_get_indexdef(X.indexrelid) AS indexdef \ echo "Vacuuming database."
FROM pg_index X, pg_class C, pg_class I \ echo "VACUUM ANALYZE" \
WHERE C.oid = X.indrelid \ | $PGPATH/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
AND I.oid = X.indexrelid;" | \
postgres $PGSQL_OPT template1 > /dev/null echo
echo "$CMDNAME completed successfully. You can now start the database server."
echo "Loading pg_description" echo "($PGPATH/postmaster -D $PGDATA)"
echo "copy pg_description from '$TEMPLATE_DESCR'" | \ echo
postgres $PGSQL_OPT template1 > /dev/null
echo "copy pg_description from '$GLOBAL_DESCR'" | \ exit 0
postgres $PGSQL_OPT template1 > /dev/null
echo "vacuum analyze" | \
postgres $PGSQL_OPT template1 > /dev/null
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_shadow.h,v 1.4 1999/02/13 23:21:14 momjian Exp $ * $Id: pg_shadow.h,v 1.5 1999/12/17 01:05:31 momjian Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -67,39 +67,11 @@ typedef FormData_pg_shadow *Form_pg_shadow; ...@@ -67,39 +67,11 @@ typedef FormData_pg_shadow *Form_pg_shadow;
/* ---------------- /* ----------------
* initial contents of pg_shadow * initial contents of pg_shadow
*
* The uppercase quantities will be replaced at initdb time with
* user choices.
* ---------------- * ----------------
*/ */
DATA(insert OID = 0 ( postgres PGUID t t t t _null_ 2116994400 )); DATA(insert OID = 0 ( POSTGRES PGUID t t t t PASSWORD _null_ ));
BKI_BEGIN
#ifdef ALLOW_PG_GROUP
BKI_END
DATA(insert OID = 0 ( mike 799 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( mao 1806 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( hellers 1089 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( joey 5209 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( jolly 5443 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( sunita 6559 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( paxson 3029 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( marc 2435 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( jiangwu 6124 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( aoki 2360 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( avi 31080 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( kristin 1123 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( andrew 5229 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( nobuko 5493 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( hartzell 6676 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( devine 6724 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( boris 6396 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( sklower 354 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( marcel 31113 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( ginger 3692 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( woodruff 31026 t t t t _null_ 2116994400 ));
DATA(insert OID = 0 ( searcher 8261 t t t t _null_ 2116994400 ));
BKI_BEGIN
#endif /* ALLOW_PG_GROUP */
BKI_END
#endif /* PG_SHADOW_H */ #endif /* PG_SHADOW_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment