gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

77 lines
8.0KB

  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>CREATE TABLESPACE</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="sql-createtableas.html" title="CREATE TABLE AS" /><link rel="next" href="sql-createtsconfig.html" title="CREATE TEXT SEARCH CONFIGURATION" /></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">CREATE TABLESPACE</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createtableas.html" title="CREATE TABLE AS">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</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="sql-createtsconfig.html" title="CREATE TEXT SEARCH CONFIGURATION">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-CREATETABLESPACE"><div class="titlepage"></div><a id="id-1.9.3.87.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE TABLESPACE</span></h2><p>CREATE TABLESPACE — define a new tablespace</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
  3. CREATE TABLESPACE <em class="replaceable"><code>tablespace_name</code></em>
  4. [ OWNER { <em class="replaceable"><code>new_owner</code></em> | CURRENT_USER | SESSION_USER } ]
  5. LOCATION '<em class="replaceable"><code>directory</code></em>'
  6. [ WITH ( <em class="replaceable"><code>tablespace_option</code></em> = <em class="replaceable"><code>value</code></em> [, ... ] ) ]
  7. </pre></div><div class="refsect1" id="id-1.9.3.87.5"><h2>Description</h2><p>
  8. <code class="command">CREATE TABLESPACE</code> registers a new cluster-wide
  9. tablespace. The tablespace name must be distinct from the name of any
  10. existing tablespace in the database cluster.
  11. </p><p>
  12. A tablespace allows superusers to define an alternative location on
  13. the file system where the data files containing database objects
  14. (such as tables and indexes) can reside.
  15. </p><p>
  16. A user with appropriate privileges can pass
  17. <em class="replaceable"><code>tablespace_name</code></em> to
  18. <code class="command">CREATE DATABASE</code>, <code class="command">CREATE TABLE</code>,
  19. <code class="command">CREATE INDEX</code> or <code class="command">ADD CONSTRAINT</code> to have the data
  20. files for these objects stored within the specified tablespace.
  21. </p><div class="warning"><h3 class="title">Warning</h3><p>
  22. A tablespace cannot be used independently of the cluster in which it
  23. is defined; see <a class="xref" href="manage-ag-tablespaces.html" title="22.6. Tablespaces">Section 22.6</a>.
  24. </p></div></div><div class="refsect1" id="id-1.9.3.87.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>tablespace_name</code></em></span></dt><dd><p>
  25. The name of a tablespace to be created. The name cannot
  26. begin with <code class="literal">pg_</code>, as such names
  27. are reserved for system tablespaces.
  28. </p></dd><dt><span class="term"><em class="replaceable"><code>user_name</code></em></span></dt><dd><p>
  29. The name of the user who will own the tablespace. If omitted,
  30. defaults to the user executing the command. Only superusers
  31. can create tablespaces, but they can assign ownership of tablespaces
  32. to non-superusers.
  33. </p></dd><dt><span class="term"><em class="replaceable"><code>directory</code></em></span></dt><dd><p>
  34. The directory that will be used for the tablespace. The directory
  35. must exist (<code class="command">CREATE TABLESPACE</code> will not create it),
  36. should be empty, and must be owned by the
  37. <span class="productname">PostgreSQL</span> system user. The directory must be
  38. specified by an absolute path name.
  39. </p></dd><dt><span class="term"><em class="replaceable"><code>tablespace_option</code></em></span></dt><dd><p>
  40. A tablespace parameter to be set or reset. Currently, the only
  41. available parameters are <code class="varname">seq_page_cost</code>,
  42. <code class="varname">random_page_cost</code> and <code class="varname">effective_io_concurrency</code>.
  43. Setting either value for a particular tablespace will override the
  44. planner's usual estimate of the cost of reading pages from tables in
  45. that tablespace, as established by the configuration parameters of the
  46. same name (see <a class="xref" href="runtime-config-query.html#GUC-SEQ-PAGE-COST">seq_page_cost</a>,
  47. <a class="xref" href="runtime-config-query.html#GUC-RANDOM-PAGE-COST">random_page_cost</a>,
  48. <a class="xref" href="runtime-config-resource.html#GUC-EFFECTIVE-IO-CONCURRENCY">effective_io_concurrency</a>). This may be useful if
  49. one tablespace is located on a disk which is faster or slower than the
  50. remainder of the I/O subsystem.
  51. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.87.7"><h2>Notes</h2><p>
  52. Tablespaces are only supported on systems that support symbolic links.
  53. </p><p>
  54. <code class="command">CREATE TABLESPACE</code> cannot be executed inside a transaction
  55. block.
  56. </p></div><div class="refsect1" id="id-1.9.3.87.8"><h2>Examples</h2><p>
  57. To create a tablespace <code class="literal">dbspace</code> at file system location
  58. <code class="literal">/data/dbs</code>, first create the directory using operating
  59. system facilities and set the correct ownership:
  60. </p><pre class="programlisting">
  61. mkdir /data/dbs
  62. chown postgres:postgres /data/dbs
  63. </pre><p>
  64. Then issue the tablespace creation command inside
  65. <span class="productname">PostgreSQL</span>:
  66. </p><pre class="programlisting">
  67. CREATE TABLESPACE dbspace LOCATION '/data/dbs';
  68. </pre><p>
  69. </p><p>
  70. To create a tablespace owned by a different database user, use a command
  71. like this:
  72. </p><pre class="programlisting">
  73. CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
  74. </pre></div><div class="refsect1" id="id-1.9.3.87.9"><h2>Compatibility</h2><p>
  75. <code class="command">CREATE TABLESPACE</code> is a <span class="productname">PostgreSQL</span>
  76. extension.
  77. </p></div><div class="refsect1" id="id-1.9.3.87.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a>, <a class="xref" href="sql-createtable.html" title="CREATE TABLE"><span class="refentrytitle">CREATE TABLE</span></a>, <a class="xref" href="sql-createindex.html" title="CREATE INDEX"><span class="refentrytitle">CREATE INDEX</span></a>, <a class="xref" href="sql-droptablespace.html" title="DROP TABLESPACE"><span class="refentrytitle">DROP TABLESPACE</span></a>, <a class="xref" href="sql-altertablespace.html" title="ALTER TABLESPACE"><span class="refentrytitle">ALTER TABLESPACE</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createtableas.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createtsconfig.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE TABLE AS </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> CREATE TEXT SEARCH CONFIGURATION</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1