Commit 75e5e20d authored by Tom Lane's avatar Tom Lane

Add -O/--owner switch to createdb script, in support of new OWNER option

for CREATE DATABASE.
parent 36d2cc1d
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createdb.sgml,v 1.24 2002/01/20 22:19:56 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/createdb.sgml,v 1.25 2002/02/24 23:27:57 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -92,6 +92,15 @@ PostgreSQL documentation ...@@ -92,6 +92,15 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>-O, --owner <replaceable class="parameter">owner</replaceable></term>
<listitem>
<para>
Specifies the database user who will own the new database.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term>-D, --location <replaceable class="parameter">datadir</replaceable></term> <term>-D, --location <replaceable class="parameter">datadir</replaceable></term>
<listitem> <listitem>
...@@ -144,12 +153,13 @@ PostgreSQL documentation ...@@ -144,12 +153,13 @@ PostgreSQL documentation
</variablelist> </variablelist>
The options <literal>-h</literal>, <literal>-p</literal>, <literal>-U</literal>, The options <option>-h</option>, <option>-p</option>, <option>-U</option>,
<literal>-W</literal>, and <literal>-e</literal> are passed on literally to <option>-W</option>, and <option>-e</option> are passed on literally to
<xref linkend="app-psql">. <xref linkend="app-psql">.
The options <literal>-D</literal>, <literal>-T</literal>, and The options <option>-O</option>, <option>-D</option>,
<literal>-E</literal> are converted into options for the underlying <option>-T</option>, and
<option>-E</option> are converted into options for the underlying
SQL command <xref linkend="SQL-CREATEDATABASE" SQL command <xref linkend="SQL-CREATEDATABASE"
endterm="SQL-CREATEDATABASE-title">; see there for more information endterm="SQL-CREATEDATABASE-title">; see there for more information
about them. about them.
...@@ -202,7 +212,14 @@ PostgreSQL documentation ...@@ -202,7 +212,14 @@ PostgreSQL documentation
</title> </title>
<para> <para>
<application>createdb</application> creates a new <productname>PostgreSQL</productname> <application>createdb</application> creates a new <productname>PostgreSQL</productname>
database. The user who executes this command becomes the database owner. database.
</para>
<para>
Normally, the database user who executes this command becomes the owner of
the new database.
However a different owner can be specified via the <option>-O</option>
option, if the executing user has appropriate privileges.
</para> </para>
<para> <para>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.19 2002/02/18 05:48:44 momjian Exp $ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.20 2002/02/24 23:27:58 tgl Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -23,6 +23,7 @@ MB= ...@@ -23,6 +23,7 @@ MB=
TEMPLATE= TEMPLATE=
PSQLOPT= PSQLOPT=
dbname= dbname=
dbowner=
dbcomment= dbcomment=
dbpath= dbpath=
...@@ -71,6 +72,15 @@ do ...@@ -71,6 +72,15 @@ do
PSQLOPT="$PSQLOPT -o /dev/null" PSQLOPT="$PSQLOPT -o /dev/null"
;; ;;
# options converted into SQL command # options converted into SQL command
--owner|-O)
dbowner="$2"
shift;;
-O*)
dbowner=`echo "$1" | sed 's/^-O//'`
;;
--owner=*)
dbowner=`echo "$1" | sed 's/^--owner=//'`
;;
--location|-D) --location|-D)
dbpath="$2" dbpath="$2"
shift;; shift;;
...@@ -127,6 +137,7 @@ if [ "$usage" ]; then ...@@ -127,6 +137,7 @@ if [ "$usage" ]; then
echo " $CMDNAME [options] [dbname] [description]" echo " $CMDNAME [options] [dbname] [description]"
echo echo
echo "Options:" echo "Options:"
echo " -O, --owner=OWNER Database user to own the new database"
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 " -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"
...@@ -170,6 +181,7 @@ dbname=`echo "$dbname" | sed 's/\"/\\\"/g'` ...@@ -170,6 +181,7 @@ dbname=`echo "$dbname" | sed 's/\"/\\\"/g'`
TEMPLATE=`echo "$TEMPLATE" | sed 's/\"/\"\"/g'` TEMPLATE=`echo "$TEMPLATE" | sed 's/\"/\"\"/g'`
withstring= withstring=
[ "$dbowner" ] && withstring="$withstring OWNER = \"$dbowner\""
[ "$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\"" [ "$TEMPLATE" ] && withstring="$withstring TEMPLATE = \"$TEMPLATE\""
......
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