gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

103 行
7.3KB

  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 V1.79.1" /><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><div xmlns="http://www.w3.org/TR/xhtml1/transitional" 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 12.4 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></hr></div><div class="sect1" id="TUTORIAL-ACCESSDB"><div class="titlepage"><div><div><h2 class="title" style="clear: both">1.4. Accessing a Database</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. </p><div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: bullet; "><li class="listitem" style="list-style-type: disc"><p>
  5. Running the <span class="productname">PostgreSQL</span> interactive
  6. terminal program, called <span class="application"><em class="firstterm">psql</em></span>, which allows you
  7. to interactively enter, edit, and execute
  8. <acronym class="acronym">SQL</acronym> commands.
  9. </p></li><li class="listitem" style="list-style-type: disc"><p>
  10. Using an existing graphical frontend tool like
  11. <span class="application">pgAdmin</span> or an office suite with
  12. <acronym class="acronym">ODBC</acronym> or <acronym class="acronym">JDBC</acronym> support to create and manipulate a
  13. database. These possibilities are not covered in this
  14. tutorial.
  15. </p></li><li class="listitem" style="list-style-type: disc"><p>
  16. Writing a custom application, using one of the several
  17. available language bindings. These possibilities are discussed
  18. further in <a class="xref" href="client-interfaces.html" title="Part IV. Client Interfaces">Part IV</a>.
  19. </p></li></ul></div><p>
  20. You probably want to start up <code class="command">psql</code> to try
  21. the examples in this tutorial. It can be activated for the
  22. <code class="literal">mydb</code> database by typing the command:
  23. </p><pre class="screen">
  24. <code class="prompt">$</code> <strong class="userinput"><code>psql mydb</code></strong>
  25. </pre><p>
  26. If you do not supply the database name then it will default to your
  27. user account name. You already discovered this scheme in the
  28. previous section using <code class="command">createdb</code>.
  29. </p><p>
  30. In <code class="command">psql</code>, you will be greeted with the following
  31. message:
  32. </p><pre class="screen">
  33. psql (12.4)
  34. Type "help" for help.
  35. mydb=&gt;
  36. </pre><p>
  37. <a id="id-1.4.3.5.4.3" class="indexterm"></a>
  38. The last line could also be:
  39. </p><pre class="screen">
  40. mydb=#
  41. </pre><p>
  42. That would mean you are a database superuser, which is most likely
  43. the case if you installed the <span class="productname">PostgreSQL</span> instance
  44. yourself. Being a superuser means that you are not subject to
  45. access controls. For the purposes of this tutorial that is not
  46. important.
  47. </p><p>
  48. If you encounter problems starting <code class="command">psql</code>
  49. then go back to the previous section. The diagnostics of
  50. <code class="command">createdb</code> and <code class="command">psql</code> are
  51. similar, and if the former worked the latter should work as well.
  52. </p><p>
  53. The last line printed out by <code class="command">psql</code> is the
  54. prompt, and it indicates that <code class="command">psql</code> is listening
  55. to you and that you can type <acronym class="acronym">SQL</acronym> queries into a
  56. work space maintained by <code class="command">psql</code>. Try out these
  57. commands:
  58. <a id="id-1.4.3.5.6.5" class="indexterm"></a>
  59. </p><pre class="screen">
  60. <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>SELECT version();</code></strong>
  61. version
  62. ------------------------------------------------------------------------------------------
  63. PostgreSQL 12.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
  64. (1 row)
  65. <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>SELECT current_date;</code></strong>
  66. date
  67. ------------
  68. 2016-01-07
  69. (1 row)
  70. <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>SELECT 2 + 2;</code></strong>
  71. ?column?
  72. ----------
  73. 4
  74. (1 row)
  75. </pre><p>
  76. </p><p>
  77. The <code class="command">psql</code> program has a number of internal
  78. commands that are not SQL commands. They begin with the backslash
  79. character, <span class="quote">“<span class="quote"><code class="literal">\</code></span>”</span>.
  80. For example,
  81. you can get help on the syntax of various
  82. <span class="productname">PostgreSQL</span> <acronym class="acronym">SQL</acronym>
  83. commands by typing:
  84. </p><pre class="screen">
  85. <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>\h</code></strong>
  86. </pre><p>
  87. </p><p>
  88. To get out of <code class="command">psql</code>, type:
  89. </p><pre class="screen">
  90. <code class="prompt">mydb=&gt;</code> <strong class="userinput"><code>\q</code></strong>
  91. </pre><p>
  92. and <code class="command">psql</code> will quit and return you to your
  93. command shell. (For more internal commands, type
  94. <code class="literal">\?</code> at the <code class="command">psql</code> prompt.) The
  95. full capabilities of <code class="command">psql</code> are documented in
  96. <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
  97. features explicitly, but you can use them yourself when it is helpful.
  98. </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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tutorial-start.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="tutorial-sql.html">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">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>
上海开阖软件有限公司 沪ICP备12045867号-1