]> begriffs open source - ai-pg/blob - full-docs/html/tutorial-accessdb.html
Include latest toc output
[ai-pg] / full-docs / html / tutorial-accessdb.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>1.4. Accessing a Database</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="tutorial-createdb.html" title="1.3. Creating a Database" /><link rel="next" href="tutorial-sql.html" title="Chapter 2. The SQL Language" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">1.4. Accessing a Database</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="tutorial-createdb.html" title="1.3. Creating a Database">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="tutorial-start.html" title="Chapter 1. Getting Started">Up</a></td><th width="60%" align="center">Chapter 1. Getting Started</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="tutorial-sql.html" title="Chapter 2. The SQL Language">Next</a></td></tr></table><hr /></div><div class="sect1" id="TUTORIAL-ACCESSDB"><div class="titlepage"><div><div><h2 class="title" style="clear: both">1.4. Accessing a Database <a href="#TUTORIAL-ACCESSDB" class="id_link">#</a></h2></div></div></div><a id="id-1.4.3.5.2" class="indexterm"></a><p>
3     Once you have created a database, you can access it by:
4
5     </p><div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: bullet; "><li class="listitem" style="list-style-type: disc"><p>
6        Running the <span class="productname">PostgreSQL</span> interactive
7        terminal program, called <span class="application"><em class="firstterm">psql</em></span>, which allows you
8        to interactively enter, edit, and execute
9        <acronym class="acronym">SQL</acronym> commands.
10       </p></li><li class="listitem" style="list-style-type: disc"><p>
11        Using an existing graphical frontend tool like
12        <span class="application">pgAdmin</span> or an office suite with
13        <acronym class="acronym">ODBC</acronym> or <acronym class="acronym">JDBC</acronym> support to create and manipulate a
14        database.  These possibilities are not covered in this
15        tutorial.
16       </p></li><li class="listitem" style="list-style-type: disc"><p>
17        Writing a custom application, using one of the several
18        available language bindings.  These possibilities are discussed
19        further in <a class="xref" href="client-interfaces.html" title="Part IV. Client Interfaces">Part IV</a>.
20       </p></li></ul></div><p>
21
22     You probably want to start up <code class="command">psql</code> to try
23     the examples in this tutorial.  It can be activated for the
24     <code class="literal">mydb</code> database by typing the command:
25 </p><pre class="screen">
26 <code class="prompt">$</code> <strong class="userinput"><code>psql mydb</code></strong>
27 </pre><p>
28     If you do not supply the database name then it will default to your
29     user account name.  You already discovered this scheme in the
30     previous section using <code class="command">createdb</code>.
31    </p><p>
32     In <code class="command">psql</code>, you will be greeted with the following
33     message:
34 </p><pre class="screen">
35 psql (18.0)
36 Type "help" for help.
37
38 mydb=&gt;
39 </pre><p>
40     <a id="id-1.4.3.5.4.3" class="indexterm"></a>
41     The last line could also be:
42 </p><pre class="screen">
43 mydb=#
44 </pre><p>
45     That would mean you are a database superuser, which is most likely
46     the case if you installed the <span class="productname">PostgreSQL</span> instance
47     yourself.  Being a superuser means that you are not subject to
48     access controls.  For the purposes of this tutorial that is not
49     important.
50    </p><p>
51     If you encounter problems starting <code class="command">psql</code>
52     then go back to the previous section.  The diagnostics of
53     <code class="command">createdb</code> and <code class="command">psql</code> are
54     similar, and if the former worked the latter should work as well.
55    </p><p>
56     The last line printed out by <code class="command">psql</code> is the
57     prompt, and it indicates that <code class="command">psql</code> is listening
58     to you and that you can type <acronym class="acronym">SQL</acronym> queries into a
59     work space maintained by <code class="command">psql</code>.  Try out these
60     commands:
61     <a id="id-1.4.3.5.6.5" class="indexterm"></a>
62 </p><pre class="screen">
63 <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>SELECT version();</code></strong>
64                                          version
65 -------------------------------------------------------------------​-----------------------
66  PostgreSQL 18.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
67 (1 row)
68
69 <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>SELECT current_date;</code></strong>
70     date
71 ------------
72  2016-01-07
73 (1 row)
74
75 <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>SELECT 2 + 2;</code></strong>
76  ?column?
77 ----------
78         4
79 (1 row)
80 </pre><p>
81    </p><p>
82     The <code class="command">psql</code> program has a number of internal
83     commands that are not SQL commands.  They begin with the backslash
84     character, <span class="quote">“<span class="quote"><code class="literal">\</code></span>”</span>.
85     For example,
86     you can get help on the syntax of various
87     <span class="productname">PostgreSQL</span> <acronym class="acronym">SQL</acronym>
88     commands by typing:
89 </p><pre class="screen">
90 <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>\h</code></strong>
91 </pre><p>
92    </p><p>
93     To get out of <code class="command">psql</code>, type:
94 </p><pre class="screen">
95 <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>\q</code></strong>
96 </pre><p>
97     and <code class="command">psql</code> will quit and return you to your
98     command shell. (For more internal commands, type
99     <code class="literal">\?</code> at the <code class="command">psql</code> prompt.)  The
100     full capabilities of <code class="command">psql</code> are documented in
101     <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a>.  In this tutorial we will not use these
102     features explicitly, but you can use them yourself when it is helpful.
103    </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tutorial-createdb.html" title="1.3. Creating a Database">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tutorial-start.html" title="Chapter 1. Getting Started">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="tutorial-sql.html" title="Chapter 2. The SQL Language">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1.3. Creating a Database </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> Chapter 2. The <acronym class="acronym">SQL</acronym> Language</td></tr></table></div></body></html>