2010-09-20 22:08:53 +02:00
|
|
|
<!-- doc/src/sgml/start.sgml -->
|
2000-03-31 05:27:42 +02:00
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
<chapter id="tutorial-start">
|
2000-04-07 15:30:58 +02:00
|
|
|
<title>Getting Started</title>
|
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
<sect1 id="tutorial-install">
|
|
|
|
<title>Installation</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Before you can use <productname>PostgreSQL</productname> you need
|
|
|
|
to install it, of course. It is possible that
|
|
|
|
<productname>PostgreSQL</productname> is already installed at your
|
|
|
|
site, either because it was included in your operating system
|
|
|
|
distribution or because the system administrator already installed
|
|
|
|
it. If that is the case, you should obtain information from the
|
|
|
|
operating system documentation or your system administrator about
|
|
|
|
how to access <productname>PostgreSQL</productname>.
|
|
|
|
</para>
|
|
|
|
|
2000-04-07 15:30:58 +02:00
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
If you are not sure whether <productname>PostgreSQL</productname>
|
|
|
|
is already available or whether you can use it for your
|
|
|
|
experimentation then you can install it yourself. Doing so is not
|
|
|
|
hard and it can be a good exercise.
|
|
|
|
<productname>PostgreSQL</productname> can be installed by any
|
2004-06-29 21:57:40 +02:00
|
|
|
unprivileged user; no superuser (<systemitem>root</systemitem>)
|
2001-09-03 01:27:50 +02:00
|
|
|
access is required.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
If you are installing <productname>PostgreSQL</productname>
|
2003-03-25 17:15:44 +01:00
|
|
|
yourself, then refer to <xref linkend="installation">
|
2002-10-20 07:05:46 +02:00
|
|
|
for instructions on installation, and return to
|
2001-09-03 01:27:50 +02:00
|
|
|
this guide when the installation is complete. Be sure to follow
|
|
|
|
closely the section about setting up the appropriate environment
|
|
|
|
variables.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
If your site administrator has not set things up in the default
|
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
|
|
|
way, you might have some more work to do. For example, if the
|
2001-09-03 01:27:50 +02:00
|
|
|
database server machine is a remote machine, you will need to set
|
|
|
|
the <envar>PGHOST</envar> environment variable to the name of the
|
|
|
|
database server machine. The environment variable
|
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
|
|
|
<envar>PGPORT</envar> might also have to be set. The bottom line is
|
2001-09-03 01:27:50 +02:00
|
|
|
this: if you try to start an application program and it complains
|
|
|
|
that it cannot connect to the database, you should consult your
|
|
|
|
site administrator or, if that is you, the documentation to make
|
|
|
|
sure that your environment is properly set up. If you did not
|
|
|
|
understand the preceding paragraph then read the next section.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
2001-09-03 01:27:50 +02:00
|
|
|
</sect1>
|
|
|
|
|
|
|
|
|
|
|
|
<sect1 id="tutorial-arch">
|
|
|
|
<title>Architectural Fundamentals</title>
|
2000-04-07 15:30:58 +02:00
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
Before we proceed, you should understand the basic
|
|
|
|
<productname>PostgreSQL</productname> system architecture.
|
|
|
|
Understanding how the parts of
|
2001-11-28 21:49:10 +01:00
|
|
|
<productname>PostgreSQL</productname> interact will make this
|
2001-09-03 01:27:50 +02:00
|
|
|
chapter somewhat clearer.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
<para>
|
|
|
|
In database jargon, <productname>PostgreSQL</productname> uses a
|
|
|
|
client/server model. A <productname>PostgreSQL</productname>
|
|
|
|
session consists of the following cooperating processes
|
|
|
|
(programs):
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
A server process, which manages the database files, accepts
|
|
|
|
connections to the database from client applications, and
|
2009-06-17 23:58:49 +02:00
|
|
|
performs database actions on behalf of the clients. The
|
2001-09-03 01:27:50 +02:00
|
|
|
database server program is called
|
2006-06-18 17:38:37 +02:00
|
|
|
<filename>postgres</filename>.
|
|
|
|
<indexterm><primary>postgres</primary></indexterm>
|
2001-09-03 01:27:50 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The user's client (frontend) application that wants to perform
|
|
|
|
database operations. Client applications can be very diverse
|
2002-10-20 07:05:46 +02:00
|
|
|
in nature: a client could be a text-oriented tool, a graphical
|
2001-09-03 01:27:50 +02:00
|
|
|
application, a web server that accesses the database to
|
|
|
|
display web pages, or a specialized database maintenance tool.
|
|
|
|
Some client applications are supplied with the
|
2004-06-29 21:57:40 +02:00
|
|
|
<productname>PostgreSQL</productname> distribution; most are
|
2001-09-03 01:27:50 +02:00
|
|
|
developed by users.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
As is typical of client/server applications, the client and the
|
|
|
|
server can be on different hosts. In that case they communicate
|
|
|
|
over a TCP/IP network connection. You should keep this in mind,
|
|
|
|
because the files that can be accessed on a client machine might
|
2001-11-19 06:37:53 +01:00
|
|
|
not be accessible (or might only be accessible using a different
|
2001-11-28 21:49:10 +01:00
|
|
|
file name) on the database server machine.
|
2001-09-03 01:27:50 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The <productname>PostgreSQL</productname> server can handle
|
2009-04-27 18:27:36 +02:00
|
|
|
multiple concurrent connections from clients. To achieve this it
|
2001-09-03 01:27:50 +02:00
|
|
|
starts (<quote>forks</quote>) a new process for each connection.
|
|
|
|
From that point on, the client and the new server process
|
|
|
|
communicate without intervention by the original
|
2006-06-18 17:38:37 +02:00
|
|
|
<filename>postgres</filename> process. Thus, the
|
|
|
|
master server process is always running, waiting for
|
2001-09-03 01:27:50 +02:00
|
|
|
client connections, whereas client and associated server processes
|
|
|
|
come and go. (All of this is of course invisible to the user. We
|
|
|
|
only mention it here for completeness.)
|
|
|
|
</para>
|
2000-04-07 15:30:58 +02:00
|
|
|
</sect1>
|
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
|
|
|
|
<sect1 id="tutorial-createdb">
|
|
|
|
<title>Creating a Database</title>
|
|
|
|
|
|
|
|
<indexterm zone="tutorial-createdb">
|
|
|
|
<primary>database</primary>
|
|
|
|
<secondary>creating</secondary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<indexterm zone="tutorial-createdb">
|
|
|
|
<primary>createdb</primary>
|
|
|
|
</indexterm>
|
2000-04-07 15:30:58 +02:00
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
The first test to see whether you can access the database server
|
|
|
|
is to try to create a database. A running
|
|
|
|
<productname>PostgreSQL</productname> server can manage many
|
|
|
|
databases. Typically, a separate database is used for each
|
|
|
|
project or for each user.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
Possibly, your site administrator has already created a database
|
|
|
|
for your use. He should have told you what the name of your
|
2005-01-08 02:44:08 +01:00
|
|
|
database is. In that case you can omit this step and skip ahead
|
2001-09-03 01:27:50 +02:00
|
|
|
to the next section.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
To create a new database, in this example named
|
2002-01-20 23:19:57 +01:00
|
|
|
<literal>mydb</literal>, you use the following command:
|
2001-09-03 01:27:50 +02:00
|
|
|
<screen>
|
|
|
|
<prompt>$</prompt> <userinput>createdb mydb</userinput>
|
|
|
|
</screen>
|
2007-06-21 12:43:09 +02:00
|
|
|
If this produces no response then this step was successful and you can skip over the
|
2001-09-03 01:27:50 +02:00
|
|
|
remainder of this section.
|
|
|
|
</para>
|
2000-04-07 15:30:58 +02:00
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
<para>
|
2009-04-27 18:27:36 +02:00
|
|
|
If you see a message similar to:
|
2001-09-03 01:27:50 +02:00
|
|
|
<screen>
|
|
|
|
createdb: command not found
|
|
|
|
</screen>
|
2001-11-21 07:09:45 +01:00
|
|
|
then <productname>PostgreSQL</> was not installed properly. Either it was not
|
2009-06-17 23:58:49 +02:00
|
|
|
installed at all or your shell's search path was not set to include it.
|
|
|
|
Try calling the command with an absolute path instead:
|
2001-09-03 01:27:50 +02:00
|
|
|
<screen>
|
2001-11-23 22:08:51 +01:00
|
|
|
<prompt>$</prompt> <userinput>/usr/local/pgsql/bin/createdb mydb</userinput>
|
2001-09-03 01:27:50 +02:00
|
|
|
</screen>
|
|
|
|
The path at your site might be different. Contact your site
|
2009-04-27 18:27:36 +02:00
|
|
|
administrator or check the installation instructions to
|
2001-09-03 01:27:50 +02:00
|
|
|
correct the situation.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Another response could be this:
|
|
|
|
<screen>
|
2009-06-17 23:58:49 +02:00
|
|
|
createdb: could not connect to database postgres: could not connect to server: No such file or directory
|
2001-07-15 15:45:04 +02:00
|
|
|
Is the server running locally and accepting
|
|
|
|
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
|
2001-09-03 01:27:50 +02:00
|
|
|
</screen>
|
|
|
|
This means that the server was not started, or it was not started
|
|
|
|
where <command>createdb</command> expected it. Again, check the
|
|
|
|
installation instructions or consult the administrator.
|
|
|
|
</para>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
<para>
|
2005-01-08 02:44:08 +01:00
|
|
|
Another response could be this:
|
|
|
|
<screen>
|
2006-10-22 01:12:57 +02:00
|
|
|
createdb: could not connect to database postgres: FATAL: role "joe" does not exist
|
2005-01-08 02:44:08 +01:00
|
|
|
</screen>
|
|
|
|
where your own login name is mentioned. This will happen if the
|
|
|
|
administrator has not created a <productname>PostgreSQL</> user account
|
|
|
|
for you. (<productname>PostgreSQL</> user accounts are distinct from
|
|
|
|
operating system user accounts.) If you are the administrator, see
|
|
|
|
<xref linkend="user-manag"> for help creating accounts. You will need to
|
|
|
|
become the operating system user under which <productname>PostgreSQL</>
|
|
|
|
was installed (usually <literal>postgres</>) to create the first user
|
|
|
|
account. It could also be that you were assigned a
|
|
|
|
<productname>PostgreSQL</> user name that is different from your
|
|
|
|
operating system user name; in that case you need to use the <option>-U</>
|
|
|
|
switch or set the <envar>PGUSER</> environment variable to specify your
|
|
|
|
<productname>PostgreSQL</> user name.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If you have a user account but it does not have the privileges required to
|
|
|
|
create a database, you will see the following:
|
2001-09-03 01:27:50 +02:00
|
|
|
<screen>
|
2003-09-13 00:17:24 +02:00
|
|
|
createdb: database creation failed: ERROR: permission denied to create database
|
2001-09-03 01:27:50 +02:00
|
|
|
</screen>
|
|
|
|
Not every user has authorization to create new databases. If
|
|
|
|
<productname>PostgreSQL</productname> refuses to create databases
|
|
|
|
for you then the site administrator needs to grant you permission
|
|
|
|
to create databases. Consult your site administrator if this
|
|
|
|
occurs. If you installed <productname>PostgreSQL</productname>
|
|
|
|
yourself then you should log in for the purposes of this tutorial
|
|
|
|
under the user account that you started the server as.
|
|
|
|
|
|
|
|
<footnote>
|
|
|
|
<para>
|
|
|
|
As an explanation for why this works:
|
|
|
|
<productname>PostgreSQL</productname> user names are separate
|
2006-10-22 01:12:57 +02:00
|
|
|
from operating system user accounts. When you connect to a
|
2001-09-03 01:27:50 +02:00
|
|
|
database, you can choose what
|
|
|
|
<productname>PostgreSQL</productname> user name to connect as;
|
|
|
|
if you don't, it will default to the same name as your current
|
|
|
|
operating system account. As it happens, there will always be a
|
|
|
|
<productname>PostgreSQL</productname> user account that has the
|
|
|
|
same name as the operating system user that started the server,
|
2004-12-17 05:50:32 +01:00
|
|
|
and it also happens that that user always has permission to
|
2001-09-03 01:27:50 +02:00
|
|
|
create databases. Instead of logging in as that user you can
|
|
|
|
also specify the <option>-U</option> option everywhere to select
|
|
|
|
a <productname>PostgreSQL</productname> user name to connect as.
|
|
|
|
</para>
|
|
|
|
</footnote>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
You can also create databases with other names.
|
|
|
|
<productname>PostgreSQL</productname> allows you to create any
|
|
|
|
number of databases at a given site. Database names must have an
|
2002-08-13 22:40:44 +02:00
|
|
|
alphabetic first character and are limited to 63 characters in
|
2001-09-03 01:27:50 +02:00
|
|
|
length. A convenient choice is to create a database with the same
|
|
|
|
name as your current user name. Many tools assume that database
|
|
|
|
name as the default, so it can save you some typing. To create
|
2009-04-27 18:27:36 +02:00
|
|
|
that database, simply type:
|
2001-09-03 01:27:50 +02:00
|
|
|
<screen>
|
|
|
|
<prompt>$</prompt> <userinput>createdb</userinput>
|
|
|
|
</screen>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2003-02-19 05:06:28 +01:00
|
|
|
If you do not want to use your database anymore you can remove it.
|
2001-09-03 01:27:50 +02:00
|
|
|
For example, if you are the owner (creator) of the database
|
2002-01-20 23:19:57 +01:00
|
|
|
<literal>mydb</literal>, you can destroy it using the following
|
2001-09-03 01:27:50 +02:00
|
|
|
command:
|
|
|
|
<screen>
|
|
|
|
<prompt>$</prompt> <userinput>dropdb mydb</userinput>
|
|
|
|
</screen>
|
2001-11-23 22:08:51 +01:00
|
|
|
(For this command, the database name does not default to the user
|
2001-09-03 01:27:50 +02:00
|
|
|
account name. You always need to specify it.) This action
|
|
|
|
physically removes all files associated with the database and
|
|
|
|
cannot be undone, so this should only be done with a great deal of
|
|
|
|
forethought.
|
|
|
|
</para>
|
2003-06-25 01:26:46 +02:00
|
|
|
|
|
|
|
<para>
|
Update documentation on may/can/might:
Standard English uses "may", "can", and "might" in different ways:
may - permission, "You may borrow my rake."
can - ability, "I can lift that log."
might - possibility, "It might rain today."
Unfortunately, in conversational English, their use is often mixed, as
in, "You may use this variable to do X", when in fact, "can" is a better
choice. Similarly, "It may crash" is better stated, "It might crash".
Also update two error messages mentioned in the documenation to match.
2007-01-31 21:56:20 +01:00
|
|
|
More about <command>createdb</command> and <command>dropdb</command> can
|
2003-06-25 01:26:46 +02:00
|
|
|
be found in <xref linkend="APP-CREATEDB"> and <xref linkend="APP-DROPDB">
|
|
|
|
respectively.
|
|
|
|
</para>
|
2001-09-03 01:27:50 +02:00
|
|
|
</sect1>
|
1998-03-01 09:16:16 +01:00
|
|
|
|
2000-04-07 15:30:58 +02:00
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
<sect1 id="tutorial-accessdb">
|
|
|
|
<title>Accessing a Database</title>
|
|
|
|
|
|
|
|
<indexterm zone="tutorial-accessdb">
|
|
|
|
<primary>psql</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Once you have created a database, you can access it by:
|
|
|
|
|
|
|
|
<itemizedlist spacing="compact" mark="bullet">
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Running the <productname>PostgreSQL</productname> interactive
|
2002-01-20 23:19:57 +01:00
|
|
|
terminal program, called <application><firstterm>psql</></application>, which allows you
|
2001-09-03 01:27:50 +02:00
|
|
|
to interactively enter, edit, and execute
|
|
|
|
<acronym>SQL</acronym> commands.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2000-04-07 15:30:58 +02:00
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
Using an existing graphical frontend tool like
|
2008-01-23 03:04:47 +01:00
|
|
|
<application>pgAdmin</application> or an office suite with
|
2009-04-27 18:27:36 +02:00
|
|
|
<acronym>ODBC</> or <acronym>JDBC</> support to create and manipulate a
|
2002-11-11 21:14:04 +01:00
|
|
|
database. These possibilities are not covered in this
|
|
|
|
tutorial.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
Writing a custom application, using one of the several
|
|
|
|
available language bindings. These possibilities are discussed
|
2003-03-25 17:15:44 +01:00
|
|
|
further in <xref linkend="client-interfaces">.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
2001-09-03 01:27:50 +02:00
|
|
|
|
2009-04-27 18:27:36 +02:00
|
|
|
You probably want to start up <command>psql</command> to try
|
2001-09-03 01:27:50 +02:00
|
|
|
the examples in this tutorial. It can be activated for the
|
2002-01-20 23:19:57 +01:00
|
|
|
<literal>mydb</literal> database by typing the command:
|
2001-09-03 01:27:50 +02:00
|
|
|
<screen>
|
|
|
|
<prompt>$</prompt> <userinput>psql mydb</userinput>
|
|
|
|
</screen>
|
2009-04-27 18:27:36 +02:00
|
|
|
If you do not supply the database name then it will default to your
|
2001-09-03 01:27:50 +02:00
|
|
|
user account name. You already discovered this scheme in the
|
2009-04-27 18:27:36 +02:00
|
|
|
previous section using <command>createdb</command>.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
In <command>psql</command>, you will be greeted with the following
|
|
|
|
message:
|
|
|
|
<screen>
|
2008-05-16 19:17:00 +02:00
|
|
|
psql (&version;)
|
|
|
|
Type "help" for help.
|
2010-11-23 21:27:50 +01:00
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
mydb=>
|
|
|
|
</screen>
|
|
|
|
<indexterm><primary>superuser</primary></indexterm>
|
2009-04-27 18:27:36 +02:00
|
|
|
The last line could also be:
|
2001-09-03 01:27:50 +02:00
|
|
|
<screen>
|
|
|
|
mydb=#
|
|
|
|
</screen>
|
|
|
|
That would mean you are a database superuser, which is most likely
|
|
|
|
the case if you installed <productname>PostgreSQL</productname>
|
|
|
|
yourself. Being a superuser means that you are not subject to
|
2009-04-27 18:27:36 +02:00
|
|
|
access controls. For the purposes of this tutorial that is not
|
|
|
|
important.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
2001-09-03 01:27:50 +02:00
|
|
|
<para>
|
2005-01-08 02:44:08 +01:00
|
|
|
If you encounter problems starting <command>psql</command>
|
2001-09-03 01:27:50 +02:00
|
|
|
then go back to the previous section. The diagnostics of
|
2005-01-08 02:44:08 +01:00
|
|
|
<command>createdb</command> and <command>psql</command> are
|
|
|
|
similar, and if the former worked the latter should work as well.
|
2001-09-03 01:27:50 +02:00
|
|
|
</para>
|
2000-04-07 15:30:58 +02:00
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
The last line printed out by <command>psql</command> is the
|
|
|
|
prompt, and it indicates that <command>psql</command> is listening
|
|
|
|
to you and that you can type <acronym>SQL</acronym> queries into a
|
2002-01-20 23:19:57 +01:00
|
|
|
work space maintained by <command>psql</command>. Try out these
|
2001-09-03 01:27:50 +02:00
|
|
|
commands:
|
|
|
|
<indexterm><primary>version</primary></indexterm>
|
|
|
|
<screen>
|
|
|
|
<prompt>mydb=></prompt> <userinput>SELECT version();</userinput>
|
2009-01-06 04:05:23 +01:00
|
|
|
version
|
|
|
|
-----------------------------------------------------------------------
|
|
|
|
PostgreSQL &version; on i586-pc-linux-gnu, compiled by GCC 2.96, 32-bit
|
2001-09-03 01:27:50 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
<prompt>mydb=></prompt> <userinput>SELECT current_date;</userinput>
|
|
|
|
date
|
|
|
|
------------
|
2002-10-20 07:05:46 +02:00
|
|
|
2002-08-31
|
2001-09-03 01:27:50 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
<prompt>mydb=></prompt> <userinput>SELECT 2 + 2;</userinput>
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
4
|
|
|
|
(1 row)
|
|
|
|
</screen>
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2001-09-03 01:27:50 +02:00
|
|
|
The <command>psql</command> program has a number of internal
|
2001-11-19 06:37:53 +01:00
|
|
|
commands that are not SQL commands. They begin with the backslash
|
2009-12-19 03:34:17 +01:00
|
|
|
character, <quote><literal>\</literal></quote>.
|
|
|
|
For example,
|
2001-09-03 01:27:50 +02:00
|
|
|
you can get help on the syntax of various
|
|
|
|
<productname>PostgreSQL</productname> <acronym>SQL</acronym>
|
|
|
|
commands by typing:
|
|
|
|
<screen>
|
|
|
|
<prompt>mydb=></prompt> <userinput>\h</userinput>
|
|
|
|
</screen>
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2009-04-27 18:27:36 +02:00
|
|
|
To get out of <command>psql</command>, type:
|
2001-09-03 01:27:50 +02:00
|
|
|
<screen>
|
|
|
|
<prompt>mydb=></prompt> <userinput>\q</userinput>
|
|
|
|
</screen>
|
|
|
|
and <command>psql</command> will quit and return you to your
|
|
|
|
command shell. (For more internal commands, type
|
|
|
|
<literal>\?</literal> at the <command>psql</command> prompt.) The
|
2002-10-20 07:05:46 +02:00
|
|
|
full capabilities of <command>psql</command> are documented in
|
2003-08-10 03:20:34 +02:00
|
|
|
<xref linkend="app-psql">. If <productname>PostgreSQL</> is
|
2001-09-03 01:27:50 +02:00
|
|
|
installed correctly you can also type <literal>man psql</literal>
|
|
|
|
at the operating system shell prompt to see the documentation. In
|
|
|
|
this tutorial we will not use these features explicitly, but you
|
2009-04-27 18:27:36 +02:00
|
|
|
can use them yourself when it is helpful.
|
2000-04-07 15:30:58 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect1>
|
|
|
|
</chapter>
|