mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Add --template option to createdb script to allow access to WITH TEMPLATE
option of CREATE DATABASE. In pg_regress, create regression database from template0 to ensure that any installation-local cruft in template1 will not mess up the tests.
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
				
			|||||||
<!--
 | 
					<!--
 | 
				
			||||||
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createdb.sgml,v 1.16 2000/12/25 23:15:26 petere Exp $
 | 
					$Header: /cvsroot/pgsql/doc/src/sgml/ref/createdb.sgml,v 1.17 2001/02/18 17:53:54 tgl Exp $
 | 
				
			||||||
Postgres documentation
 | 
					Postgres documentation
 | 
				
			||||||
-->
 | 
					-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -41,7 +41,7 @@ Postgres documentation
 | 
				
			|||||||
	Specifies the hostname of the machine on which the 
 | 
						Specifies the hostname of the machine on which the 
 | 
				
			||||||
	<application>postmaster</application>
 | 
						<application>postmaster</application>
 | 
				
			||||||
	is running.  If host begins with a slash, it is used 
 | 
						is running.  If host begins with a slash, it is used 
 | 
				
			||||||
	as the directory for the unix domain socket.
 | 
						as the directory for the Unix-domain socket.
 | 
				
			||||||
       </para>
 | 
					       </para>
 | 
				
			||||||
      </listitem>
 | 
					      </listitem>
 | 
				
			||||||
     </varlistentry>
 | 
					     </varlistentry>
 | 
				
			||||||
@@ -98,17 +98,26 @@ Postgres documentation
 | 
				
			|||||||
      <term>-D, --location <replaceable class="parameter">datadir</replaceable></term>
 | 
					      <term>-D, --location <replaceable class="parameter">datadir</replaceable></term>
 | 
				
			||||||
      <listitem>
 | 
					      <listitem>
 | 
				
			||||||
       <para>
 | 
					       <para>
 | 
				
			||||||
	Specifies the alternative database location.  See also <xref
 | 
						Specifies the alternative location for the database.  See also <xref
 | 
				
			||||||
	linkend="app-initlocation">.
 | 
						linkend="app-initlocation">.
 | 
				
			||||||
       </para>
 | 
					       </para>
 | 
				
			||||||
      </listitem>
 | 
					      </listitem>
 | 
				
			||||||
     </varlistentry>
 | 
					     </varlistentry>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     <varlistentry>
 | 
				
			||||||
 | 
					      <term>-T, --template <replaceable class="parameter">template</replaceable></term>
 | 
				
			||||||
 | 
					      <listitem>
 | 
				
			||||||
 | 
					       <para>
 | 
				
			||||||
 | 
					        Specifies the template database from which to build this database.
 | 
				
			||||||
 | 
					       </para>
 | 
				
			||||||
 | 
					      </listitem>
 | 
				
			||||||
 | 
					     </varlistentry>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
     <varlistentry>
 | 
					     <varlistentry>
 | 
				
			||||||
      <term>-E, --encoding <replaceable class="parameter">encoding</replaceable></term>
 | 
					      <term>-E, --encoding <replaceable class="parameter">encoding</replaceable></term>
 | 
				
			||||||
      <listitem>
 | 
					      <listitem>
 | 
				
			||||||
       <para>
 | 
					       <para>
 | 
				
			||||||
        Specifies the character encoding scheme to be used with this database.
 | 
					        Specifies the character encoding scheme to be used in this database.
 | 
				
			||||||
       </para>
 | 
					       </para>
 | 
				
			||||||
      </listitem>
 | 
					      </listitem>
 | 
				
			||||||
     </varlistentry>
 | 
					     </varlistentry>
 | 
				
			||||||
@@ -140,6 +149,12 @@ Postgres documentation
 | 
				
			|||||||
    The options <literal>-h</literal>, <literal>-p</literal>, <literal>-U</literal>,
 | 
					    The options <literal>-h</literal>, <literal>-p</literal>, <literal>-U</literal>,
 | 
				
			||||||
    <literal>-W</literal>, and <literal>-e</literal> are passed on literally to
 | 
					    <literal>-W</literal>, and <literal>-e</literal> are passed on literally to
 | 
				
			||||||
    <xref linkend="app-psql">.
 | 
					    <xref linkend="app-psql">.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The options <literal>-D</literal>, <literal>-T</literal>, and
 | 
				
			||||||
 | 
					    <literal>-E</literal> are converted into options for the underlying
 | 
				
			||||||
 | 
					    SQL command <xref linkend="SQL-CREATEDATABASE"
 | 
				
			||||||
 | 
					    endterm="SQL-CREATEDATABASE-title">, which see for more information
 | 
				
			||||||
 | 
					    about them.
 | 
				
			||||||
   </para>
 | 
					   </para>
 | 
				
			||||||
  </refsect2>
 | 
					  </refsect2>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -168,7 +183,7 @@ Postgres documentation
 | 
				
			|||||||
      <listitem>
 | 
					      <listitem>
 | 
				
			||||||
       <para>
 | 
					       <para>
 | 
				
			||||||
       The comment/description for the database could not be created.
 | 
					       The comment/description for the database could not be created.
 | 
				
			||||||
       the database itself will have been created already. You can use the
 | 
					       The database itself will have been created already. You can use the
 | 
				
			||||||
       <acronym>SQL</acronym> command <command>COMMENT ON DATABASE</command> to
 | 
					       <acronym>SQL</acronym> command <command>COMMENT ON DATABASE</command> to
 | 
				
			||||||
       create the comment later on.
 | 
					       create the comment later on.
 | 
				
			||||||
       </para>
 | 
					       </para>
 | 
				
			||||||
@@ -199,10 +214,10 @@ Postgres documentation
 | 
				
			|||||||
   the <productname>Postgres</productname> interactive terminal
 | 
					   the <productname>Postgres</productname> interactive terminal
 | 
				
			||||||
   <xref linkend="APP-PSQL">. Thus, there is nothing
 | 
					   <xref linkend="APP-PSQL">. Thus, there is nothing
 | 
				
			||||||
   special about creating databases via this or other methods. This means
 | 
					   special about creating databases via this or other methods. This means
 | 
				
			||||||
   that the <application>psql</application> must be found by the script and that
 | 
					   that the <application>psql</application> program must be found by the script and that
 | 
				
			||||||
   a database server is running at the targeted host. Also, any default
 | 
					   a database server must be running at the targeted port. Also, any default
 | 
				
			||||||
   settings and environment variables available to <application>psql</application>
 | 
					   settings and environment variables available to <application>psql</application>
 | 
				
			||||||
   and the <application>libpq</application> front-end library do apply.
 | 
					   and the <application>libpq</application> front-end library will apply.
 | 
				
			||||||
  </para>
 | 
					  </para>
 | 
				
			||||||
 </refsect1>
 | 
					 </refsect1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,11 +7,12 @@
 | 
				
			|||||||
#    This program runs psql with the "-c" option to create
 | 
					#    This program runs psql with the "-c" option to create
 | 
				
			||||||
#    the requested database.
 | 
					#    the requested database.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# Copyright (c) 1994, Regents of the University of California
 | 
					# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
 | 
				
			||||||
 | 
					# Portions Copyright (c) 1994, Regents of the University of California
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# IDENTIFICATION
 | 
					# IDENTIFICATION
 | 
				
			||||||
#    $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.13 2001/01/21 05:16:45 momjian Exp $
 | 
					#    $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.14 2001/02/18 17:53:54 tgl Exp $
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
#-------------------------------------------------------------------------
 | 
					#-------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,6 +20,7 @@ CMDNAME=`basename $0`
 | 
				
			|||||||
PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"`
 | 
					PATHNAME=`echo $0 | sed "s,$CMDNAME\$,,"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MB=
 | 
					MB=
 | 
				
			||||||
 | 
					TEMPLATE=
 | 
				
			||||||
PSQLOPT=
 | 
					PSQLOPT=
 | 
				
			||||||
dbname=
 | 
					dbname=
 | 
				
			||||||
dbcomment=
 | 
					dbcomment=
 | 
				
			||||||
@@ -78,6 +80,15 @@ do
 | 
				
			|||||||
        --location=*)
 | 
					        --location=*)
 | 
				
			||||||
                dbpath=`echo "$1" | sed 's/^--location=//'`
 | 
					                dbpath=`echo "$1" | sed 's/^--location=//'`
 | 
				
			||||||
                ;;
 | 
					                ;;
 | 
				
			||||||
 | 
						--template|-T)
 | 
				
			||||||
 | 
							TEMPLATE="$2"
 | 
				
			||||||
 | 
							shift;;
 | 
				
			||||||
 | 
					        -T*)
 | 
				
			||||||
 | 
					                TEMPLATE=`echo "$1" | sed 's/^-T//'`
 | 
				
			||||||
 | 
					                ;;
 | 
				
			||||||
 | 
					        --template=*)
 | 
				
			||||||
 | 
					                TEMPLATE=`echo "$1" | sed 's/^--template=//'`
 | 
				
			||||||
 | 
					                ;;
 | 
				
			||||||
	--encoding|-E)
 | 
						--encoding|-E)
 | 
				
			||||||
		MB="$2"
 | 
							MB="$2"
 | 
				
			||||||
		shift;;
 | 
							shift;;
 | 
				
			||||||
@@ -111,6 +122,7 @@ if [ "$usage" ]; then
 | 
				
			|||||||
        echo
 | 
					        echo
 | 
				
			||||||
	echo "Options:"
 | 
						echo "Options:"
 | 
				
			||||||
	echo "  -D, --location=PATH             Alternative place to store the database"
 | 
						echo "  -D, --location=PATH             Alternative place to store the database"
 | 
				
			||||||
 | 
						echo "  -T, --template=TEMPLATE         Template database to copy"
 | 
				
			||||||
	echo "  -E, --encoding=ENCODING         Multibyte encoding for the database"
 | 
						echo "  -E, --encoding=ENCODING         Multibyte encoding for the database"
 | 
				
			||||||
	echo "  -h, --host=HOSTNAME             Database server host"
 | 
						echo "  -h, --host=HOSTNAME             Database server host"
 | 
				
			||||||
	echo "  -p, --port=PORT                 Database server port"
 | 
						echo "  -p, --port=PORT                 Database server port"
 | 
				
			||||||
@@ -149,10 +161,12 @@ fi
 | 
				
			|||||||
# escape the quotes
 | 
					# escape the quotes
 | 
				
			||||||
dbpath=`echo "$dbpath" | sed "s/'/\\\\\'/g"`
 | 
					dbpath=`echo "$dbpath" | sed "s/'/\\\\\'/g"`
 | 
				
			||||||
dbname=`echo "$dbname" | sed 's/\"/\\\"/g'`
 | 
					dbname=`echo "$dbname" | sed 's/\"/\\\"/g'`
 | 
				
			||||||
 | 
					TEMPLATE=`echo "$TEMPLATE" | sed 's/\"/\"\"/g'`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
withstring=
 | 
					withstring=
 | 
				
			||||||
[ "$dbpath" ] &&     withstring="$withstring LOCATION = '$dbpath'"
 | 
					[ "$dbpath" ] &&     withstring="$withstring LOCATION = '$dbpath'"
 | 
				
			||||||
[ "$MB" ] &&         withstring="$withstring ENCODING = '$MB'"
 | 
					[ "$MB" ] &&         withstring="$withstring ENCODING = '$MB'"
 | 
				
			||||||
 | 
					[ "$TEMPLATE" ] &&   withstring="$withstring TEMPLATE = \"$TEMPLATE\""
 | 
				
			||||||
[ "$withstring" ] && withstring=" WITH$withstring"
 | 
					[ "$withstring" ] && withstring=" WITH$withstring"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
${PATHNAME}psql $PSQLOPT -d template1 -c "CREATE DATABASE \"$dbname\"$withstring"
 | 
					${PATHNAME}psql $PSQLOPT -d template1 -c "CREATE DATABASE \"$dbname\"$withstring"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
#! /bin/sh
 | 
					#! /bin/sh
 | 
				
			||||||
# $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.18 2001/01/19 23:43:36 petere Exp $
 | 
					# $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.19 2001/02/18 17:53:55 tgl Exp $
 | 
				
			||||||
 | 
					
 | 
				
			||||||
me=`basename $0`
 | 
					me=`basename $0`
 | 
				
			||||||
: ${TMPDIR=/tmp}
 | 
					: ${TMPDIR=/tmp}
 | 
				
			||||||
@@ -420,10 +420,12 @@ fi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# ----------
 | 
					# ----------
 | 
				
			||||||
# Create the regression database
 | 
					# Create the regression database
 | 
				
			||||||
 | 
					# We use template0 so that any installation-local cruft in template1
 | 
				
			||||||
 | 
					# will not mess up the tests.
 | 
				
			||||||
# ----------
 | 
					# ----------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
message "creating database \"$dbname\""
 | 
					message "creating database \"$dbname\""
 | 
				
			||||||
"$bindir/createdb" $encoding_opt $psql_options "$dbname"
 | 
					"$bindir/createdb" $encoding_opt $psql_options --template template0 "$dbname"
 | 
				
			||||||
if [ $? -ne 0 ]; then
 | 
					if [ $? -ne 0 ]; then
 | 
				
			||||||
    echo "$me: createdb failed"
 | 
					    echo "$me: createdb failed"
 | 
				
			||||||
    (exit 2); exit
 | 
					    (exit 2); exit
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user