To create a new database named <Quote>mydb</Quote> from the command line, type
To create a new database named <Quote>mydb</Quote> from the command line, type
<ProgramListing>
<ProgramListing>
% createdb mydb
% createdb mydb
</ProgramListing>
</ProgramListing>
and to do the same from within <Application>psql</Application> type
and to do the same from within <Application>psql</Application> type
<ProgramListing>
<ProgramListing>
* CREATE DATABASE mydb;
=> CREATE DATABASE mydb;
</ProgramListing>
</ProgramListing>
</Para>
</Para>
<Para>
<Para>
If you do not have the privileges required to create a database, you will see
If you do not have the privileges required to create a database, you will see
the following:
the following:
<ProgramListing>
<ProgramListing>
% createdb mydb
ERROR: CREATE DATABASE: Permission denied.
WARN:user "your username" is not allowed to create/destroy databases
</ProgramListing>
createdb: database creation failed on mydb.
</ProgramListing>
</Para>
</Para>
<Para>
<Para>
...
@@ -123,45 +121,41 @@ createdb: database creation failed on mydb.
...
@@ -123,45 +121,41 @@ createdb: database creation failed on mydb.
ensure that <FileName>/alt/postgres</FileName> already exists and is writable by
ensure that <FileName>/alt/postgres</FileName> already exists and is writable by
the Postgres administrator account.
the Postgres administrator account.
Then, from the command line, type
Then, from the command line, type
<ProgramListing>
<ProgramListing>
% initlocation $PGDATA2
% initlocation PGDATA2
Creating Postgres database system directory /alt/postgres/data
Creating Postgres database system directory /alt/postgres/data
Creating Postgres database system directory /alt/postgres/data/base
Creating Postgres database system directory /alt/postgres/data/base
</ProgramListing>
</ProgramListing>
</Para>
</Para>
<Para>
<Para>
To create a database in the alternate storage area <envar>PGDATA2</envar>
To create a database in the alternate storage area <envar>PGDATA2</envar>
from the command line, use the following command:
from the command line, use the following command:
<ProgramListing>
<ProgramListing>
% createdb -D PGDATA2 mydb
% createdb -D PGDATA2 mydb
</ProgramListing>
</ProgramListing>
and to do the same from within <Application>psql</Application> type
and to do the same from within <Application>psql</Application> type
<ProgramListing>
<ProgramListing>
* CREATE DATABASE mydb WITH LOCATION = 'PGDATA2';
=> CREATE DATABASE mydb WITH LOCATION = 'PGDATA2';
</ProgramListing>
</ProgramListing>
</Para>
</Para>
<Para>
<Para>
If you do not have the privileges required to create a database, you will see
If you do not have the privileges required to create a database, you will see
the following:
the following:
<ProgramListing>
<ProgramListing>
% createdb mydb
ERROR: CREATE DATABASE: permission denied
WARN:user "your username" is not allowed to create/destroy databases
</ProgramListing>
createdb: database creation failed on mydb.
</ProgramListing>
</Para>
</Para>
<Para>
<Para>
If the specified location does not exist or the database backend does not have
If the specified location does not exist or the database backend does not have
permission to access it or to write to directories under it, you will see
permission to access it or to write to directories under it, you will see
the following:
the following:
<ProgramListing>
<ProgramListing>
% createdb -D /alt/postgres/data mydb
ERROR: The database path '/no/where' is invalid. This may be due to a character that is not allowed or because the chosen path isn't permitted for databases.
ERROR: Unable to create database directory /alt/postgres/data/base/mydb
</ProgramListing>
createdb: database creation failed on mydb.
</ProgramListing>
</Para>
</Para>
</Sect1>
</Sect1>
...
@@ -176,9 +170,9 @@ createdb: database creation failed on mydb.
...
@@ -176,9 +170,9 @@ createdb: database creation failed on mydb.
<ItemizedList Mark="bullet" Spacing="compact">
<ItemizedList Mark="bullet" Spacing="compact">
<ListItem>
<ListItem>
<Para>
<Para>
running the <ProductName>Postgres</ProductName> terminal monitor programs (e.g.
running the <ProductName>PostgreSQL</ProductName> interactive terminal
<Application>psql</Application>) which allows you to interactively
<Application>psql</Application> which allows you to interactively
enter, edit, and execute <Acronym>SQL</Acronym> commands.
enter, edit, and execute <Acronym>SQL</Acronym> commands.
</Para>
</Para>
</ListItem>
</ListItem>
<ListItem>
<ListItem>
...
@@ -202,26 +196,26 @@ to try out the examples in this manual.
...
@@ -202,26 +196,26 @@ to try out the examples in this manual.
You will be greeted with the following message:
You will be greeted with the following message:
<ProgramListing>
<ProgramListing>
Welcome to the POSTGRESQL interactive sql monitor:
Welcome to psql, the PostgreSQL interactive terminal.
Please read the file COPYRIGHT for copyright terms of POSTGRESQL
Type: \copyright for distribution terms
type \? for help on slash commands
\h for help with SQL commands
type \q to quit
\? for help on internal slash commands
type \g or terminate with semicolon to execute query
\g or terminate with semicolon to execute query
You are currently connected to the database: template1
\q to quit
mydb=>
mydb=>
</ProgramListing>
</ProgramListing>
</Para>
</Para>
<Para>
<Para>
This prompt indicates that the terminal monitor is listening
This prompt indicates that psql is listening
to you and that you can type <Acronym>SQL</Acronym> queries into a
to you and that you can type <Acronym>SQL</Acronym> queries into a
workspace maintained by the terminal monitor.
workspace maintained by the terminal monitor.
The <Application>psql</Application> program responds to escape codes that begin
The <Application>psql</Application> program responds to escape codes that begin
with the backslash character, <Quote>\</Quote> For example, you
with the backslash character, <Quote>\</Quote> For example, you
can get help on the syntax of various
can get help on the syntax of various
<ProductName>Postgres</ProductName> <Acronym>SQL</Acronym> commands by typing:
<ProductName>PostgreSQL</ProductName> <Acronym>SQL</Acronym> commands by typing:
<ProgramListing>
<ProgramListing>
mydb=> \h
mydb=> \h
</ProgramListing>
</ProgramListing>
...
@@ -249,7 +243,7 @@ mydb=> \q
...
@@ -249,7 +243,7 @@ mydb=> \q
</ProgramListing>
</ProgramListing>
and <Application>psql</Application> will quit and return you to your command
and <Application>psql</Application> will quit and return you to your command
shell. (For more escape codes, type <Command>\h</Command> at the monitor
shell. (For more escape codes, type <Command>\?</Command> at the psql
prompt.)
prompt.)
White space (i.e., spaces, tabs and newlines) may be
White space (i.e., spaces, tabs and newlines) may be
used freely in <Acronym>SQL</Acronym> queries. Single-line comments are denoted by
used freely in <Acronym>SQL</Acronym> queries. Single-line comments are denoted by
...
@@ -280,14 +274,14 @@ TBD
...
@@ -280,14 +274,14 @@ TBD
<Title>Destroying a Database</Title>
<Title>Destroying a Database</Title>
<Para>
<Para>
If you are the database administrator for the database
If you are the owner of the database
<Database>mydb</Database>, you can destroy it using the following Unix command:
<Database>mydb</Database>, you can destroy it using the following Unix command:
<ProgramListing>
<ProgramListing>
% dropdb mydb
% dropdb mydb
</ProgramListing>
</ProgramListing>
This action physically removes all of the Unix files
This action physically removes all of the Unix files
associated with the database and cannot be undone, so
associated with the database and cannot be undone, so
this should only be done with a great deal of forethought.
this should only be done with a great deal of forethought.