#
#
# 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 $
#
#----------------------------------------------------------------------------
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 \
&createdb;
- &createlang;
&createuser;
- &destroydb;
- &destroylang;
- &destroyuser;
+ &dropdb;
+ &dropuser;
&ecpgRef;
&pgAccess;
&pgAdmin;
-CREATEDB
+CREATE DATABASE
Creating Postgres database system directory /home/olly/private_db/base
- 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
-
+ 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.
olly=> create database elsewhere with location = '/home/olly/private_db';
- CREATEDB
+ CREATE DATABASE
-
+ id="sql-createuser-title">
CREATE USER
SQL - Language Statements
- Create a new
Postgres database
+ Create a new
PostgreSQL database
- 1999-07-20
+ 1999-11-07
-createdb [ dbname ]
-createdb [ -h host ] [ -p port ]
- [ -D datadir ] [ -u ] [ dbname ]
+createdb [ options ] dbname [ description ]
- 1998-10-02
+ 1999-11-07
Inputs
- -h host
+ -h, --host host
Specifies the hostname of the machine on which the
- is running. Defaults to using a local Unix domain socket
- rather than an IP connection.
+ is running.
+
- -p port
+ -p, --port port
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the
postmaster
- is listening for connections. The port number defaults to 5432,
- or the value of the PGPORT
- environment variable (if set).
+ is listening for connections.
- -u
+ -U, --username username
- Use password authentication.
- Prompts for
- username
- and password.
+ Username to connect as.
- -D datadir
+ -W, --password
- Specifies the alternate database location for this database installation.
- This is the location of the installation system tables, not the location
- of this specific database, which may be different.
+ Force password prompt.
- dbname
+ -e, --echo
- Specifies the name of the database to be created. The name must be
- unique among all
Postgres databases in this installation.
- dbname
- defaults to the value of the
- USER
- environment variable.
+ Echo the queries that
createdb generates
+ and sends to the backend.
-
-
-
-
-
-
- 1998-10-02
-
-
- Outputs
-
-
createdb will create files in the
- PGDATA/dbname/
- data area for the new database.
-
-
-
-Connection to database 'template1' failed.
-connectDB() failed: Is the postmaster running and accepting connections at 'UNIX Socket' on port 'port'?
-createdb: database creation failed on dbname.
-
+ -q, --quiet
-
createdb could not attach to the
- process on the specified host and port. If you see this message,
- ensure that the
postmaster
- 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.
+ Do not display a response.
-
-Connection to database 'template1' failed.
-FATAL 1: SetUserId: user 'username' is not in 'pg_shadow'
-createdb: database creation failed on dbname.
-
+ -D, --dbpath datadir
- You do not have a valid entry in the relation pg_shadow
- and and will not be allowed to access
Postgres.
-
Contact your Postgres administrator.
+ Specifies the alternate database location for this database installation.
+ This is the location of the installation system tables, not the location
+ of this specific database, which may be different.
-
-ERROR: user 'username' is not allowed to create/destroy databases
-createdb: database creation failed on dbname.
-
+ -E, --encoding encoding
- You do not have permission to create new databases.
- Contact your
Postgres site administrator.
+ Specifies the character encoding scheme to be used with this database.
-
-ERROR: createdb: database 'dbname' already exists.
-createdb: database creation failed on dbname.
-
+ dbname
- The database already exists.
+ Specifies the name of the database to be created. The name must be
+ unique among all
Postgres databases in this installation.
-
-createdb: database creation failed on dbname.
-
+ description
- An internal error occurred in
psql
- or in the backend server. Ensure that your site administrator has
- properly installed
Postgresand initialized the site with
+ This optionally specifies a comment to be associated with the newly created
+ database.
+
+ The options -h, -p, -U,
+ -W, and -e are passed on literally to
+ .
+
+
+
+
+
+ 1999-11-07
+
+
+ Outputs
+
+
+
+ CREATE DATABASE
+
+
The database was successfully created.
+
+
+
+
+ createdb: Database creation failed.
+
+
+
+
+
+ createdb: Comment creation failed.
+
+ The comment/description for the database could not be created.
+ the database itself will have been created already. You can use the
+
SQL command
COMMENT ON DATABASE to
+ create the comment later on.
+
+
+
+
+
+ If there is an error condition, the backend error message will be displayed.
+ See
+ and for possibilities.
-
-
createdb internally runs
-
CREATE DATABASE from
psql
- while connected to the template1 database.
-
-
- 1998-10-02
+ 1999-11-07
Description
- The person who executes this command becomes
- the database administrator, or
DBA,
- for this database and is the only
- person, other than the
Postgres super-user,
- who can destroy it.
+
createdb creates a new
PostgreSQL
+ database. The user who executes this command becomes the database owner.
+
-
createdb is a shell script that invokes
- process must be running on the database server host before
- is executed. The
- PGOPTION
- and
- PGREALM
- environment variables will be passed on to
- and processed as described in
- .
+
createdb is a shell script wrapper around the
+ via
+ the
PostgreSQL interactive terminal
+ . Thus, there is nothing
+ special about creating databases via this or other methods. This means
+ that the
psql 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
psql
+ and the
libpq front-end library do apply.
- 1998-10-02
+ 1999-11-07
Usage
To create the database demo
- using the postmaster on the local host, port 5432:
+ using the default database server:
-$ createdb demo
+$ createdb demo
+CREATE DATABASE
+
+ The response is the same as you would have gotten from running the
+
CREATE DATABASE SQL command.
To create the database demo
- using the postmaster on host eden, port 5000:
+ using the postmaster on host eden, port 5000, using the LATIN1
+ encoding scheme and look at the underlying query:
-$ createdb -p 5000 -h eden demo
+$ createdb -p 5000 -h eden -E LATIN1 -e demo
+QUERY: CREATE DATABASE "demo" WITH ENCODING = 'LATIN1'
+CREATE DATABASE
-
-
-
-
-
-
- Application
-
-
-
-
-
- Add a new programming language to a
Postgres database
-
-
-
-
- 1999-08-05
-
-
-createlang [ langname ]
-createlang [ -h host ] [ -p port ]
- [ langname ]
-
-
-
-
- Inputs
-
-
createlang accepts the following command line arguments:
-
-
-
- langname
-
- Specifies the name of the backend programming language to be defined.
-
createlang will prompt for
- langname
- if it is not specified on the command line.
-
-
-
-
-
-
-
createlang also accepts
- the following command line arguments for connection parameters:
-
-
-
- -h host
-
- Specifies the hostname of the machine on which the
- is running. Defaults to using a local Unix domain socket
- rather than an IP connection.
-
-
-
-
-
- -p port
-
- Specifies the Internet TCP/IP port or local Unix domain socket file
- extension on which the
postmaster
- is listening for connections. The port number defaults to 5432,
- or the value of the PGPORT
- environment variable (if set).
-
-
-
-
-
-
-
-
-
-
- 1998-10-04
-
-
- Outputs
-
-
createlang installs a new programming
- language into a
Postgres server,
- so has not explicit external output.
-
-
-
-
-
-
- 1998-10-04
-
-
- Description
-
-
-
createlang is a utility for adding a new
- programming language to a
-
createlang currently accepts two
- languages, plsql and pltcl.
-
-
-
-
-
- Notes
-
-
- See
-
- for more details.
-
-
-
-
-
- Usage
-
- To install pltcl:
-
-% createlang pltcl
-
-
-
-
-
-
- Create a new
Postgres user
+ Create a new
PostgreSQL user
- 1999-07-20
+ 1999-11-07
+
-createuser [ username ]
-createuser [ -h host ] [ -p port ]
- [ -i userid ] [ -d | -D ] [ -u | -U ]
- [ username ]
+createuser [ options ] [ username ]
- 1998-10-02
+ 1999-11-07
Inputs
- -h host
+ -h, --host host
Specifies the hostname of the machine on which the
- is running. Defaults to using a local Unix domain socket
- rather than an IP connection.
+ is running.
- -p port
+ -p, --port port
Specifies the Internet TCP/IP port or local Unix domain socket file
extension on which the
postmaster
- is listening for connections. The port number defaults to 5432,
- or the value of the PGPORT
- environment variable (if set).
+ is listening for connections.
- -d
+ -e, --echo
- Allows the user to create databases.
+ Echo the queries that
createdb generates
+ and sends to the backend.
- -D
+ -q, --quiet
- Forbids the user to create databases.
+ Do not display a response.
- -i userid
+ -d, --createdb
- Specifies the numeric identifier to be associated with this user.
- This identifier must be unique among all
-
Postgres 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.
- -u
+ -D, --no-createdb
- Allows the user to create other users.
+ Forbids the new user to create databases.
- -U
+ -a, --adduser
- Forbids the user to create other users.
+ Allows the new user to create other users.
- username
+ -A, --no-adduser
- Specifies the name of the
Postgres user to be created.
- This name must be unique among all
Postgres users.
- You will be prompted for a name if none is specified on the command line.
-
-
-
-
-
-
-
-
-
- 1998-10-02
-
-
- Outputs
-
-
createuser will add an entry in the
- pg_user or pg_shadow system table.
-
-
-
-
-Connection to database 'template1' failed.
-connectDB() failed: Is the postmaster running and accepting connections at 'UNIX Socket' on port 'port'?
-createuser: database access failed.
-
-
-
createuser could not attach to the
- process on the specified host and port. If you see this message,
- ensure that the
postmaster
- 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.
+ Forbids the new user to create other users.
-
-Connection to database 'template1' failed.
-FATAL 1: SetUserId: user 'username' is not in 'pg_shadow'
-createuser: database access failed.
-
+ -P, --pwprompt
- You do not have a valid entry in the relation pg_shadow
- and and will not be allowed to access
Postgres. Contact your
-
Postgres administrator.
+ If given,
createuser will issue a prompt for
+ the password of the new user. This is not necessary if you do not plan
+ on using password authentication.
-
-createuser: username cannot create users.
-
+ username
- You do not have permission to create new users; contact your
-
Postgres site administrator.
+ Specifies the name of the
PostgreSQL user to be created.
+
This name must be unique among all PostgreSQL users.
-
+
+
+
+ You will be prompted for a name and other missing information if it is not
+ specified on the command line.
+
+
+ The options -h, -p, and -e,
+ are passed on literally to . If you
+ need the
psql options
-U and
+ -W 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.
+
+
+
+
+ 1999-11-07
+
+
+ Outputs
+
+
-
-createuser: user "username" already exists
-
+ CREATE USER
- The user to be added already has an entry in the
- pg_shadow class.
+ All is well.
-
-database access failed
-
+ createuser: Creation of user "username" failed.
- An internal error occurred in
psql
- or in the backend server. Ensure that your site administrator has
- properly installed
Postgresand initialized the site with
+ Something went wrong. The user was not created.
+
-
-
-
createuser internally runs
- while connected to the template1 database.
-
-
+ If there is an error condition, the backend error message will be displayed.
+ See
+ and for possibilities.
+
- 1998-10-02
+ 1998-11-07
Description
Only users with usesuper set in
the pg_shadow class can create
- new
Postgres users. As shipped,
- the user postgres can create users.
+
-
createuser is a shell script that invokes
- process must be running on the database server host before
-
createuser is executed.
- The
- PGOPTION
- and
- PGREALM
- environment variables will be passed on to
- and processed as described in
- .
+
createuser is a shell script wrapper around the
+ via
+ the
PostgreSQL interactive terminal
+ . Thus, there is nothing
+ special about creating users via this or other methods. This means
+ that the
psql 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
psql
+ and the
libpq front-end library do apply.
+
+
+
+
+
+ 1999-11-07
+
+
+ Usage
+
- Once invoked,
createuser
- 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.
-
-
- The
Postgres user identifier
- does not need to be the same as the user's Unix UID. However, typically
- they are assigned to be the same.
-
-
+ To create a user joe
+ on the default database server:
+
+$ createuser joe
+Is the new user allowed to create databases? (y/n) n
+Shall the new user be allowed to create more new users? (y/n) n
+CREATE USER
+
-
+
- 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
Postgres super-user,
- whether the new user may create new databases and whether the new user
- is allowed to create other new users.
+ To create the same user joe
+ using the postmaster on host eden, port 5000, avoiding
+ the prompts and taking a look at the underlying query:
+
+$ createuser -p 5000 -h eden -D -A -e joe
+QUERY: CREATE USER "joe" NOCREATEDB NOCREATEUSER
+CREATE USER
+
+
-
-
-
-
-
- Application
-
-
-
-
-
- Remove an existing
Postgres database
-
-
-
-
- 1999-07-20
-
-
-destroydb [ dbname ]
-destroydb [ -h host ] [ -p port ]
- [ -i ] [ dbname ]
-
-
-
-
- 1998-10-02
-
-
- Inputs
-
-
-
-
- -h host
-
- Specifies the hostname of the machine on which the
- is running. Defaults to using a local Unix domain socket
- rather than an IP connection.
-
-
-
-
-
- -p port
-
- Specifies the Internet TCP/IP port or local Unix domain socket file
- extension on which the
postmaster
- is listening for connections. The port number defaults to 5432,
- or the value of the PGPORT
- environment variable (if set).
-
-
-
-
-
- -i
-
- Run in interactive mode.
- Prompts for confirmation before destroying a database.
-
-
-
-
-
- dbname
-
- Specifies the name of the database to be destroyed. The database
- must be one of the existing
Postgres databases
- in this installation.
- dbname
- defaults to the value of the
- USER
- environment variable.
-
-
-
-
-
-
-
-
-
- 1998-10-02
-
-
- Outputs
-
-
destroydb will remove files from the
- PGDATA/dbname/
- data area for the existing database.
-
-
-
-
-Connection to database 'template1' failed.
-connectDB() failed: Is the postmaster running and accepting connections
- at 'UNIX Socket' on port 'port'?
-destroydb: database destroy failed on dbname.
-
-
-
destroydb could not attach to the
- process on the specified host and port. If you see this message,
- ensure that the
postmaster
- 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.
-
-
-
-
-
-
-Connection to database 'template1' failed.
-FATAL 1: SetUserId: user 'username' is not in 'pg_shadow'
-destroydb: database destroy failed on dbname.
-
-
- You do not have a valid entry in the relation pg_shadow
- and and will not be allowed to access
Postgres.
- Contact your
Postgres administrator.
-
-
-
-
-
-
-ERROR: user 'username' is not allowed to create/destroy databases
-destroydb: database destroy failed on dbname.
-
-
- You do not have permission to destroy (or create) databases.
- Contact your
Postgres site administrator.
-
-
-
-
-
-
-ERROR: destroydb: database 'dbname' does not exist.
-destroydb: database destroy failed on dbname.
-
-
- The database to be removed does not have an entry in the
- pg_database class.
-
-
-
-
-
-
-ERROR: destroydb: database 'dbname' is not owned by you.
-destroydb: database destroy failed on dbname.
-
-
- You are not the Database Administrator (DBA) for the specified database.
-
-
-
-
-
-
-destroydb: database destroy failed on dbname.
-
-
- An internal error occurred in
psql
- or in the backend server. Ensure that your site administrator has
- properly installed
Postgresand initialized the site with
-
-
-
-
-
-
-
destroydb internally runs
-
DESTROY DATABASE from
psql
- while connected to the template1 database.
-
-
-
-
-
-
-
- 1998-10-02
-
-
- Description
-
-
destroydb destroys an existing
- The person who executes this command must be
- the database administrator, or
DBA,
- or must be the
Postgres super-user.
- The program runs silently; no confirmation message will be displayed.
- After the database is destroyed, a Unix shell prompt will reappear.
-
- All references to
- the database are removed, including the directory containing this
- database and its associated files.
-
-
destroydb is a shell script that invokes
- process must be running on the database server host before
- is executed. The
- PGOPTION
- and
- PGREALM
- environment variables will be passed on to
- and processed as described in .
-
-
-
-
-
- 1998-10-02
-
-
- Usage
-
- To destroy the database demo
- using the postmaster on the local host, port 5432:
- destroydb demo
-
-
- To destroy the database demo
- using the postmaster on host eden, port 5000:
- destroydb -p 5000 -h eden demo
-
-
-
-
-
-
-
-
-
-
-
-
- Application
-
-
-
-
-
- Add a programming language to a
Postgres database
-
-
-
-
- 1999-08-05
-
-
-destroylang [ langname ]
-destroylang [ -h host ] [ -p port ]
- [ langname ]
-
-
-
-
- Inputs
-
-
destroylang accepts the following command line arguments:
-
-
-
- langname
-
- Specifies the name of the backend programming language to be destroyed.
-
destroylang will prompt for
- langname
- if it is not specified on the command line.
-
-
-
-
-
-
-
destroylang also accepts
- the following command line arguments for connection parameters:
-
-
-
- -h host
-
- Specifies the hostname of the machine on which the
- is running. Defaults to using a local Unix domain socket
- rather than an IP connection.
-
-
-
-
-
- -p port
-
- Specifies the Internet TCP/IP port or local Unix domain socket file
- extension on which the
postmaster
- is listening for connections. The port number defaults to 5432,
- or the value of the PGPORT
- environment variable (if set).
-
-
-
-
-
-
-
-
-
-
- 1998-10-04
-
-
- Outputs
-
-
destroylang removes an existing programming
- language from a
Postgres server,
- so has not explicit external output.
-
-
-
-
-
-
- 1998-10-04
-
-
- Description
-
-
-
destroylang is a utility for removing an
- existing programming language from a
-
destroylang currently accepts two
- languages, plsql and pltcl.
-
-
-
-
-
- Notes
-
-
- See
-
- for more details.
-
-
-
-
-
- Usage
-
- To remove pltcl:
-
-% destroylang pltcl
-
-
-
-
-
-
-
-
-
-
-
-
- Application
-
-
-
-
-
- Destroy a
Postgres user and associated databases
-
-
-
-
- 1999-07-20
-
-
-destroyuser [ username ]
-destroyuser [ -h host ] [ -p port ]
- [ username ]
-
-
-
-
- 1998-10-02
-
-
- Inputs
-
-
-
-
- -h host
-
- Specifies the hostname of the machine on which the
- is running. Defaults to using a local Unix domain socket
- rather than an IP connection.
-
-
-
-
-
- -p port
-
- Specifies the Internet TCP/IP port or local Unix domain socket file
- extension on which the
postmaster
- is listening for connections. The port number defaults to 5432,
- or the value of the PGPORT
- environment variable (if set).
-
-
-
-
-
- username
-
- Specifies the name of the
Postgres user to be removed.
- This name must exist in the
Postgres installation.
- You will be prompted for a name if none is specified on the command line.
-
-
-
-
-
-
-
-
-
- 1998-10-02
-
-
- Outputs
-
-
destroyuser will remove an entry in the
- pg_user or pg_shadow system table,
- and will remove all databases for which that user is the administrator
-
-
-
-
-Connection to database 'template1' failed.
-connectDB() failed: Is the postmaster running and accepting connections
- at 'UNIX Socket' on port 'port'?
-destroyuser: database access failed.
-
-
-
destroyuser could not attach to the
- process on the specified host and port. If you see this message,
- ensure that the
postmaster
- 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.
-
-
-
-
-
-
-Connection to database 'template1' failed.
-FATAL 1: SetUserId: user 'username' is not in 'pg_shadow'
-destroyuser: database access failed.
-
-
- You do not have a valid entry in the relation pg_shadow
- and and will not be allowed to access
Postgres. Contact your
-
Postgres administrator.
-
-
-
-
-
-
-destroyuser: username cannot delete users.
-
-
- You do not have permission to delete users; contact your
-
Postgres site administrator.
-
-
-
-
-
-
-destroyuser: user "username" already exists
-
-
- The user to be added already has an entry in the
- pg_shadow class.
-
-
-
-
-
-
-database access failed
-
-
- An internal error occurred in
psql
- or in the backend server. Ensure that your site administrator has
- properly installed
Postgresand initialized the site with
-
-
-
-
-
-
-destroydb on dbname failed - exiting
-
-
- An internal error occurred in
psql
- or in the backend server. There was possibly a Unix permissions problem with the
- specified database.
-
-
-
-
-
-
-delete of user username was UNSUCCESSFUL
-
-
- An internal error occurred in
psql
- or in the backend server.
-
-
-
-
-
-
-
-
destroyuser internally runs
- while connected to the template1 database.
-
-
-
-
-
-
-
- 1998-10-02
-
-
- Description
-
-
destroyuser removes an existing
- and the databases for which that user
- is database administrator.
- Only users with usesuper set in
- the pg_shadow class can destroy
-
Postgres users. As shipped,
- the user postgres can remove users.
-
-
destroyuser is a shell script that invokes
- process must be running on the database server host before
-
destroyuser is executed.
- The
- PGOPTION
- and
- PGREALM
- environment variables will be passed on to
- and processed as described in .
-
-
- Once invoked,
destroyuser
- 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.
-
-
-
-
-
-DESTROYDB
+DROP DATABASE
This query cannot be executed while connected to the target
- database. It is usually preferable to use
- estroydb" endterm="app-destroydb-title">
- instead.
+ database. Thus, it might be more convenient to use
+ ropdb" endterm="app-dropdb-title">
+ from the shell instead.
Refer to
- and
for information on how to create a database.
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
destroyuser
+ can be used in place of the
dropuser
script, regardless of how the user was created.
--- /dev/null
+
+
+
+
+
+
+ Application
+
+
+
+
+
+ Remove an existing
PostgreSQL database
+
+
+
+
+ 1999-11-07
+
+
+dropdb [ options ] dbname
+
+
+
+
+ 1999-11-07
+
+
+ Inputs
+
+
+
+
+ -h, --host host
+
+ Specifies the hostname of the machine on which the
+ is running.
+
+
+
+
+
+ -p, --port port
+
+ Specifies the Internet TCP/IP port or local Unix domain socket file
+ extension on which the
postmaster
+ is listening for connections.
+
+
+
+
+
+ -U, --username username
+
+ Username to connect as.
+
+
+
+
+
+ -W, --password
+
+ Force password prompt.
+
+
+
+
+
+ -e, --echo
+
+ Echo the queries that
dropdb generates
+ and sends to the backend.
+
+
+
+
+
+ -q, --quiet
+
+ Do not display a response.
+
+
+
+
+
+ -i, --interactive
+
+ Issues a verification prompt before doing anything destructive.
+
+
+
+
+
+ dbname
+
+ Specifies the name of the database to be removed. The database
+ must be one of the existing
PostgreSQL databases
+ in this installation.
+
+
+
+
+
+ The options -h, -p, -U,
+ -W, and -e are passed on literally to
+ .
+
+
+
+
+
+
+ 1998-10-02
+
+
+ Outputs
+
+
+
+
+ DROP DATABASE
+
+
The database was successfully removed.
+
+
+
+
+ dropdb: Database removal failed.
+
+
Something didn't work out.
+
+
+
+
+ If there is an error condition, the backend error message will be displayed.
+ See
+ and for possibilities.
+
+
+
+
+
+
+
+ 1998-10-02
+
+
+ Description
+
+
dropdb destroys an existing
+ The user who executes this command must be a database
+ superuser or the owner of the database.
+
+
+
dropdb is a shell script wrapper around the
+ via
+ the
PostgreSQL interactive terminal
+ . Thus, there is nothing
+ special about dropping databases via this or other methods. This means
+ that the
psql 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
psql
+ and the
libpq front-end library do apply.
+
+
+
+
+
+ 1999-11-07
+
+
+ Usage
+
+ To destroy the database demo
+ on the default database server:
+$ dropdb demo
+DROP DATABASE
+
+
+ To destroy the database demo
+ using the postmaster on host eden, port 5000, with verification
+ and a peek at the underlying query:
+$ dropdb -p 5000 -h eden -i -e demo
+Database "demo" will be permanently deleted.
+Are you sure? (y/n) y
+QUERY: DROP DATABASE "demo"
+DROP DATABASE
+
+
+
+
+
+
--- /dev/null
+
+
+
+
+
+
+ Application
+
+
+
+
+
+ Drops (removes) a
Postgres user
+
+
+
+
+ 1999-11-07
+
+
+dropuser [ options ] [ username ]
+
+
+
+
+ 1999-11-07
+
+
+ Inputs
+
+
+
+
+ -h, --host host
+
+ Specifies the hostname of the machine on which the
+ is running.
+
+
+
+
+
+ -p, --port port
+
+ Specifies the Internet TCP/IP port or local Unix domain socket file
+ extension on which the
postmaster
+ is listening for connections.
+
+
+
+
+
+ -e, --echo
+
+ Echo the queries that
createdb generates
+ and sends to the backend.
+
+
+
+
+
+ -q, --quiet
+
+ Do not display a response.
+
+
+
+
+
+ -i, --interactive
+
+ Prompt for confirmation before actually removing the user.
+
+
+
+
+
+ username
+
+ Specifies the name of the
PostgreSQL user to be removed.
+ This name must exist in the
Postgres installation.
+ You will be prompted for a name if none is specified on the command line.
+
+
+
+
+
+
+ The options -h, -p, and -e,
+ are passed on literally to . If you
+ need the
psql options
-U and
+ -W 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.
+
+
+
+
+
+ 1999-11-07
+
+
+ Outputs
+
+
+
+
+ DROP USER
+
+ All is well.
+
+
+
+
+
+ dropuser: Deletion of user "username" failed.
+
+ Something went wrong. The user was not removed.
+
+
+
+
+
+
+ If there is an error condition, the backend error message will be displayed.
+ See
+ and for possibilities.
+
+
+
+
+
+
+ 1999-11-07
+
+
+ Description
+
+
dropuser removes an existing
+ and the databases which that user owned.
+ Only users with usesuper set in
+ the pg_shadow class can destroy
+
+
+
dropuser is a shell script wrapper around the
+ via
+ the
PostgreSQL interactive terminal
+ . Thus, there is nothing
+ special about removing users via this or other methods. This means
+ that the
psql 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
psql
+ and the
libpq front-end library do apply.
+
+
+
+
+
+
+ 1999-11-07
+
+
+ Usage
+
+ To remove user joe
+ from the default database server:
+$ dropuser joe
+DROP USER
+
+
+
+ To remove user joe
+ using the postmaster on host eden, port 5000, with verification
+ and a peek at the underlying query:
+$ dropuser -p 5000 -h eden -i -e joe
+User "joe" and any owned databases will be permanently deleted.
+Are you sure? (y/n) y
+QUERY: DROP USER "joe"
+DROP USER
+
+
+
+
+
+
+
#
#
# 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
+++ /dev/null
-#-------------------------------------------------------------------------
-#
-# Makefile.inc--
-# Makefile for bin/createdb
-#
-# 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 $
-#
-#-------------------------------------------------------------------------
-
-SRCDIR= ../..
-include ../../Makefile.global
-
-all: createdb
-
-createdb: createdb.sh
- sed 's/__MULTIBYTE__/$(MULTIBYTE)/' createdb.sh > createdb
-
-install: createdb
- $(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
-
-clean:
- rm -f createdb
-
-dep depend:
+++ /dev/null
-#!/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
-h -p -D [dbname]"
- exit 1
- else
- echo "Usage: $CMDNAME -a
-h -p -D -E [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
+++ /dev/null
-#-------------------------------------------------------------------------
-#
-# 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
-
-install: createuser
- $(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
-
-clean:
- rm -f createuser
-
-dep depend:
+++ /dev/null
-#!/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
+++ /dev/null
-#-------------------------------------------------------------------------
-#
-# 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:
+++ /dev/null
-#!/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
+++ /dev/null
-#-------------------------------------------------------------------------
-#
-# 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
-
-install: destroyuser
- $(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$<
-
-clean:
- rm -f destroyuser
-
-dep depend:
+++ /dev/null
-#!/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
--- /dev/null
+#-------------------------------------------------------------------------
+#
+# Makefile.inc--
+# Makefile for bin/scripts
+#
+# Copyright (c) 1994, Regents of the University of California
+#
+#
+# IDENTIFICATION
+# $Header: /cvsroot/pgsql/src/bin/scripts/Makefile,v 1.1 1999/12/04 04:53:21 momjian Exp $
+#
+#-------------------------------------------------------------------------
+
+.SUFFIXES:
+
+SRCDIR=../..
+include ../../Makefile.global
+
+SCRIPTS=createdb dropdb createuser dropuser vacuumdb
+
+all: $(SCRIPTS)
+
+createdb:
+dropdb:
+createuser:
+dropuser:
+vacuumdb:
+
+install: $(SCRIPTS)
+ $(INSTALL) $(INSTL_EXE_OPTS) $< $(BINDIR)/$(X)$<
+
+clean:
+dep depend:
--- /dev/null
+#!/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
] [-p ] [-D ] \\"
+ echo " [-E ] [-U ] [-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
--- /dev/null
+#!/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
] [-p ] [-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
--- /dev/null
+#!/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
] [-p ] [-U ] [-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
--- /dev/null
+#!/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
] [-p ] [-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
--- /dev/null
+#!/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
] [-p ] [-U ] [-W] [-d ] \\"
+ 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
+++ /dev/null
-#-------------------------------------------------------------------------
-#
-# 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:
+++ /dev/null
-#!/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
-h -p --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