📄 create_database.sgml
字号:
<refentry id="SQL-CREATEDATABASE"> <refmeta> <refentrytitle> CREATE DATABASE </refentrytitle> <refmiscinfo>SQL - Language Statements</refmiscinfo> </refmeta> <refnamediv> <refname> CREATE DATABASE </refname> <refpurpose> Creates a new database </refpurpose> </refnamediv> <refsynopsisdiv> <refsynopsisdivinfo> <date>1998-04-15</date> </refsynopsisdivinfo> <synopsis>CREATE DATABASE <replaceable class="PARAMETER">name</replaceable> [ WITH LOCATION = '<replaceable class="parameter">dbpath</replaceable>' ] </synopsis> <refsect2 id="R2-SQL-CREATEDATABASE-1"> <refsect2info> <date>1998-04-15</date> </refsect2info> <title> Inputs </title> <para> <variablelist> <varlistentry> <term><replaceable class="parameter">name</replaceable></term> <listitem> <para> The name of a database to create. </para> </listitem> </varlistentry> <varlistentry> <term><replaceable class="parameter">dbpath</replaceable></term> <listitem> <para> An alternate location can be specified as either an environment variable known to the backend server (e.g. '<envar>PGDATA2</envar>') or as an absolute path name (e.g. '<filename>/usr/local/pgsql/data</filename>'). In either case, the location must be pre-configured by <command>initlocation</command>. </para> </listitem> </varlistentry> </variablelist> </para> </refsect2> <refsect2 id="R2-SQL-CREATEDATABASE-2"> <refsect2info> <date>1998-04-15</date> </refsect2info> <title> Outputs </title> <para> <variablelist> <varlistentry> <term><computeroutput>CREATEDB </computeroutput></term> <listitem> <para> Message returned if the command completes successfully. </para> </listitem> </varlistentry> <varlistentry> <term><computeroutput>WARN: createdb: database "<replaceable class="parameter">name</replaceable>" already exists. </computeroutput></term> <listitem> <para> This occurs if <replaceable class="parameter">database</replaceable> specified already exists. </para> </listitem> </varlistentry> <varlistentry> <term><computeroutput>ERROR: Unable to create database directory <replaceable class="parameter">directory</replaceable> </computeroutput></term> <listitem> <para> There was a problem with creating the required directory; this operation will need permissions for the <literal>postgres</literal> user on the specified location. </para> </listitem> </varlistentry> </variablelist> </para> </refsect2> </refsynopsisdiv> <refsect1 id="R1-SQL-CREATEDATABASE-1"> <refsect1info> <date>1998-04-15</date> </refsect1info> <title> Description </title> <para> <command>CREATE DATABASE</command> creates a new Postgres database. The creator becomes the administrator of the new database. </para> <refsect2 id="R2-SQL-CREATEDATABASE-3"> <refsect2info> <date>1998-04-15</date> </refsect2info> <title> Notes </title> <para> <command>CREATE DATABASE</command> is a <productname>Postgres</productname> language extension. </para> <para> Use <command>DROP DATABASE</command> to remove a database. </para> </refsect2> </refsect1> <refsect1 id="R1-SQL-CREATEDATABASE-2"> <title> Usage </title> <para> To create a new database: <programlisting><prompt>olly=></prompt> <userinput>create database lusiadas;</userinput> </programlisting> </para> <para> To create a new database in an alternate area <filename>~/private_db</filename>: <programlisting><prompt>$</prompt> <userinput>mkdir private_db</userinput><prompt>$</prompt> <userinput>initlocation ~/private_db</userinput><computeroutput>Creating Postgres database system directory /home/olly/private_db/base</computeroutput> <prompt>$</prompt> <userinput>psql olly</userinput> <computeroutput>Welcome to the POSTGRESQL interactive sql monitor: Please read the file COPYRIGHT for copyright terms of POSTGRESQL type \? for help on slash commands type \q to quit type \g or terminate with semicolon to execute query You are currently connected to the database: template1 <prompt>olly=></prompt></computeroutput> <userinput>create database elsewhere with location = '/home/olly/private_db';</userinput> <computeroutput>CREATEDB</computeroutput> </programlisting> </para> </refsect1> <refsect1 id="R1-SQL-CREATEDATABASE-3"> <title> Bugs </title> <para> There are security and data integrity issues involved with using alternate database locations specified with absolute path names, and by default only an environment variable known to the backend may be specified for an alternate location. See the Administrator's Guide for more information. </para> </refsect1><!--comment from Olly; response from Thomas... <comment> initlocation does not create a PG_VERSION file in the specified location. How will Postgres handle the situation if it is upgraded to an incompatible database version? </comment>Hmm. This isn't an issue since the upgrade would do a dump/reload from the main database area also.Not sure if the dump/reload would guarantee that the alternate data area gets refreshed though...--> <refsect1 id="R1-SQL-CREATEDATABASE-4"> <title> Compatibility </title> <refsect2 id="R2-SQL-CREATEDATABASE-4"> <refsect2info> <date>1998-04-15</date> </refsect2info> <title> SQL92 </title> <para> There is no <command>CREATE DATABASE</command> statement in SQL92. </para> <para> The equivalent command in standard SQL is <command>CREATE SCHEMA</command>. </para> </refsect2> </refsect1></refentry><!-- Keep this comment at the end of the fileLocal variables:mode: sgmlsgml-omittag:nilsgml-shorttag:tsgml-minimize-attributes:nilsgml-always-quote-attributes:tsgml-indent-step:1sgml-indent-data:tsgml-parent-document:nilsgml-default-dtd-file:"../reference.ced"sgml-exposed-tags:nilsgml-local-catalogs:"/usr/lib/sgml/catalog"sgml-local-ecat-files:nilEnd:-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -