1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-25 01:02:05 +03:00

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

This commit is contained in:
Bruce Momjian
1999-12-04 04:53:22 +00:00
parent 21b69148dc
commit 240e4c98f5
33 changed files with 1286 additions and 2081 deletions

View File

@ -1,5 +1,5 @@
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createuser.sgml,v 1.5 1999/07/22 15:09:09 thomas Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/createuser.sgml,v 1.6 1999/12/04 04:53:15 momjian Exp $
Postgres documentation
-->
@ -15,23 +15,21 @@ Postgres documentation
<application>createuser</application>
</refname>
<refpurpose>
Create a new <productname>Postgres</productname> user
Create a new <productname>PostgreSQL</productname> user
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>1999-07-20</date>
<date>1999-11-07</date>
</refsynopsisdivinfo>
<synopsis>
createuser [ <replaceable class="parameter">username</replaceable> ]
createuser [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replaceable class="parameter">port</replaceable> ]
[ -i <replaceable class="parameter">userid</replaceable> ] [ -d | -D ] [ -u | -U ]
[ <replaceable class="parameter">username</replaceable> ]
createuser [ <replaceable class="parameter">options</replaceable> ] [ <replaceable class="parameter">username</replaceable> ]
</synopsis>
<refsect2 id="R2-APP-CREATEUSER-1">
<refsect2info>
<date>1998-10-02</date>
<date>1999-11-07</date>
</refsect2info>
<title>
Inputs
@ -40,76 +38,89 @@ createuser [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replac
<variablelist>
<varlistentry>
<term>-h <replaceable class="parameter">host</replaceable></term>
<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. Defaults to using a local Unix domain socket
rather than an IP connection.
is running.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-p <replaceable class="parameter">port</replaceable></term>
<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. The port number defaults to 5432,
or the value of the <envar>PGPORT</envar>
environment variable (if set).
is listening for connections.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-d</term>
<term>-e, --echo</term>
<listitem>
<para>
Allows the user to create databases.
Echo the queries that <application>createdb</application> generates
and sends to the backend.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-D</term>
<term>-q, --quiet</term>
<listitem>
<para>
Forbids the user to create databases.
Do not display a response.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-i <replaceable class="parameter">userid</replaceable></term>
<term>-d, --createdb</term>
<listitem>
<para>
Specifies the numeric identifier to be associated with this user.
This identifier must be unique among all
<productname>Postgres</productname> users, and is not required
to match the operating system UID.
You will be prompted for an identifier if none is specified on the command line,
and it will suggest an identifier matching the UID.
Allows the new user to create databases.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-u</term>
<term>-D, --no-createdb</term>
<listitem>
<para>
Allows the user to create other users.
Forbids the new user to create databases.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-U</term>
<term>-a, --adduser</term>
<listitem>
<para>
Forbids the user to create other users.
Allows the new user to create other users.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-A, --no-adduser</term>
<listitem>
<para>
Forbids the new user to create other users.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-P, --pwprompt</term>
<listitem>
<para>
If given, <application>createuser</application> will issue a prompt for
the password of the new user. This is not necessary if you do not plan
on using password authentication.
</para>
</listitem>
</varlistentry>
@ -118,166 +129,126 @@ createuser [ -h <replaceable class="parameter">host</replaceable> ] [ -p <replac
<term><replaceable class="parameter">username</replaceable></term>
<listitem>
<para>
Specifies the name of the <productname>Postgres</productname> user to be created.
This name must be unique among all <productname>Postgres</productname> users.
You will be prompted for a name if none is specified on the command line.
Specifies the name of the <productname>PostgreSQL</productname> user to be created.
This name must be unique among all <productname>PostgreSQL</productname> users.
</para>
</listitem>
</varlistentry>
</variablelist>
You will be prompted for a name and other missing information if it is not
specified on the command line.
</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-CREATEUSER-2">
<refsect2info>
<date>1998-10-02</date>
<date>1999-11-07</date>
</refsect2info>
<title>
Outputs
</title>
<para>
<application>createuser</application> will add an entry in the
<literal>pg_user</literal> or <literal>pg_shadow</literal> system table.
<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>'?
createuser: database access failed.
</computeroutput></term>
<term><computeroutput>CREATE USER</computeroutput></term>
<listitem>
<para>
<application>createuser</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.
All is well.
</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'
createuser: database access failed.
</computeroutput></term>
<term><computeroutput>createuser: Creation of user "<replaceable class="parameter">username</replaceable>" 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.
Something went wrong. The user was not created.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
createuser: <replaceable class="parameter">username</replaceable> cannot create users.
</computeroutput></term>
<listitem>
<para>
You do not have permission to create new users; contact your
<productname>Postgres</productname> site administrator.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
createuser: 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>
</variablelist>
</para>
<note>
<para>
<application>createuser</application> internally runs
<command>CREATE USER</command> from <application>psql</application>
while connected to the <literal>template1</literal> database.
</para>
</note>
If there is an error condition, the backend error message will be displayed.
See <xref linkend="SQL-CREATEUSER" endterm="SQL-CREATEUSER-title">
and <xref linkend="APP-PSQL" endterm="APP-PSQL-title"> for possibilities.
</para>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-APP-CREATEUSER-1">
<refsect1info>
<date>1998-10-02</date>
<date>1998-11-07</date>
</refsect1info>
<title>
Description
</title>
<para>
<application>createuser</application> creates a
new <productname>Postgres</productname> user.
new <productname>PostgreSQL</productname> user.
Only users with <literal>usesuper</literal> set in
the <literal>pg_shadow</literal> class can create
new <productname>Postgres</productname> users. As shipped,
the user <literal>postgres</literal> can create users.
</para>
<para>
<application>createuser</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>createuser</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">.
new <productname>Postgres</productname> users.
</para>
<para>
Once invoked, <application>createuser</application>
will ask a series of questions to obtain parameters not specified on
the command line. The new user's database login name and a numeric
user identifier must be specified.
<note>
<para>
The <productname>Postgres</productname> user identifier
does not need to be the same as the user's Unix UID. However, typically
they are assigned to be the same.
</para>
</note>
<application>createuser</application> is a shell script wrapper around the
<acronym>SQL</acronym> command
<xref linkend="SQL-CREATEUSER" endterm="SQL-CREATEUSER-title"> via
the <productname>PostgreSQL</productname> interactive terminal
<xref linkend="APP-PSQL" endterm="APP-PSQL-title">. Thus, there is nothing
special about creating 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-CREATEUSER-2">
<refsect1info>
<date>1999-11-07</date>
</refsect1info>
<title>
Usage
</title>
<para>
You must also describe the privileges of the new user for security purposes.
Specifically, you will be asked whether the new user should be able to
act as <productname>Postgres</productname> super-user,
whether the new user may create new databases and whether the new user
is allowed to create other new users.
To create a user <literal>joe</literal>
on the default database server:
<programlisting>
$ <userinput>createuser joe</userinput>
Is the new user allowed to create databases? (y/n) <userinput>n</userinput>
Shall the new user be allowed to create more new users? (y/n) <userinput>n</userinput>
CREATE USER
</programlisting>
</para>
<para>
To create the same user <literal>joe</literal>
using the postmaster on host eden, port 5000, avoiding
the prompts and taking a look at the underlying query:
<programlisting>
$ <userinput>createuser -p 5000 -h eden -D -A -e joe</userinput>
QUERY: CREATE USER "joe" NOCREATEDB NOCREATEUSER
CREATE USER
</programlisting>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file