1 <REFENTRY ID="SQL-CREATEDATABASE-1">
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>
41 <replaceable class="parameter">name</replaceable>
45 The name of a database to create.
51 <replaceable class="parameter">dbpath</replaceable>
55 An alternate location can be specified as either an
56 environment variable known to the backend server
57 (e.g. '<envar>PGDATA2</envar>') or as an absolute path name
58 (e.g. '<filename>/usr/local/pgsql/data</filename>').
59 In either case, the location must be pre-configured
60 by <command>initlocation</command>.
70 <REFSECT2 ID="R2-SQL-CREATEDATABASE-2">
72 <DATE>1998-04-15</DATE>
88 <ReturnValue>CREATEDB</ReturnValue>
92 Message returned if the command completes successfully.
98 <ReturnValue>WARN: createdb: database "<replaceable class="parameter">name</replaceable>" already exists.</ReturnValue>
102 This occurs if <replaceable class="parameter">database</replaceable> specified already exists.
108 <ReturnValue>ERROR: Unable to create database directory <replaceable class="parameter">directory</replaceable>
113 There was a problem with creating the required directory; this operation will
114 need permissions for the <literal>postgres</literal> user on the specified location.
125 <REFSECT1 ID="R1-SQL-CREATEDATABASE-1">
127 <DATE>1998-04-15</DATE>
133 <command>CREATE DATABASE</command> creates a new Postgres database.
134 The creator becomes the administrator of the new database.
137 <REFSECT2 ID="R2-SQL-CREATEDATABASE-3">
139 <DATE>1998-04-15</DATE>
145 <command>CREATE DATABASE</command> statement is a Postgres language extension.
148 Refer to <command>DROP DATABASE</command> statement to remove a database.
152 <REFSECT1 ID="R1-SQL-CREATEDATABASE-2">
157 To create a new database:
160 <prompt>olly=></prompt> <userinput>create database lusiadas;</userinput>
163 To create a new database in an alternate area <filename>~/private_db</filename>:
166 <prompt>$</prompt> <userinput>mkdir private_db</userinput>
167 <prompt>$</prompt> <userinput>initlocation ~/private_db</userinput>
168 <computeroutput>Creating Postgres database system directory /home/olly/private_db/base</computeroutput>
170 <prompt>$</prompt> <userinput>psql olly</userinput>
171 <computeroutput>Welcome to the POSTGRESQL interactive sql monitor:
172 Please read the file COPYRIGHT for copyright terms of POSTGRESQL
174 type \? for help on slash commands
176 type \g or terminate with semicolon to execute query
177 You are currently connected to the database: template1
179 <prompt>olly=></prompt></computeroutput> <userinput>create database elsewhere with location = '/home/olly/private_db';</userinput>
180 <computeroutput>CREATEDB</computeroutput>
184 <REFSECT1 ID="R1-SQL-CREATEDATABASE-3">
189 There are security and data integrity issues involved with using alternate database locations
190 specified with absolute path names. See the Administrator's Guide for more information.
195 comment from Olly; response from Thomas...
197 initlocation does not create a PG_VERSION file in the specified location.
198 How will Postgres handle the situation if it is upgraded to an
199 incompatible database version?
201 Hmm. This isn't an issue since the upgrade would do a dump/reload from the main database area also.
202 Not sure if the dump/reload would guarantee that the alternate data area gets refreshed though...
205 <REFSECT1 ID="R1-SQL-CREATEDATABASE-4">
212 <REFSECT2 ID="R2-SQL-CREATEDATABASE-4">
214 <DATE>1998-04-15</DATE>
220 There is no <command>CREATE DATABASE</command> statement on SQL92.
223 The equivalent command in standard SQL is <command>CREATE SCHEMA</command>.
230 <!-- Keep this comment at the end of the file
235 sgml-minimize-attributes:nil
236 sgml-always-quote-attributes:t
239 sgml-parent-document:nil
240 sgml-default-dtd-file:"../reference.ced"
241 sgml-exposed-tags:nil
242 sgml-local-catalogs:"/usr/lib/sgml/catalog"
243 sgml-local-ecat-files:nil