can be activated for the
<literal>mydb</literal> database by typing the command:
<screen>
<prompt>$</prompt> <userinput>psql mydb</userinput>
</screen>
If you do not supply the database name then it will default to your
user account name. You already discovered this scheme in the
previous section using <command>createdb</command>.
</para>
<para>
In <command>psql</command>, you will be greeted with the following
message:
<screen>
psql (&version;)
Type "help" for help.
mydb=>
</screen>
<indexterm><primary>superuser</primary></indexterm>
The last line could also be:
<screen>
mydb=#
</screen>
That would mean you are a database superuser, which is most likely
the case if you installed the <productname>PostgreSQL</productname> instance
yourself. Being a superuser means that you are not subject to
access controls. For the purposes of this tutorial that is not
important.
</para>
<para>
If you encounter problems starting <command>psql</command>
then go back to the previous section. The diagnostics of
<command>createdb</command> and <command>psql</command> are
similar, and if the former worked the latter should work as well.
</para>
<para>
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
work space maintained by <command>psql</command>. Try out these
commands:
<indexterm><primary>version</primary></indexterm>
<screen>
<prompt>mydb=></prompt> <userinput>SELECT version();</userinput>
version
-------------------------------------------------------------------&zwsp;-----------------------
PostgreSQL &version; on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
(1 row)
<prompt>mydb=></prompt> <userinput>SELECT current_date;</userinput>
date
------------
2016-01-07
(1 row)
<prompt>mydb=></prompt> <userinput>SELECT 2 + 2;</userinput>
?column?
----------
4
(1 row)
</screen>
</para>
<para>
The <command>psql</command> program has a number of internal
commands that are not SQL commands. They begin with the backslash
character, <quote><literal>\</literal></quote>.
For example,
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>
</para>
<para>
To get out of <command>psql</command>, type:
<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
full capabilities of <command>psql</command> are documented in
<xref linkend="app-psql"/>. In this tutorial we will not use these
features explicitly, but you can use them yourself when it is helpful.
</para>
</sect1>
</chapter>