Commit 240e4c98 authored by Bruce Momjian's avatar Bruce Momjian

New scripts for create/drop user/db from Peter Eisentraut

parent 21b69148
......@@ -8,7 +8,7 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/doc/src/sgml/Makefile,v 1.10 1999/08/08 04:18:29 thomas Exp $
# $Header: /cvsroot/pgsql/doc/src/sgml/Makefile,v 1.11 1999/12/04 04:53:14 momjian Exp $
#
#----------------------------------------------------------------------------
......@@ -67,10 +67,11 @@ vpath %.sgml ./ref
MANSOURCES= $(wildcard ref/*.sgml)
APPLICATIONS= createdb.sgml createuser.sgml \
createlang.sgml \
destroydb.sgml destroyuser.sgml \
destroylang.sgml \
APPLICATIONS= \
createdb.sgml
createuser.sgml \
dropdb.sgml
dropuser.sgml \
initdb.sgml initlocation.sgml \
ipcclean.sgml \
pg_dump.sgml \
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/docguide.sgml,v 1.22 1999/10/09 02:29:15 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/docguide.sgml,v 1.23 1999/12/04 04:53:14 momjian Exp $
Documentation Guide
Thomas Lockhart
......@@ -503,8 +503,8 @@ Status
<row><entry> ./doc/src/sgml/ref/createuser.sgml </entry><entry> New for v6.4 </entry></row>
<row><entry> ./doc/src/sgml/ref/declare.sgml </entry><entry> New for v6.4 </entry></row>
<row><entry> ./doc/src/sgml/ref/delete.sgml </entry><entry> New for v6.4 </entry></row>
<row><entry> ./doc/src/sgml/ref/destroydb.sgml </entry><entry> New for v6.4 </entry></row>
<row><entry> ./doc/src/sgml/ref/destroyuser.sgml </entry><entry> New for v6.4 </entry></row>
<row><entry> ./doc/src/sgml/ref/dropdb.sgml </entry><entry> Renamed for v7.0 </entry></row>
<row><entry> ./doc/src/sgml/ref/dropuser.sgml </entry><entry> Renamed for v7.0 </entry></row>
<row><entry> ./doc/src/sgml/ref/drop_aggregate.sgml </entry><entry> New for v6.4 </entry></row>
<row><entry> ./doc/src/sgml/ref/drop_database.sgml </entry><entry> New for v6.4 </entry></row>
<row><entry> ./doc/src/sgml/ref/drop_function.sgml </entry><entry> New for v6.4 </entry></row>
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.12 1999/10/01 15:24:09 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.13 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
Complete list of usable sgml source files in this directory.
-->
......@@ -100,11 +100,9 @@ Complete list of usable sgml source files in this directory.
<!-- these are in the "utilities" reference chapter -->
<!entity createdb system "createdb.sgml">
<!entity createlang system "createlang.sgml">
<!entity createuser system "createuser.sgml">
<!entity destroydb system "destroydb.sgml">
<!entity destroylang system "destroylang.sgml">
<!entity destroyuser system "destroyuser.sgml">
<!entity dropdb system "dropdb.sgml">
<!entity dropuser system "dropuser.sgml">
<!entity ecpgRef system "ecpg-ref.sgml">
<!entity initdb system "initdb.sgml">
<!entity initlocation system "initlocation.sgml">
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/commands.sgml,v 1.19 1999/10/01 15:24:09 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/commands.sgml,v 1.20 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
-->
......@@ -107,11 +107,9 @@ functions supported by <productname>Postgres</productname>.
</abstract>
&createdb;
&createlang;
&createuser;
&destroydb;
&destroylang;
&destroyuser;
&dropdb;
&dropuser;
&ecpgRef;
&pgAccess;
&pgAdmin;
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_database.sgml,v 1.9 1999/07/22 15:09:07 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_database.sgml,v 1.10 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
-->
......@@ -68,7 +68,7 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATIO
<variablelist>
<varlistentry>
<term><computeroutput>
CREATEDB
CREATE DATABASE
</computeroutput></term>
<listitem>
<para>
......@@ -184,16 +184,15 @@ comment from Olly; response from Thomas...
<computeroutput>Creating Postgres database system directory /home/olly/private_db/base</computeroutput>
<prompt>$</prompt> <userinput>psql olly</userinput>
<computeroutput>Welcome to the POSTGRESQL interactive sql monitor:
Please read the file COPYRIGHT for copyright terms of POSTGRESQL
type \? for help on slash commands
type \q to quit
type \g or terminate with semicolon to execute query
You are currently connected to the database: template1
<computeroutput>Welcome to psql, the PostgreSQL interactive terminal.
(Please type \copyright to see the distribution terms of PostgreSQL.)
Type \h for help with SQL commands,
\? for help on internal slash commands,
\q to quit,
\g or terminate with semicolon to execute query.
<prompt>olly=></prompt></computeroutput> <userinput>create database elsewhere with location = '/home/olly/private_db';</userinput>
<computeroutput>CREATEDB</computeroutput>
<computeroutput>CREATE DATABASE</computeroutput>
</programlisting>
</para>
</refsect1>
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_user.sgml,v 1.10 1999/11/30 03:57:23 momjian Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_user.sgml,v 1.11 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
-->
<refentry id="SQL-CREATEUSER">
<refmeta>
<refentrytitle>
<refentrytitle id="sql-createuser-title">
CREATE USER
</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
......
This diff is collapsed.
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createlang.sgml,v 1.1 1999/08/06 13:50:30 thomas Exp $
Postgres documentation
-->
<refentry id="APP-CREATELANG">
<refmeta>
<refentrytitle id="APP-CREATELANG-TITLE">
<application>createlang</application>
</refentrytitle>
<refmiscinfo>Application</refmiscinfo>
</refmeta>
<refnamediv>
<refname id="createlang">
<application>createlang</application>
</refname>
<refpurpose>
Add a new programming language to a <productname>Postgres</productname> database
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>1999-08-05</date>
</refsynopsisdivinfo>
<synopsis>
createlang [ <replaceable class="parameter">langname</replaceable> ]
createlang [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ]
[ <replaceable class="parameter">langname</replaceable> ]
</synopsis>
<refsect2 id="R2-APP-CREATELANG-1">
<title>
Inputs
</title>
<para>
<application>createlang</application> accepts the following command line arguments:
<variablelist>
<varlistentry>
<term><replaceable class="parameter">langname</replaceable></term>
<listitem>
<para>
Specifies the name of the backend programming language to be defined.
<application>createlang</application> will prompt for
<replaceable class="parameter">langname</replaceable>
if it is not specified on the command line.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<application>createlang</application> also accepts
the following command line arguments for connection parameters:
<variablelist>
<varlistentry>
<term>-h <replaceable class="parameter">host</replaceable></term>
<listitem>
<para>
Specifies the hostname of the machine on which the
<application>postmaster</application>
is running. Defaults to using a local Unix domain socket
rather than an IP connection.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-p <replaceable class="parameter">port</replaceable></term>
<listitem>
<para>
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the <application>postmaster</application>
is listening for connections. The port number defaults to 5432,
or the value of the <envar>PGPORT</envar>
environment variable (if set).
</para>
</listitem>
</varlistentry>
<!--
<varlistentry>
<term>-u</term>
<listitem>
<para>
Use password authentication.
Prompts for
<replaceable class="parameter">username</replaceable>
and <replaceable class="parameter">password</replaceable>.
</para>
</listitem>
</varlistentry>
-->
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-APP-CREATELANG-2">
<refsect2info>
<date>1998-10-04</date>
</refsect2info>
<title>
Outputs
</title>
<para>
<application>createlang</application> installs a new programming
language into a <productname>Postgres</productname> server,
so has not explicit external output.
</para>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-APP-CREATELANG-1">
<refsect1info>
<date>1998-10-04</date>
</refsect1info>
<title>
Description
</title>
<para>
<application>createlang</application> is a utility for adding a new
programming language to a
<productname>Postgres</productname> database.
<application>createlang</application> currently accepts two
languages, <literal>plsql</literal> and <literal>pltcl</literal>.
</para>
</refsect1>
<refsect1 id="R1-APP-CREATELANG-2">
<title>
Notes
</title>
<para>
See
<xref linkend="sql-createlanguage" endterm="sql-createlanguage-title">
for more details.
</para>
</refsect1>
<refsect1 id="R1-APP-CREATELANG-3">
<title>
Usage
</title>
<para>
To install <literal>pltcl</literal>:
<programlisting>
% createlang pltcl
</programlisting>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
This diff is collapsed.
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/destroydb.sgml,v 1.5 1999/07/22 15:09:10 thomas Exp $
Postgres documentation
-->
<refentry id="APP-DESTROYDB">
<refmeta>
<refentrytitle id="APP-DESTROYDB-TITLE">
<application>destroydb</application>
</refentrytitle>
<refmiscinfo>Application</refmiscinfo>
</refmeta>
<refnamediv>
<refname>
<application>destroydb</application>
</refname>
<refpurpose>
Remove an existing <productname>Postgres</productname> database
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>1999-07-20</date>
</refsynopsisdivinfo>
<synopsis>
destroydb [ <replaceable class="parameter">dbname</replaceable> ]
destroydb [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ]
[ -i ] [ <replaceable class="parameter">dbname</replaceable> ]
</synopsis>
<refsect2 id="R2-APP-DESTROYDB-1">
<refsect2info>
<date>1998-10-02</date>
</refsect2info>
<title>
Inputs
</title>
<para>
<variablelist>
<varlistentry>
<term>-h <replaceable class="parameter">host</replaceable></term>
<listitem>
<para>
Specifies the hostname of the machine on which the
<application>postmaster</application>
is running. Defaults to using a local Unix domain socket
rather than an IP connection.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-p <replaceable class="parameter">port</replaceable></term>
<listitem>
<para>
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the <application>postmaster</application>
is listening for connections. The port number defaults to 5432,
or the value of the <envar>PGPORT</envar>
environment variable (if set).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-i</term>
<listitem>
<para>
Run in interactive mode.
Prompts for confirmation before destroying a database.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">dbname</replaceable></term>
<listitem>
<para>
Specifies the name of the database to be destroyed. The database
must be one of the existing <productname>Postgres</productname> databases
in this installation.
<replaceable class="parameter">dbname</replaceable>
defaults to the value of the
<envar>USER</envar>
environment variable.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-APP-DESTROYDB-2">
<refsect2info>
<date>1998-10-02</date>
</refsect2info>
<title>
Outputs
</title>
<para>
<application>destroydb</application> will remove files from the
<filename><envar>PGDATA</envar>/<replaceable class="parameter">dbname</replaceable>/</filename>
data area for the existing database.
<variablelist>
<varlistentry>
<term><computeroutput>
Connection to database 'template1' failed.
connectDB() failed: Is the postmaster running and accepting connections
at 'UNIX Socket' on port '<replaceable class="parameter">port</replaceable>'?
destroydb: database destroy failed on <replaceable class="parameter">dbname</replaceable>.
</computeroutput></term>
<listitem>
<para>
<application>destroydb</application> could not attach to the
<application>postmaster</application>
process on the specified host and port. If you see this message,
ensure that the <application>postmaster</application>
is running on the proper host and that you have specified the proper
port. If your site uses an authentication system, ensure that you
have obtained the required authentication credentials.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
Connection to database 'template1' failed.
FATAL 1: SetUserId: user '<replaceable class="parameter">username</replaceable>' is not in 'pg_shadow'
destroydb: database destroy failed on <replaceable class="parameter">dbname</replaceable>.
</computeroutput></term>
<listitem>
<para>
You do not have a valid entry in the relation <literal>pg_shadow</literal>
and and will not be allowed to access <productname>Postgres</productname>.
Contact your <productname>Postgres</productname> administrator.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
ERROR: user '<replaceable class="parameter">username</replaceable>' is not allowed to create/destroy databases
destroydb: database destroy failed on <replaceable class="parameter">dbname</replaceable>.
</computeroutput></term>
<listitem>
<para>
You do not have permission to destroy (or create) databases.
Contact your <productname>Postgres</productname> site administrator.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
ERROR: destroydb: database '<replaceable class="parameter">dbname</replaceable>' does not exist.
destroydb: database destroy failed on <replaceable class="parameter">dbname</replaceable>.
</computeroutput></term>
<listitem>
<para>
The database to be removed does not have an entry in the
<literal>pg_database</literal> class.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
ERROR: destroydb: database '<replaceable class="parameter">dbname</replaceable>' is not owned by you.
destroydb: database destroy failed on <replaceable class="parameter">dbname</replaceable>.
</computeroutput></term>
<listitem>
<para>
You are not the Database Administrator (DBA) for the specified database.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
destroydb: database destroy failed on <replaceable class="parameter">dbname</replaceable>.
</computeroutput></term>
<listitem>
<para>
An internal error occurred in <application>psql</application>
or in the backend server. Ensure that your site administrator has
properly installed <productname>Postgres</productname>and initialized the site with
<application>initdb</application>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<note>
<para>
<application>destroydb</application> internally runs
<command>DESTROY DATABASE</command> from <application>psql</application>
while connected to the <literal>template1</literal> database.
</para>
</note>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-APP-DESTROYDB-1">
<refsect1info>
<date>1998-10-02</date>
</refsect1info>
<title>
Description
</title>
<para>
<application>destroydb</application> destroys an existing
<productname>Postgres</productname> database.
The person who executes this command must be
the database administrator, or <acronym>DBA</acronym>,
or must be the <productname>Postgres</productname> super-user.
The program runs silently; no confirmation message will be displayed.
After the database is destroyed, a Unix shell prompt will reappear.
</para>
<para>
All references to
the database are removed, including the directory containing this
database and its associated files.
</para>
<para>
<application>destroydb</application> is a shell script that invokes
<application>psql</application>.
Hence, a <application>postmaster</application>
process must be running on the database server host before
<application>destroydb</application>
is executed. The
<envar>PGOPTION</envar>
and
<envar>PGREALM</envar>
environment variables will be passed on to
<application>psql</application>
and processed as described in <xref endterm="app-psql-title" linkend="app-psql-title">.
</para>
</refsect1>
<refsect1 id="R1-APP-DESTROYDB-2">
<refsect1info>
<date>1998-10-02</date>
</refsect1info>
<title>
Usage
</title>
<para>
To destroy the database <literal>demo</literal>
using the postmaster on the local host, port 5432:
<programlisting>
destroydb demo
</programlisting>
</para>
<para>
To destroy the database <literal>demo</literal>
using the postmaster on host eden, port 5000:
<programlisting>
destroydb -p 5000 -h eden demo
</programlisting>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/destroylang.sgml,v 1.1 1999/08/06 13:50:30 thomas Exp $
Postgres documentation
-->
<refentry id="APP-DESTROYLANG">
<refmeta>
<refentrytitle id="APP-DESTROYLANG-TITLE">
<application>destroylang</application>
</refentrytitle>
<refmiscinfo>Application</refmiscinfo>
</refmeta>
<refnamediv>
<refname id="destroylang">
<application>destroylang</application>
</refname>
<refpurpose>
Add a programming language to a <productname>Postgres</productname> database
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>1999-08-05</date>
</refsynopsisdivinfo>
<synopsis>
destroylang [ <replaceable class="parameter">langname</replaceable> ]
destroylang [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ]
[ <replaceable class="parameter">langname</replaceable> ]
</synopsis>
<refsect2 id="R2-APP-DESTROYLANG-1">
<title>
Inputs
</title>
<para>
<application>destroylang</application> accepts the following command line arguments:
<variablelist>
<varlistentry>
<term><replaceable class="parameter">langname</replaceable></term>
<listitem>
<para>
Specifies the name of the backend programming language to be destroyed.
<application>destroylang</application> will prompt for
<replaceable class="parameter">langname</replaceable>
if it is not specified on the command line.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<application>destroylang</application> also accepts
the following command line arguments for connection parameters:
<variablelist>
<varlistentry>
<term>-h <replaceable class="parameter">host</replaceable></term>
<listitem>
<para>
Specifies the hostname of the machine on which the
<application>postmaster</application>
is running. Defaults to using a local Unix domain socket
rather than an IP connection.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-p <replaceable class="parameter">port</replaceable></term>
<listitem>
<para>
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the <application>postmaster</application>
is listening for connections. The port number defaults to 5432,
or the value of the <envar>PGPORT</envar>
environment variable (if set).
</para>
</listitem>
</varlistentry>
<!--
<varlistentry>
<term>-u</term>
<listitem>
<para>
Use password authentication.
Prompts for
<replaceable class="parameter">username</replaceable>
and <replaceable class="parameter">password</replaceable>.
</para>
</listitem>
</varlistentry>
-->
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-APP-DESTROYLANG-2">
<refsect2info>
<date>1998-10-04</date>
</refsect2info>
<title>
Outputs
</title>
<para>
<application>destroylang</application> removes an existing programming
language from a <productname>Postgres</productname> server,
so has not explicit external output.
</para>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-APP-DESTROYLANG-1">
<refsect1info>
<date>1998-10-04</date>
</refsect1info>
<title>
Description
</title>
<para>
<application>destroylang</application> is a utility for removing an
existing programming language from a
<productname>Postgres</productname> database.
<application>destroylang</application> currently accepts two
languages, <literal>plsql</literal> and <literal>pltcl</literal>.
</para>
</refsect1>
<refsect1 id="R1-APP-DESTROYLANG-2">
<title>
Notes
</title>
<para>
See
<xref linkend="sql-droplanguage" endterm="sql-droplanguage-title">
for more details.
</para>
</refsect1>
<refsect1 id="R1-APP-DESTROYLANG-3">
<title>
Usage
</title>
<para>
To remove <literal>pltcl</literal>:
<programlisting>
% destroylang pltcl
</programlisting>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/Attic/destroyuser.sgml,v 1.5 1999/07/22 15:09:10 thomas Exp $
Postgres documentation
-->
<refentry id="APP-DESTROYUSER">
<refmeta>
<refentrytitle id="APP-DESTROYUSER-TITLE">
<application>destroyuser</application>
</refentrytitle>
<refmiscinfo>Application</refmiscinfo>
</refmeta>
<refnamediv>
<refname>
<application>destroyuser</application>
</refname>
<refpurpose>
Destroy a <productname>Postgres</productname> user and associated databases
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>1999-07-20</date>
</refsynopsisdivinfo>
<synopsis>
destroyuser [ <replaceable class="parameter">username</replaceable> ]
destroyuser [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ]
[ <replaceable class="parameter">username</replaceable> ]
</synopsis>
<refsect2 id="R2-APP-DESTROYUSER-1">
<refsect2info>
<date>1998-10-02</date>
</refsect2info>
<title>
Inputs
</title>
<para>
<variablelist>
<varlistentry>
<term>-h <replaceable class="parameter">host</replaceable></term>
<listitem>
<para>
Specifies the hostname of the machine on which the
<application>postmaster</application>
is running. Defaults to using a local Unix domain socket
rather than an IP connection.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-p <replaceable class="parameter">port</replaceable></term>
<listitem>
<para>
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the <application>postmaster</application>
is listening for connections. The port number defaults to 5432,
or the value of the <envar>PGPORT</envar>
environment variable (if set).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">username</replaceable></term>
<listitem>
<para>
Specifies the name of the <productname>Postgres</productname> user to be removed.
This name must exist in the <productname>Postgres</productname> installation.
You will be prompted for a name if none is specified on the command line.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-APP-DESTROYUSER-2">
<refsect2info>
<date>1998-10-02</date>
</refsect2info>
<title>
Outputs
</title>
<para>
<application>destroyuser</application> will remove an entry in the
<literal>pg_user</literal> or <literal>pg_shadow</literal> system table,
and will remove all databases for which that user is the administrator
(<acronym>DBA</acronym>).
<variablelist>
<varlistentry>
<term><computeroutput>
Connection to database 'template1' failed.
connectDB() failed: Is the postmaster running and accepting connections
at 'UNIX Socket' on port '<replaceable class="parameter">port</replaceable>'?
destroyuser: database access failed.
</computeroutput></term>
<listitem>
<para>
<application>destroyuser</application> could not attach to the
<application>postmaster</application>
process on the specified host and port. If you see this message,
ensure that the <application>postmaster</application>
is running on the proper host and that you have specified the proper
port. If your site uses an authentication system, ensure that you
have obtained the required authentication credentials.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
Connection to database 'template1' failed.
FATAL 1: SetUserId: user '<replaceable class="parameter">username</replaceable>' is not in 'pg_shadow'
destroyuser: database access failed.
</computeroutput></term>
<listitem>
<para>
You do not have a valid entry in the relation <literal>pg_shadow</literal>
and and will not be allowed to access <productname>Postgres</productname>. Contact your
<productname>Postgres</productname> administrator.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
destroyuser: <replaceable class="parameter">username</replaceable> cannot delete users.
</computeroutput></term>
<listitem>
<para>
You do not have permission to delete users; contact your
<productname>Postgres</productname> site administrator.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
destroyuser: user "<replaceable class="parameter">username</replaceable>" already exists
</computeroutput></term>
<listitem>
<para>
The user to be added already has an entry in the
<literal>pg_shadow</literal> class.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
database access failed
</computeroutput></term>
<listitem>
<para>
An internal error occurred in <application>psql</application>
or in the backend server. Ensure that your site administrator has
properly installed <productname>Postgres</productname>and initialized the site with
<application>initdb</application>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
destroydb on <replaceable class="parameter">dbname</replaceable> failed - exiting
</computeroutput></term>
<listitem>
<para>
An internal error occurred in <application>psql</application>
or in the backend server. There was possibly a Unix permissions problem with the
specified database.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
delete of user <replaceable class="parameter">username</replaceable> was UNSUCCESSFUL
</computeroutput></term>
<listitem>
<para>
An internal error occurred in <application>psql</application>
or in the backend server.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<note>
<para>
<application>destroyuser</application> internally runs
<command>DROP USER</command> from <application>psql</application>
while connected to the <literal>template1</literal> database.
</para>
</note>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-APP-DESTROYUSER-1">
<refsect1info>
<date>1998-10-02</date>
</refsect1info>
<title>
Description
</title>
<para>
<application>destroyuser</application> removes an existing
<productname>Postgres</productname> user
and the databases for which that user
is database administrator.
Only users with <literal>usesuper</literal> set in
the <literal>pg_shadow</literal> class can destroy
<productname>Postgres</productname> users. As shipped,
the user <literal>postgres</literal> can remove users.
</para>
<para>
<application>destroyuser</application> is a shell script that invokes
<application>psql</application>.
Hence, a <application>postmaster</application>
process must be running on the database server host before
<application>destroyuser</application> is executed.
The
<envar>PGOPTION</envar>
and
<envar>PGREALM</envar>
environment variables will be passed on to
<application>psql</application>
and processed as described in <xref endterm="app-psql-title" linkend="app-psql-title">.
</para>
<para>
Once invoked, <application>destroyuser</application>
will warn you about the databases that will be destroyed in the
process and permit you to abort the removal of the user if desired.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_database.sgml,v 1.7 1999/08/06 13:50:30 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_database.sgml,v 1.8 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
-->
......@@ -59,7 +59,7 @@ DROP DATABASE <replaceable class="PARAMETER">name</replaceable>
<variablelist>
<varlistentry>
<term><computeroutput>
DESTROYDB
DROP DATABASE
</computeroutput></term>
<listitem>
<para>
......@@ -116,14 +116,13 @@ WARN: destroydb: database "<replaceable class="parameter">name</replaceable>" do
<para>
This query cannot be executed while connected to the target
database. It is usually preferable to use
<xref linkend="app-destroydb" endterm="app-destroydb-title">
instead.
database. Thus, it might be more convenient to use
<xref linkend="app-dropdb" endterm="app-dropdb-title">
from the shell instead.
</para>
<para>
Refer to
<xref linkend="app-createdb" endterm="app-createdb-title"> and
<xref linkend="sql-createdatabase" endterm="sql-createdatabase-title">
for information on how to create a database.
</para>
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_user.sgml,v 1.7 1999/07/22 15:09:11 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_user.sgml,v 1.8 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
-->
......@@ -95,7 +95,7 @@ ERROR: removeUser: user "<replaceable class="parameter">name</replaceable>" does
along with any databases owned by the user. It
does not remove tables, views, or triggers owned by the
named user in databases not owned by the user. This statement
can be used in place of the <application>destroyuser</application>
can be used in place of the <application>dropuser</application>
script, regardless of how the user was created.
</para>
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/dropdb.sgml,v 1.1 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
-->
<refentry id="APP-DROPDB">
<refmeta>
<refentrytitle id="APP-DROPDB-TITLE">
<application>dropdb</application>
</refentrytitle>
<refmiscinfo>Application</refmiscinfo>
</refmeta>
<refnamediv>
<refname>
<application>dropdb</application>
</refname>
<refpurpose>
Remove an existing <productname>PostgreSQL</productname> database
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>1999-11-07</date>
</refsynopsisdivinfo>
<synopsis>
dropdb [ <replaceable class="parameter">options</replaceable> ] <replaceable class="parameter">dbname</replaceable>
</synopsis>
<refsect2 id="R2-APP-DROPDB-1">
<refsect2info>
<date>1999-11-07</date>
</refsect2info>
<title>
Inputs
</title>
<para>
<variablelist>
<varlistentry>
<term>-h, --host <replaceable class="parameter">host</replaceable></term>
<listitem>
<para>
Specifies the hostname of the machine on which the
<application>postmaster</application>
is running.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-p, --port <replaceable class="parameter">port</replaceable></term>
<listitem>
<para>
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the <application>postmaster</application>
is listening for connections.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-U, --username <replaceable class="parameter">username</replaceable></term>
<listitem>
<para>
Username to connect as.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-W, --password</term>
<listitem>
<para>
Force password prompt.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-e, --echo</term>
<listitem>
<para>
Echo the queries that <application>dropdb</application> generates
and sends to the backend.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-q, --quiet</term>
<listitem>
<para>
Do not display a response.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-i, --interactive</term>
<listitem>
<para>
Issues a verification prompt before doing anything destructive.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">dbname</replaceable></term>
<listitem>
<para>
Specifies the name of the database to be removed. The database
must be one of the existing <productname>PostgreSQL</productname> databases
in this installation.
</para>
</listitem>
</varlistentry>
</variablelist>
The options <literal>-h</literal>, <literal>-p</literal>, <literal>-U</literal>,
<literal>-W</literal>, and <literal>-e</literal> are passed on literally to
<xref linkend="APP-PSQL" endterm="APP-PSQL-title">.
</para>
</refsect2>
<refsect2 id="R2-APP-DROPDB-2">
<refsect2info>
<date>1998-10-02</date>
</refsect2info>
<title>
Outputs
</title>
<para>
<variablelist>
<varlistentry>
<term><computeroutput>DROP DATABASE</computeroutput></term>
<listitem>
<para>The database was successfully removed.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>dropdb: Database removal failed.</computeroutput></term>
<listitem>
<para>Something didn't work out.</para>
</listitem>
</varlistentry>
</variablelist>
If there is an error condition, the backend error message will be displayed.
See <xref linkend="SQL-DROPDATABASE" endterm="SQL-DROPDATABASE-title">
and <xref linkend="APP-PSQL" endterm="APP-PSQL-title"> for possibilities.
</para>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-APP-DROPDB-1">
<refsect1info>
<date>1998-10-02</date>
</refsect1info>
<title>
Description
</title>
<para>
<application>dropdb</application> destroys an existing
<productname>PostgreSQL</productname> database.
The user who executes this command must be a database
superuser or the owner of the database.
</para>
<para>
<application>dropdb</application> is a shell script wrapper around the
<acronym>SQL</acronym> command
<xref linkend="SQL-DROPDATABASE" endterm="SQL-DROPDATABASE-title"> via
the <productname>PostgreSQL</productname> interactive terminal
<xref linkend="APP-PSQL" endterm="APP-PSQL-title">. Thus, there is nothing
special about dropping databases via this or other methods. This means
that the <application>psql</application> must be found by the script and that
a database server is running at the targeted host. Also, any default
settings and environment variables available to <application>psql</application>
and the <application>libpq</application> front-end library do apply.
</para>
</refsect1>
<refsect1 id="R1-APP-DROPDB-2">
<refsect1info>
<date>1999-11-07</date>
</refsect1info>
<title>
Usage
</title>
<para>
To destroy the database <literal>demo</literal>
on the default database server:
<programlisting>
$ <userinput>dropdb demo</userinput>
DROP DATABASE
</programlisting>
</para>
<para>
To destroy the database <literal>demo</literal>
using the postmaster on host eden, port 5000, with verification
and a peek at the underlying query:
<programlisting>
$ <userinput>dropdb -p 5000 -h eden -i -e demo</userinput>
Database "demo" will be permanently deleted.
Are you sure? (y/n) <userinput>y</userinput>
QUERY: DROP DATABASE "demo"
DROP DATABASE
</programlisting>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/dropuser.sgml,v 1.1 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
-->
<refentry id="APP-DROPUSER">
<refmeta>
<refentrytitle id="APP-DROPUSER-TITLE">
<application>dropuser</application>
</refentrytitle>
<refmiscinfo>Application</refmiscinfo>
</refmeta>
<refnamediv>
<refname>
<application>dropuser</application>
</refname>
<refpurpose>
Drops (removes) a <productname>Postgres</productname> user
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>1999-11-07</date>
</refsynopsisdivinfo>
<synopsis>
dropuser [ <replaceable class="parameter">options</replaceable> ] [ <replaceable class="parameter">username</replaceable> ]
</synopsis>
<refsect2 id="R2-APP-DROPUSER-1">
<refsect2info>
<date>1999-11-07</date>
</refsect2info>
<title>
Inputs
</title>
<para>
<variablelist>
<varlistentry>
<term>-h, --host <replaceable class="parameter">host</replaceable></term>
<listitem>
<para>
Specifies the hostname of the machine on which the
<application>postmaster</application>
is running.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-p, --port <replaceable class="parameter">port</replaceable></term>
<listitem>
<para>
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the <application>postmaster</application>
is listening for connections.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-e, --echo</term>
<listitem>
<para>
Echo the queries that <application>createdb</application> generates
and sends to the backend.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-q, --quiet</term>
<listitem>
<para>
Do not display a response.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-i, --interactive</term>
<listitem>
<para>
Prompt for confirmation before actually removing the user.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">username</replaceable></term>
<listitem>
<para>
Specifies the name of the <productname>PostgreSQL</productname> user to be removed.
This name must exist in the <productname>Postgres</productname> installation.
You will be prompted for a name if none is specified on the command line.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The options <literal>-h</literal>, <literal>-p</literal>, and <literal>-e</literal>,
are passed on literally to <xref linkend="APP-PSQL" endterm="APP-PSQL-title">. If you
need the <application>psql</application> options <literal>-U</literal> and
<literal>-W</literal> as well, you can uncomment the
respective lines in the source. They are disabled by default because of the potential
conceptual confusion between existing and new users.
</para>
</refsect2>
<refsect2 id="R2-APP-DROPUSER-2">
<refsect2info>
<date>1999-11-07</date>
</refsect2info>
<title>
Outputs
</title>
<para>
<variablelist>
<varlistentry>
<term><computeroutput>DROP USER</computeroutput></term>
<listitem>
<para>
All is well.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>dropuser: Deletion of user "<replaceable class="parameter">username</replaceable>" failed.</computeroutput></term>
<listitem>
<para>
Something went wrong. The user was not removed.
</para>
</listitem>
</varlistentry>
</variablelist>
If there is an error condition, the backend error message will be displayed.
See <xref linkend="SQL-DROPUSER" endterm="SQL-DROPUSER-title">
and <xref linkend="APP-PSQL" endterm="APP-PSQL-title"> for possibilities.
</para>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-APP-DROPUSER-1">
<refsect1info>
<date>1999-11-07</date>
</refsect1info>
<title>
Description
</title>
<para>
<application>dropuser</application> removes an existing
<productname>PostgreSQL</productname> user
<emphasis>and</emphasis> the databases which that user owned.
Only users with <literal>usesuper</literal> set in
the <literal>pg_shadow</literal> class can destroy
<productname>PostgreSQL</productname> users.
</para>
<para>
<application>dropuser</application> is a shell script wrapper around the
<acronym>SQL</acronym> command
<xref linkend="SQL-DROPUSER" endterm="SQL-DROPUSER-title"> via
the <productname>PostgreSQL</productname> interactive terminal
<xref linkend="APP-PSQL" endterm="APP-PSQL-title">. Thus, there is nothing
special about removing users via this or other methods. This means
that the <application>psql</application> must be found by the script and that
a database server is running at the targeted host. Also, any default
settings and environment variables available to <application>psql</application>
and the <application>libpq</application> front-end library do apply.
</para>
</refsect1>
<refsect1 id="R1-APP-DROPUSER-2">
<refsect1info>
<date>1999-11-07</date>
</refsect1info>
<title>
Usage
</title>
<para>
To remove user <literal>joe</literal>
from the default database server:
<programlisting>
$ <userinput>dropuser joe</userinput>
DROP USER
</programlisting>
</para>
<para>
To remove user <literal>joe</literal>
using the postmaster on host eden, port 5000, with verification
and a peek at the underlying query:
<programlisting>
$ <userinput>dropuser -p 5000 -h eden -i -e joe</userinput>
User "joe" and any owned databases will be permanently deleted.
Are you sure? (y/n) <userinput>y</userinput>
QUERY: DROP USER "joe"
DROP USER
</programlisting>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
......@@ -7,16 +7,15 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.18 1999/05/20 16:49:59 wieck Exp $
# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.19 1999/12/04 04:53:16 momjian Exp $
#
#-------------------------------------------------------------------------
SRCDIR= ..
include ../Makefile.global
DIRS = pg_id pg_version psql pg_dump pg_passwd cleardbdir createdb \
createlang createuser destroydb destroylang destroyuser initdb \
vacuumdb initlocation ipcclean
DIRS = pg_id pg_version psql pg_dump pg_passwd cleardbdir \
createlang destroylang initdb initlocation ipcclean
ifdef MULTIBYTE
DIRS += pg_encoding
......
#!/bin/sh
#-------------------------------------------------------------------------
#
# createdb.sh--
# create a postgres database
#
# this program runs the monitor with the "-c" option to create
# the requested database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.12 1999/11/18 21:47:37 momjian Exp $
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
MBENABLED=__MULTIBYTE__
MB=
if [ -z "$USER" ]; then
if [ -z "$LOGNAME" ]; then
if [ -z "`whoami`" ]; then
echo "$CMDNAME: cannot determine user name"
exit 1
fi
else
USER=$LOGNAME
export USER
fi
fi
dbname=$USER
PASSWDOPT="";
while test -n "$1"
do
case $1 in
--help) usage=1;;
-a) AUTHSYS=$2; shift;;
-h) PGHOST=$2; shift;;
-p) PGPORT=$2; shift;;
-u) PASSWDOPT=$1;;
-D) dbpath=$2; shift;;
-E)
if [ -z "$MBENABLED" ];then
echo "$CMDNAME: you need to turn on MB compile time option"
exit 1
fi
MB=$2
MBID=`pg_encoding $MB`
if [ -z "$MBID" ];then
echo "$CMDNAME: $MB is not a valid encoding name"
exit 1
fi
shift;;
-*) echo "$CMDNAME: unrecognized parameter $1"; usage=1;;
*) dbname=$1;;
esac
shift;
done
if [ "$usage" ]; then
if [ -z "$MBENABLED" ];then
echo "Usage: $CMDNAME -a <authtype> -h <server> -p <portnumber> -D <location> [dbname]"
exit 1
else
echo "Usage: $CMDNAME -a <authtype> -h <server> -p <portnumber> -D <location> -E <encoding> [dbname]"
exit 1
fi
fi
if [ -z "$AUTHSYS" ]; then
AUTHOPT=""
else
AUTHOPT="-a $AUTHSYS"
fi
if [ -z "$PGHOST" ]; then
PGHOSTOPT=""
else
PGHOSTOPT="-h $PGHOST"
fi
if [ -z "$PGPORT" ]; then
PGPORTOPT=""
else
PGPORTOPT="-p $PGPORT"
fi
if [ -z "$dbpath" ]; then
location=""
else
# if [ ! -d "$dbpath"/base ]; then
# echo "$CMDNAME: database creation failed on $dbname."
# echo "directory $dbpath/base not found."
# exit 1
# fi
location="with location = '$dbpath'"
fi
if [ -z "$MBENABLED" -o -z "$MB" ]; then
encoding=""
else
encoding="encoding = '$MB'"
if [ -z "$location" ];then
encoding="with $encoding"
fi
fi
psql $PASSWDOPT -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "create database \"$dbname\" $location $encoding" template1
if [ $? -ne 0 ]; then
echo "$CMDNAME: database creation failed on $dbname."
exit 1
fi
exit 0
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for bin/createuser
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/createuser/Attic/Makefile,v 1.9 1998/08/22 05:19:16 momjian Exp $
#
#-------------------------------------------------------------------------
SRCDIR= ../..
include ../../Makefile.global
SEDSCRIPT= \
-e "s^PG_OPT_DASH_N_PARAM^$(DASH_N)^g" \
-e "s^PG_OPT_BACKSLASH_C_PARAM^$(BACKSLASH_C)^g"
all: createuser
createuser: createuser.sh
sed $(SEDSCRIPT) <createuser.sh >createuser
install: createuser
$(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
clean:
rm -f createuser
dep depend:
#!/bin/sh
#-------------------------------------------------------------------------
#
# createuser.sh--
# utility for creating a user in the POSTGRES database
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/createuser/Attic/createuser.sh,v 1.13 1999/09/27 16:44:56 momjian Exp $
#
# Note - this should NOT be setuid.
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
SYSID=
CANADDUSER=
CANCREATE=
if [ -z "$USER" ]; then
if [ -z "$LOGNAME" ]; then
if [ -z "`whoami`" ]; then
echo "$CMDNAME: cannot determine user name"
exit 1
fi
else
USER=$LOGNAME
export USER
fi
fi
while [ -n "$1" ]
do
case $1 in
-a) AUTHSYS=$2; shift;;
-h) PGHOST=$2; shift;;
-p) PGPORT=$2; shift;;
-d) CANCREATE=t;;
-D) CANCREATE=f;;
-u) CANADDUSER=t;;
-U) CANADDUSER=f;;
-i) SYSID=$2; shift;;
*) NEWUSER=$1;;
esac
shift;
done
if [ -z "$AUTHSYS" ]; then
AUTHOPT=""
else
AUTHOPT="-a $AUTHSYS"
fi
if [ -z "$PGHOST" ]; then
PGHOSTOPT=""
else
PGHOSTOPT="-h $PGHOST"
fi
if [ -z "$PGPORT" ]; then
PGPORTOPT=""
else
PGPORTOPT="-p $PGPORT"
fi
PARGS="-tq $AUTHOPT $PGHOSTOPT $PGPORTOPT"
#
# generate the first part of the actual monitor command
#
PSQL="psql $PARGS"
#
# see if user $USER is a superuser
#
QUERY="select usesuper from pg_user where usename = '$USER' "
#echo $QUERY
ADDUSER=`$PSQL -c "$QUERY" template1`
if [ $? -ne 0 ]
then
echo "$CMDNAME: database access failed." 1>&2
exit 1
fi
if [ -n "$ADDUSER" ]
then
if [ $ADDUSER != "t" ]
then
echo "$CMDNAME: $USER cannot create users." 1>&2
exit 1
fi
fi
#
# get the user name of the new user. Make sure it doesn't already exist.
#
if [ -z "$NEWUSER" ]
then
echo PG_OPT_DASH_N_PARAM "Enter name of user to add ---> PG_OPT_BACKSLASH_C_PARAM"
read NEWUSER
fi
QUERY="select usesysid from pg_user where usename = '$NEWUSER' "
RES=`$PSQL -c "$QUERY" template1`
if [ $? -ne 0 ]
then
echo "$CMDNAME: database access failed." 1>&2
exit 1
fi
if [ -n "$RES" ]
then
echo "$CMDNAME: user "\"$NEWUSER\"" already exists" 1>&2
exit 1
fi
done=0
#
# get the system id of the new user. Make sure it is unique.
#
while [ $done -ne 1 ]
do
DEFSYSID=`pg_id $NEWUSER 2>/dev/null`
if [ $? -eq 0 ]; then
DEFMSG=" or RETURN to use unix user ID: $DEFSYSID"
else
DEFMSG=
DEFSYSID=
fi
while [ -z "$SYSID" ]
do
echo PG_OPT_DASH_N_PARAM "Enter user's postgres ID$DEFMSG -> PG_OPT_BACKSLASH_C_PARAM"
read SYSID
[ -z "$SYSID" ] && SYSID=$DEFSYSID;
SYSIDISNUM=`echo $SYSID | egrep '^[0-9]+$'`
if [ -z "$SYSIDISNUM" ]
then
echo "$CMDNAME: the postgres ID must be a number"
SYSID=
fi
done
QUERY="select usename from pg_user where usesysid = '$SYSID'::int4"
RES=`$PSQL -c "$QUERY" template1`
if [ $? -ne 0 ]
then
echo "$CMDNAME: database access failed."
exit 1
fi
if [ -n "$RES" ]
then
echo
echo "$CMDNAME: $SYSID already belongs to $RES, pick another"
DEFMSG= DEFSYSID= SYSID=
else
done=1
fi
done
#
# get the rest of the user info...
#
#
# can the user create databases?
#
if [ -z "$CANCREATE" ]
then
yn=f
while [ "$yn" != y -a "$yn" != n ]
do
echo PG_OPT_DASH_N_PARAM "Is user \"$NEWUSER\" allowed to create databases (y/n) PG_OPT_BACKSLASH_C_PARAM"
read yn
done
if [ "$yn" = y ]
then
CANCREATE=t
else
CANCREATE=f
fi
fi
#
# can the user add users?
#
if [ -z "$CANADDUSER" ]
then
yn=f
while [ "$yn" != y -a "$yn" != n ]
do
echo PG_OPT_DASH_N_PARAM "Is user \"$NEWUSER\" a superuser? (y/n) PG_OPT_BACKSLASH_C_PARAM"
read yn
done
if (test "$yn" = y)
then
CANADDUSER=t
else
CANADDUSER=f
fi
fi
if [ "$CANCREATE" = "t" -o "$CANADDUSER" = "t" ]
then CANCATUPD="t"
else CANCATUPD="f"
fi
QUERY="insert into pg_shadow \
(usename, usesysid, usecreatedb, usetrace, usesuper, usecatupd) \
values \
('$NEWUSER', $SYSID, '$CANCREATE', 'f', '$CANADDUSER','$CANCATUPD')"
RES=`$PSQL -c "$QUERY" template1`
#
# Wrap things up. If the user was created successfully, AND the user was
# NOT allowed to create databases, remind the DBA to create one for the user.
#
if [ $? -ne 0 ]
then
echo "$CMDNAME: $NEWUSER was NOT added successfully"
else
echo "$CMDNAME: $NEWUSER was successfully added"
if [ "$CANCREATE" = f ]
then
echo PG_OPT_DASH_N_PARAM "Shall I create a database for \"$NEWUSER\" (y/n) PG_OPT_BACKSLASH_C_PARAM"
read yn
if [ "$yn" = y ]
then
createdb $NEWUSER
else
echo "don't forget to create a database for $NEWUSER"
fi
fi
fi
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for bin/destroydb
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/destroydb/Attic/Makefile,v 1.8 1998/04/06 16:49:51 momjian Exp $
#
#-------------------------------------------------------------------------
SRCDIR= ../..
include ../../Makefile.global
all: destroydb
destroydb: destroydb.sh
cp destroydb.sh destroydb
install: destroydb
$(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
clean:
rm -f destroydb
dep depend:
#!/bin/sh
#-------------------------------------------------------------------------
#
# destroydb.sh--
# destroy a postgres database
#
# this program runs the monitor with the ? option to destroy
# the requested database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/destroydb/Attic/destroydb.sh,v 1.9 1999/11/18 21:47:37 momjian Exp $
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
if [ -z "$USER" ]; then
if [ -z "$LOGNAME" ]; then
if [ -z "`whoami`" ]; then
echo "$CMDNAME: cannot determine user name"
exit 1
fi
else
USER=$LOGNAME
export USER
fi
fi
dbname=$USER
forcedel=t
while [ -n "$1" ]
do
case $1 in
-i) forcedel=f;;
-a) AUTHSYS=$2; shift;;
-h) PGHOST=$2; shift;;
-p) PGPORT=$2; shift;;
*) dbname=$1;;
esac
shift;
done
if [ -z "$AUTHSYS" ]; then
AUTHOPT=""
else
AUTHOPT="-a $AUTHSYS"
fi
if [ -z "$PGHOST" ]; then
PGHOSTOPT=""
else
PGHOSTOPT="-h $PGHOST"
fi
if [ -z "$PGPORT" ]; then
PGPORTOPT=""
else
PGPORTOPT="-p $PGPORT"
fi
answer=y
if [ "$forcedel" = f ]
then
answer=f
while [ "$answer" != y -a "$answer" != n ]
do
echo "Database '$dbname' will be permanently deleted."
echo -n "Are you sure? (y/n) "
read answer
done
fi
if [ "$answer" = y ]
then
psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "drop database \"$dbname\"" template1
if [ $? -ne 0 ]
then echo "$CMDNAME: database destroy failed on $dbname."
exit 1
fi
fi
exit 0
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for bin/destroyuser
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/destroyuser/Attic/Makefile,v 1.9 1998/08/22 05:19:19 momjian Exp $
#
#-------------------------------------------------------------------------
SRCDIR= ../..
include ../../Makefile.global
SEDSCRIPT= \
-e "s^PG_OPT_DASH_N_PARAM^$(DASH_N)^g" \
-e "s^PG_OPT_BACKSLASH_C_PARAM^$(BACKSLASH_C)^g"
all: destroyuser
destroyuser: destroyuser.sh
sed $(SEDSCRIPT) <destroyuser.sh >destroyuser
install: destroyuser
$(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
clean:
rm -f destroyuser
dep depend:
#!/bin/sh
#-------------------------------------------------------------------------
#
# destroyuser.sh--
# utility for destroying a user from the POSTGRES database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/destroyuser/Attic/destroyuser.sh,v 1.11 1999/03/14 16:00:55 momjian Exp $
#
# Note - this should NOT be setuid.
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
if [ -z "$USER" ]; then
if [ -z "$LOGNAME" ]; then
if [ -z "`whoami`" ]; then
echo "$CMDNAME: cannot determine user name"
exit 1
fi
else
USER=$LOGNAME
export USER
fi
fi
while (test -n "$1")
do
case $1 in
-a) AUTHSYS=$2; shift;;
-h) PGHOST=$2; shift;;
-p) PGPORT=$2; shift;;
*) DELUSER=$1;;
esac
shift;
done
if [ -z "$AUTHSYS" ]; then
AUTHOPT=""
else
AUTHOPT="-a $AUTHSYS"
fi
if [ -z "$PGHOST" ]; then
PGHOSTOPT=""
else
PGHOSTOPT="-h $PGHOST"
fi
if [ -z "$PGPORT" ]; then
PGPORTOPT=""
else
PGPORTOPT="-p $PGPORT"
fi
PARGS="-tq $AUTHOPT $PGHOSTOPT $PGPORTOPT"
#
# generate the first part of the actual monitor command
#
PSQL="psql $PARGS"
#
# see if user $USER is allowed to create new users. Only a user who can
# create users can delete them.
#
QUERY="select usesuper from pg_user where usename = '$USER'"
ADDUSER=`$PSQL -c "$QUERY" template1`
if [ $? -ne 0 ]
then
echo "$CMDNAME: database access failed."
exit 1
fi
if [ x$ADDUSER != xt ]
then
echo "$CMDNAME: $USER cannot delete users."
exit 1
fi
#
# get the user name of the user to delete. Make sure it exists.
#
if [ -z "$DELUSER" ]
then
echo PG_OPT_DASH_N_PARAM "Enter name of user to delete ---> PG_OPT_BACKSLASH_C_PARAM"
read DELUSER
fi
QUERY="select usesysid from pg_user where usename = '$DELUSER'"
RES=`$PSQL -c "$QUERY" template1`
if [ $? -ne 0 ]
then
echo "$CMDNAME: database access failed."
exit 1
fi
if [ ! -n "$RES" ]
then
echo "$CMDNAME: user "\"$DELUSER\"" does not exist."
exit 1
fi
SYSID=`echo $RES | sed 's/ //g'`
#
# destroy the databases owned by the deleted user. First, use this query
# to find out what they are.
#
QUERY="select datname from pg_database where datdba = '$SYSID'::oid"
ALLDBS=`$PSQL -c "$QUERY" template1`
if [ $? -ne 0 ]
then
echo "$CMDNAME: database access failed - exiting..."
exit 1
fi
#
# don't try to delete template1!
#
for i in $ALLDBS
do
if [ $i != "template1" ]
then
DBLIST="$DBLIST $i"
fi
done
if [ -n "$DBLIST" ]
then
echo "User $DELUSER owned the following databases:"
echo $DBLIST
echo
#
# Now we warn the DBA that deleting this user will destroy a bunch of databases
#
yn=f
while [ "$yn" != y -a "$yn" != n ]
do
echo PG_OPT_DASH_N_PARAM "Deleting user $DELUSER will destroy them. Continue (y/n)? PG_OPT_BACKSLASH_C_PARAM"
read yn
done
if [ $yn = n ]
then
echo "$CMDNAME: exiting"
exit 1
fi
#
# now actually destroy the databases
#
for i in $DBLIST
do
echo "destroying database $i"
QUERY="drop database $i"
$PSQL -c "$QUERY" template1
if [ $? -ne 0 ]
then
echo "$CMDNAME: drop database on $i failed - exiting"
exit 1
fi
done
fi
QUERY="delete from pg_shadow where usename = '$DELUSER'"
$PSQL -c "$QUERY" template1
if [ $? -ne 0 ]
then
echo "$CMDNAME: delete of user $DELUSER was UNSUCCESSFUL"
else
echo "$CMDNAME: delete of user $DELUSER was successful."
fi
exit 0
#-------------------------------------------------------------------------
#
# Makefile.inc--
# Makefile for bin/createdb
# Makefile for bin/scripts
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/Makefile,v 1.10 1998/07/26 04:31:12 scrappy Exp $
# $Header: /cvsroot/pgsql/src/bin/scripts/Makefile,v 1.1 1999/12/04 04:53:21 momjian Exp $
#
#-------------------------------------------------------------------------
SRCDIR= ../..
.SUFFIXES:
SRCDIR=../..
include ../../Makefile.global
all: createdb
SCRIPTS=createdb dropdb createuser dropuser vacuumdb
createdb: createdb.sh
sed 's/__MULTIBYTE__/$(MULTIBYTE)/' createdb.sh > createdb
all: $(SCRIPTS)
install: createdb
$(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
createdb:
dropdb:
createuser:
dropuser:
vacuumdb:
clean:
rm -f createdb
install: $(SCRIPTS)
$(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$(X)$<
clean:
dep depend:
#!/bin/sh
#-------------------------------------------------------------------------
#
# createdb.sh--
# create a postgres database
#
# This program runs psql with the "-c" option to create
# the requested database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.1 1999/12/04 04:53:21 momjian Exp $
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
MB=
PSQLOPT=
dbname=
dbcomment=
while [ $# -gt 0 ]
do
case "$1" in
--help|-\?)
usage=t
break
;;
# options passed on to psql
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
--user|--username|-U)
PSQLOPT="$PSQLOPT -U $2"
shift;;
--password|-W)
PSQLOPT="$PSQLOPT -W"
;;
--echo|-e)
PSQLOPT="$PSQLOPT -e"
;;
--quiet|-q)
PSQLOPT="$PSQLOPT -o /dev/null"
;;
# options converted into SQL command
--dbpath|-D)
dbpath="$2"
shift;;
--encoding|-E)
MB=$2
shift
if [ -z `pg_encoding $MB` ]; then
echo "$CMDNAME: $MB is not a valid encoding name"
exit 1
fi
;;
-*)
echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
exit 1
;;
*)
if [ -z "$dbname" ]; then
dbname="$1"
else
dbcomment="$1"
fi
;;
esac
shift
done
if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-D <path>] \\"
echo " [-E <encoding>] [-U <username>] [-W] dbname [description]"
exit 0
fi
if [ -z "$dbname" ]; then
echo "$CMDNAME: Missing required argument database name. Try -? for help."
exit 1
fi
withstring=
[ "$dbpath" ] && withstring="$withstring LOCATION = '$dbpath'"
[ "$MB" ] && withstring="$withstring ENCODING = '$MB'"
[ "$withstring" ] && withstring=" WITH$withstring"
psql $PSQLOPT -d template1 -c "CREATE DATABASE \"$dbname\"$withstring"
if [ $? -ne 0 ]; then
echo "$CMDNAME: Database creation failed."
exit 1
fi
# Insert comment as well, if requested
[ -z "$dbcomment" ] && exit 0
psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS \'$dbcomment\'"
if [ $? -ne 0 ]; then
echo "$CMDNAME: Comment creation failed."
exit 1
fi
exit 0
\ No newline at end of file
#!/bin/sh
#-------------------------------------------------------------------------
#
# createuser--
# Utility for creating a user in the PostgreSQL database
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.1 1999/12/04 04:53:21 momjian Exp $
#
# Note - this should NOT be setuid.
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
NewUser=
SysID=
CanAddUser=
CanCreateDb=
PwPrompt=
Password=
PSQLOPT=
while [ $# -gt 0 ]
do
case "$1" in
--help|-\?)
usage=t
break
;;
# options passed on to psql
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
# Uncomment these lines if you need the -U and -W options.
# They are confusing in this context, however.
# --user|--username|-U)
# PSQLOPT="$PSQLOPT -U $2"
# shift;;
# --password|-W)
# PSQLOPT="$PSQLOPT -W"
# ;;
--echo|-e)
PSQLOPT="$PSQLOPT -e"
;;
--quiet|-q)
PSQLOPT="$PSQLOPT -o /dev/null"
;;
# options converted into SQL command
--createdb|-d)
CanCreateDb=t
;;
--no-createdb|-D)
CanCreateDb=f
;;
--adduser|-a)
CanAddUser=t
;;
--no-adduser|-A)
CanAddUser=f
;;
--pwprompt|--pw|-P)
PwPrompt=t
;;
-*)
echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
exit 1
;;
*)
NewUser=$1
;;
esac
shift;
done
# Help
if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-d|-D] [-a|-A] [-P] [username]"
exit 0
fi
# Get missing user attributes
if [ -z "$NewUser" ]; then
echo -n "Enter name of user to add: "
read -r NewUser
[ $? -ne 0 ] && exit 1
fi
if [ "$PwPrompt" ]; then
echo -n "Enter password for user $NewUser: "
read -r Password
fi
if [ -z "$CanCreateDb" ]; then
echo -n "Is the new user allowed to create databases? (y/n) "
read -r
[ $? -ne 0 ] && exit 1
if [ $REPLY = "y" -o $REPLY = "Y" ]; then
CanCreateDb=t
else
CanCreateDb=f
fi
fi
if [ -z "$CanAddUser" ]; then
echo -n "Shall the new user be allowed to create more new users? (y/n) "
read -r
[ $? -ne 0 ] && exit 1
if [ $REPLY = "y" -o $REPLY = "Y" ]; then
CanAddUser=t
else
CanAddUser=f
fi
fi
#
# build SQL command
#
QUERY="CREATE USER \"$NewUser\""
[ "$Password" ] && QUERY="$QUERY WITH PASSWORD \"$Password\""
[ "$CanCreateDb" = t ] && QUERY="$QUERY CREATEDB"
[ "$CanCreateDb" = f ] && QUERY="$QUERY NOCREATEDB"
[ "$CanAddUser" = t ] && QUERY="$QUERY CREATEUSER"
[ "$CanAddUser" = f ] && QUERY="$QUERY NOCREATEUSER"
psql $PSQLOPT -d template1 -c "$QUERY"
if [ $? -ne 0 ]; then
echo "$CMDNAME: Creation of user \"$NewUser\" failed."
exit 1
fi
exit 0
\ No newline at end of file
#!/bin/sh
#-------------------------------------------------------------------------
#
# dropdb--
# destroy a postgres database
#
# this program runs psql to drop the requested database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.1 1999/12/04 04:53:21 momjian Exp $
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
PSQLOPT=
dbname=
forcedel=t
while [ $# -gt 0 ]
do
case "$1" in
--help|-\?)
usage=t
break
;;
# options passed on to psql
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
--user|--username|-U)
PSQLOPT="$PSQLOPT -U $2"
shift;;
--password|-W)
PSQLOPT="$PSQLOPT -W"
;;
--echo|-e)
PSQLOPT="$PSQLOPT -e"
;;
--quiet|-q)
PSQLOPT="$PSQLOPT -o /dev/null"
;;
# other options
--interactive|-i)
forcedel=f
;;
-*)
echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
exit 1
;;
*)
dbname="$1"
;;
esac
shift
done
if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-U <username>] [-W] [-i] dbname"
exit 0
fi
if [ -z "$dbname" ]; then
echo "$CMDNAME: Missing required argument database name. Try -? for help."
exit 1
fi
if [ "$forcedel" = f ]; then
echo "Database \"$dbname\" will be permanently deleted."
echo -n "Are you sure? (y/n) "
read -r
[ $? -eq 1 ] && exit 1
[ "$REPLY" != "y" -a "$REPLY" != "Y" ] && exit 0
fi
psql $PSQLOPT -d template1 -c "DROP DATABASE \"$dbname\""
if [ $? -ne 0 ]; then
echo "$CMDNAME: Database removal failed."
exit 1
fi
exit 0
\ No newline at end of file
#!/bin/sh
#-------------------------------------------------------------------------
#
# dropuser--
# Utility for remocing a user from the PostgreSQL database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.1 1999/12/04 04:53:21 momjian Exp $
#
# Note - this should NOT be setuid.
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
PSQLOPT=
forcedel=t
while [ $# -gt 0 ]
do
case "$1" in
--help|-\?)
usage=t
break
;;
# options passed on to psql
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
# Uncomment these lines if you need the -U and -W options.
# They are confusing in this context, however.
# --user|--username|-U)
# PSQLOPT="$PSQLOPT -U $2"
# shift;;
# --password|-W)
# PSQLOPT="$PSQLOPT -W"
# ;;
--echo|-e)
PSQLOPT="$PSQLOPT -e"
;;
--quiet|-q)
PSQLOPT="$PSQLOPT -o /dev/null"
;;
# other options
--interactive|-i)
forcedel=f
;;
-*)
echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
exit 1
;;
*)
DelUser="$1"
;;
esac
shift;
done
# Help
if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-i] [username]"
exit 0
fi
# Prompt for username if missing
if [ -z "$DelUser" ]; then
echo -n "Enter name of user to delete: "
read -r NewUser
[ $? -ne 0 ] && exit 1
fi
if [ "$forcedel" = f ]; then
echo "User \"$DelUser\" and any owned databases will be permanently deleted."
echo -n "Are you sure? (y/n) "
read -r
[ $? -eq 1 ] && exit 1
[ "$REPLY" != "y" -a "$REPLY" != "Y" ] && exit 0
fi
psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\""
if [ $? -ne 0 ]; then
echo "$CMDNAME: Deletion of user \"$DelUser\" failed."
exit 1
fi
exit 0
#!/bin/sh
#-------------------------------------------------------------------------
#
# vacuumdb--
# vacuum a postgres database
#
# This script runs psql with the "-c" option to vacuum
# the requested database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.1 1999/12/04 04:53:21 momjian Exp $
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
PSQLOPT=
verbose=
analyze=
table=
while [ $# -gt 0 ]
do
case "$1" in
--help|-\?)
usage=t
break
;;
# options passed on to psql
--host|-h)
PSQLOPT="$PSQLOPT -h $2"
shift;;
--port|-p)
PSQLOPT="$PSQLOPT -p $2"
shift;;
--user|--username|-U)
PSQLOPT="$PSQLOPT -U $2"
shift;;
--password|-W)
PSQLOPT="$PSQLOPT -W"
;;
--echo|-e)
PSQLOPT="$PSQLOPT -e"
;;
--quiet|-q)
PSQLOPT="$PSQLOPT -o /dev/null"
;;
--dbname|--database|-d)
dbname="$2"
shift;;
# options converted into SQL command
--analyze|-z)
analyze="analyze"
;;
--table|-t)
table=$2
shift;;
--verbose|-v)
verbose="verbose"
;;
-*)
echo "$CMDNAME: Unrecognized option: $1. Try -? for help."
exit 1
;;
*)
dbname="$1"
;;
esac
shift
done
if [ "$usage" ]; then
echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-U <username>] [-W] [-d <dbname>] \\"
echo " [-z|--analyze] [-v|--verbose] [-t|--table 'table[(columns)]'] [dbname]"
exit 0
fi
if [ -z "$dbname" ]; then
echo "$CMDNAME: Missing required argument database name. Try -? for help."
exit 1
fi
psql $PSQLOPT -d "$dbname" -c "VACUUM $verbose $analyze $table"
if [ $? -ne 0 ]; then
echo "$CMDNAME: Database vacuum failed."
exit 1
fi
exit 0
#-------------------------------------------------------------------------
#
# Makefile--
# Makefile for bin/vacuumdb
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/vacuumdb/Attic/Makefile,v 1.1 1998/11/14 01:58:14 thomas Exp $
#
#-------------------------------------------------------------------------
SRCDIR= ../..
include ../../Makefile.global
all: vacuumdb
install: vacuumdb
$(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
clean:
dep depend:
#!/bin/sh
#-------------------------------------------------------------------------
#
# vacuumdb--
# vacuum a postgres database
#
# this program runs the monitor with the "-c" option to vacuum
# the requested database.
#
# Copyright (c) 1994, Regents of the University of California
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/vacuumdb/Attic/vacuumdb,v 1.1 1998/11/14 01:58:15 thomas Exp $
#
#-------------------------------------------------------------------------
CMDNAME=`basename $0`
if [ -z "$USER" ]; then
if [ -z "$LOGNAME" ]; then
if [ -z "`whoami`" ]; then
echo "$CMDNAME: cannot determine user name"
exit 1
fi
else
USER=$LOGNAME
export USER
fi
fi
dbname=$USER
PASSWDOPT="";
while test -n "$1"
do
case $1 in
--help) usage=1;;
--analyze) analyze="analyze";;
--table) table=$2; shift;;
--verbose) verbose="verbose";;
-a) AUTHSYS=$2; shift;;
-h) PGHOST=$2; shift;;
-p) PGPORT=$2; shift;;
-t) table=$2; shift;;
-u) PASSWDOPT=$1;;
-v) verbose="verbose";;
-z) analyze="analyze";;
-*) echo "$CMDNAME: unrecognized parameter $1"; usage=1;;
*) dbname=$1;;
esac
shift;
done
if [ "$usage" ]; then
echo "Usage: $CMDNAME -a <authtype> -h <server> -p <portnumber> --analyze --verbose [--table 'table[(cols)]'] [dbname]"
exit 1
fi
if [ -z "$AUTHSYS" ]; then
AUTHOPT=""
else
AUTHOPT="-a $AUTHSYS"
fi
if [ -z "$PGHOST" ]; then
PGHOSTOPT=""
else
PGHOSTOPT="-h $PGHOST"
fi
if [ -z "$PGPORT" ]; then
PGPORTOPT=""
else
PGPORTOPT="-p $PGPORT"
fi
if [ -z "$dbpath" ]; then
location=""
else
# if [ ! -d "$dbpath"/base ]; then
# echo "$CMDNAME: database creation failed on $dbname."
# echo "directory $dbpath/base not found."
# exit 1
# fi
location="with location = '$dbpath'"
fi
psql $PASSWDOPT -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "vacuum $verbose $analyze $table" $dbname
if [ $? -ne 0 ]; then
echo "$CMDNAME: database vacuum failed on $dbname."
exit 1
fi
exit 0
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