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 CREATE DATABASE creates a new PostgreSQL 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 CREATE DATABASE statement is a PostgreSQL language extension.
148 Refer to DROP DATABASE statement to remove a database.
152 <REFSECT1 ID="R1-SQL-CREATEDATABASE-2">
157 To create a new database:
160 CREATE DATABASE lusiadas;
163 To create a new database in <filename>~/private_db</filename>:
167 $ initlocation ~/private_db
168 <computeroutput>Creating Postgres database system directory /home/olly/private_db/base</computeroutput>
170 $ chmod a+rx private_db
171 $ chmod a+rwx private_db/base
173 <computeroutput>Welcome to the POSTGRESQL interactive sql monitor:
174 Please read the file COPYRIGHT for copyright terms of POSTGRESQL
176 type \? for help on slash commands
178 type \g or terminate with semicolon to execute query
179 You are currently connected to the database: template1
181 template1=></computeroutput> <userinput>create database elsewhere with location = '/home/olly/private_db';</userinput>
182 <computeroutput>CREATEDB</computeroutput>
186 <REFSECT1 ID="R1-SQL-CREATEDATABASE-3">
191 Where an ordinary user cannot change the ownership of files to other users
192 (which is correct from a security point of view), there is no easy way
193 to give the postgres backend access to files in a database at a
194 non-standard location without
195 giving similar access to all users. The situation shown in the usage
196 example makes <filename>/home/olly/private_db</filename> world-accessible.
199 If, on the other hand, the user gets the system administrator to give
200 file ownership to the <literal>postgres</literal> superuser and restrict access, he will
201 then be unable to delete the <filename><replaceable>directory</replaceable>/base</filename> directory.
204 initlocation does not create a PG_VERSION file in the specified location.
205 How will PostgreSQL handle the situation if it is upgraded to an
206 incompatible database version?
210 <REFSECT1 ID="R1-SQL-CREATEDATABASE-4">
217 <REFSECT2 ID="R2-SQL-CREATEDATABASE-4">
219 <DATE>1998-04-15</DATE>
225 There is no <command>CREATE DATABASE</command> statement on SQL92.
228 The equivalent command in standard SQL is <command>CREATE SCHEMA</command>.
235 <!-- Keep this comment at the end of the file
240 sgml-minimize-attributes:nil
241 sgml-always-quote-attributes:t
244 sgml-parent-document:nil
245 sgml-default-dtd-file:"../reference.ced"
246 sgml-exposed-tags:nil
247 sgml-local-catalogs:"/usr/lib/sgml/catalog"
248 sgml-local-ecat-files:nil