1 <REFENTRY ID="SQL-CREATEDATABASE">
6 <REFMISCINFO>SQL - Language Statements</REFMISCINFO>
13 Creates a new database
17 <DATE>1998-04-15</DATE>
20 CREATE DATABASE <REPLACEABLE CLASS="PARAMETER">name</REPLACEABLE> [ WITH LOCATION = '<replaceable class="parameter">dbpath</replaceable>' ]
23 <REFSECT2 ID="R2-SQL-CREATEDATABASE-1">
25 <DATE>1998-04-15</DATE>
34 <replaceable class="parameter">name</replaceable>
38 The name of a database to create.
44 <replaceable class="parameter">dbpath</replaceable>
48 An alternate location can be specified as either an
49 environment variable known to the backend server
50 (e.g. '<envar>PGDATA2</envar>') or as an absolute path name
51 (e.g. '<filename>/usr/local/pgsql/data</filename>').
52 In either case, the location must be pre-configured
53 by <command>initlocation</command>.
60 <REFSECT2 ID="R2-SQL-CREATEDATABASE-2">
62 <DATE>1998-04-15</DATE>
72 <replaceable>status</replaceable>
79 <ReturnValue>CREATEDB</ReturnValue>
83 Message returned if the command completes successfully.
89 <ReturnValue>WARN: createdb: database "<replaceable class="parameter">name</replaceable>" already exists.</ReturnValue>
93 This occurs if <replaceable class="parameter">database</replaceable> specified already exists.
99 <ReturnValue>ERROR: Unable to create database directory <replaceable class="parameter">directory</replaceable>
104 There was a problem with creating the required directory; this operation will
105 need permissions for the <literal>postgres</literal> user on the specified location.
116 <REFSECT1 ID="R1-SQL-CREATEDATABASE-1">
118 <DATE>1998-04-15</DATE>
124 <command>CREATE DATABASE</command> creates a new Postgres database.
125 The creator becomes the administrator of the new database.
128 <REFSECT2 ID="R2-SQL-CREATEDATABASE-3">
130 <DATE>1998-04-15</DATE>
136 <command>CREATE DATABASE</command> is a <productname>Postgres</productname>
140 Use <command>DROP DATABASE</command> to remove a database.
144 <REFSECT1 ID="R1-SQL-CREATEDATABASE-2">
149 To create a new database:
152 <prompt>olly=></prompt> <userinput>create database lusiadas;</userinput>
155 To create a new database in an alternate area <filename>~/private_db</filename>:
158 <prompt>$</prompt> <userinput>mkdir private_db</userinput>
159 <prompt>$</prompt> <userinput>initlocation ~/private_db</userinput>
160 <computeroutput>Creating Postgres database system directory /home/olly/private_db/base</computeroutput>
162 <prompt>$</prompt> <userinput>psql olly</userinput>
163 <computeroutput>Welcome to the POSTGRESQL interactive sql monitor:
164 Please read the file COPYRIGHT for copyright terms of POSTGRESQL
166 type \? for help on slash commands
168 type \g or terminate with semicolon to execute query
169 You are currently connected to the database: template1
171 <prompt>olly=></prompt></computeroutput> <userinput>create database elsewhere with location = '/home/olly/private_db';</userinput>
172 <computeroutput>CREATEDB</computeroutput>
176 <REFSECT1 ID="R1-SQL-CREATEDATABASE-3">
181 There are security and data integrity issues
182 involved with using alternate database locations
183 specified with absolute path names, and by default
184 only an environment variable known to the backend may be
185 specified for an alternate location.
186 See the Administrator's Guide for more information.
191 comment from Olly; response from Thomas...
193 initlocation does not create a PG_VERSION file in the specified location.
194 How will Postgres handle the situation if it is upgraded to an
195 incompatible database version?
197 Hmm. This isn't an issue since the upgrade would do a dump/reload from the main database area also.
198 Not sure if the dump/reload would guarantee that the alternate data area gets refreshed though...
201 <REFSECT1 ID="R1-SQL-CREATEDATABASE-4">
207 <REFSECT2 ID="R2-SQL-CREATEDATABASE-4">
209 <DATE>1998-04-15</DATE>
215 There is no <command>CREATE DATABASE</command> statement in SQL92.
218 The equivalent command in standard SQL is <command>CREATE SCHEMA</command>.
225 <!-- Keep this comment at the end of the file
230 sgml-minimize-attributes:nil
231 sgml-always-quote-attributes:t
234 sgml-parent-document:nil
235 sgml-default-dtd-file:"../reference.ced"
236 sgml-exposed-tags:nil
237 sgml-local-catalogs:"/usr/lib/sgml/catalog"
238 sgml-local-ecat-files:nil