summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2002-02-24 23:27:58 +0000
committerTom Lane2002-02-24 23:27:58 +0000
commit3f11f589b9bb4e5eed8a9e3affd32b0ae42f12bc (patch)
tree4e16665c0016ab92f957e8a82b493ea07109caff
parent8bb49c1390281b863d24d8452510338a533a85bd (diff)
Add -O/--owner switch to createdb script, in support of new OWNER option
for CREATE DATABASE.
-rw-r--r--doc/src/sgml/ref/createdb.sgml27
-rw-r--r--src/bin/scripts/createdb12
2 files changed, 34 insertions, 5 deletions
diff --git a/doc/src/sgml/ref/createdb.sgml b/doc/src/sgml/ref/createdb.sgml
index e21bad741b..5d5ee47796 100644
--- a/doc/src/sgml/ref/createdb.sgml
+++ b/doc/src/sgml/ref/createdb.sgml
@@ -93,6 +93,15 @@ PostgreSQL documentation
</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>
<term>-D, --location <replaceable class="parameter">datadir</replaceable></term>
<listitem>
<para>
@@ -144,12 +153,13 @@ PostgreSQL documentation
</variablelist>
- The options <literal>-h</literal>, <literal>-p</literal>, <literal>-U</literal>,
- <literal>-W</literal>, and <literal>-e</literal> are passed on literally to
+ The options <option>-h</option>, <option>-p</option>, <option>-U</option>,
+ <option>-W</option>, and <option>-e</option> are passed on literally to
<xref linkend="app-psql">.
- The options <literal>-D</literal>, <literal>-T</literal>, and
- <literal>-E</literal> are converted into options for the underlying
+ The options <option>-O</option>, <option>-D</option>,
+ <option>-T</option>, and
+ <option>-E</option> are converted into options for the underlying
SQL command <xref linkend="SQL-CREATEDATABASE"
endterm="SQL-CREATEDATABASE-title">; see there for more information
about them.
@@ -202,7 +212,14 @@ PostgreSQL documentation
</title>
<para>
<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>
diff --git a/src/bin/scripts/createdb b/src/bin/scripts/createdb
index 5832ba648b..6b4fdc1c13 100644
--- a/src/bin/scripts/createdb
+++ b/src/bin/scripts/createdb
@@ -23,6 +23,7 @@ MB=
TEMPLATE=
PSQLOPT=
dbname=
+dbowner=
dbcomment=
dbpath=
@@ -71,6 +72,15 @@ do
PSQLOPT="$PSQLOPT -o /dev/null"
;;
# 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)
dbpath="$2"
shift;;
@@ -127,6 +137,7 @@ if [ "$usage" ]; then
echo " $CMDNAME [options] [dbname] [description]"
echo
echo "Options:"
+ echo " -O, --owner=OWNER Database user to own the new 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"
@@ -170,6 +181,7 @@ dbname=`echo "$dbname" | sed 's/\"/\\\"/g'`
TEMPLATE=`echo "$TEMPLATE" | sed 's/\"/\"\"/g'`
withstring=
+[ "$dbowner" ] && withstring="$withstring OWNER = \"$dbowner\""
[ "$dbpath" ] && withstring="$withstring LOCATION = '$dbpath'"
[ "$MB" ] && withstring="$withstring ENCODING = '$MB'"
[ "$TEMPLATE" ] && withstring="$withstring TEMPLATE = \"$TEMPLATE\""