codekingpro/portable-devtools
115k
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>createdb</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 Vsnapshot" /><link rel="prev" href="app-clusterdb.html" title="clusterdb" /><link rel="next" href="app-createuser.html" title="createuser" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span class="application">createdb</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-clusterdb.html" title="clusterdb">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><th width="60%" align="center">PostgreSQL Client Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="app-createuser.html" title="createuser">Next</a></td></tr></table><hr /></div><div class="refentry" id="APP-CREATEDB"><div class="titlepage"></div><a id="id-1.9.4.4.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">createdb</span></span></h2><p>createdb — create a new <span class="productname">PostgreSQL</span> database</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.4.4.1"><code class="command">createdb</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] [<em class="replaceable"><code>dbname</code></em>3 [<em class="replaceable"><code>description</code></em>]]</p></div></div><div class="refsect1" id="R1-APP-CREATEDB-1"><h2>Description</h2><p>4 <span class="application">createdb</span> creates a new <span class="productname">PostgreSQL</span>5 database.6 </p><p>7 Normally, the database user who executes this command becomes the owner of8 the new database.9 However, a different owner can be specified via the <code class="option">-O</code>10 option, if the executing user has appropriate privileges.11 </p><p>12 <span class="application">createdb</span> is a wrapper around the13 <acronym class="acronym">SQL</acronym> command <a class="link" href="sql-createdatabase.html" title="CREATE DATABASE"><code class="command">CREATE DATABASE</code></a>.14 There is no effective difference between creating databases via15 this utility and via other methods for accessing the server.16 </p></div><div class="refsect1" id="id-1.9.4.4.6"><h2>Options</h2><p>17 <span class="application">createdb</span> accepts the following command-line arguments:18 19 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>dbname</code></em></span></dt><dd><p>20 Specifies the name of the database to be created. The name must be21 unique among all <span class="productname">PostgreSQL</span> databases in this cluster.22 The default is to create a database with the same name as the23 current system user.24 </p></dd><dt><span class="term"><em class="replaceable"><code>description</code></em></span></dt><dd><p>25 Specifies a comment to be associated with the newly created26 database.27 </p></dd><dt><span class="term"><code class="option">-D <em class="replaceable"><code>tablespace</code></em></code><br /></span><span class="term"><code class="option">--tablespace=<em class="replaceable"><code>tablespace</code></em></code></span></dt><dd><p>28 Specifies the default tablespace for the database. (This name29 is processed as a double-quoted identifier.)30 </p></dd><dt><span class="term"><code class="option">-e</code><br /></span><span class="term"><code class="option">--echo</code></span></dt><dd><p>31 Echo the commands that <span class="application">createdb</span> generates32 and sends to the server.33 </p></dd><dt><span class="term"><code class="option">-E <em class="replaceable"><code>encoding</code></em></code><br /></span><span class="term"><code class="option">--encoding=<em class="replaceable"><code>encoding</code></em></code></span></dt><dd><p>34 Specifies the character encoding scheme to be used in this35 database. The character sets supported by the36 <span class="productname">PostgreSQL</span> server are described in37 <a class="xref" href="multibyte.html#MULTIBYTE-CHARSET-SUPPORTED" title="24.3.1. Supported Character Sets">Section 24.3.1</a>.38 </p></dd><dt><span class="term"><code class="option">-l <em class="replaceable"><code>locale</code></em></code><br /></span><span class="term"><code class="option">--locale=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>39 Specifies the locale to be used in this database. This is equivalent40 to specifying <code class="option">--lc-collate</code>,41 <code class="option">--lc-ctype</code>, and <code class="option">--icu-locale</code> to the42 same value. Some locales are only valid for ICU and must be set with43 <code class="option">--icu-locale</code>.44 </p></dd><dt><span class="term"><code class="option">--lc-collate=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>45 Specifies the LC_COLLATE setting to be used in this database.46 </p></dd><dt><span class="term"><code class="option">--lc-ctype=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>47 Specifies the LC_CTYPE setting to be used in this database.48 </p></dd><dt><span class="term"><code class="option">--icu-locale=<em class="replaceable"><code>locale</code></em></code></span></dt><dd><p>49 Specifies the ICU locale ID to be used in this database, if the50 ICU locale provider is selected.51 </p></dd><dt><span class="term"><code class="option">--icu-rules=<em class="replaceable"><code>rules</code></em></code></span></dt><dd><p>52 Specifies additional collation rules to customize the behavior of the53 default collation of this database. This is supported for ICU only.54 </p></dd><dt><span class="term"><code class="option">--locale-provider={<code class="literal">libc</code>|<code class="literal">icu</code>}</code></span></dt><dd><p>55 Specifies the locale provider for the database's default collation.56 </p></dd><dt><span class="term"><code class="option">-O <em class="replaceable"><code>owner</code></em></code><br /></span><span class="term"><code class="option">--owner=<em class="replaceable"><code>owner</code></em></code></span></dt><dd><p>57 Specifies the database user who will own the new database.58 (This name is processed as a double-quoted identifier.)59 </p></dd><dt><span class="term"><code class="option">-S <em class="replaceable"><code>strategy</code></em></code><br /></span><span class="term"><code class="option">--strategy=<em class="replaceable"><code>strategy</code></em></code></span></dt><dd><p>60 Specifies the database creation strategy. See61 <a class="xref" href="sql-createdatabase.html#CREATE-DATABASE-STRATEGY">CREATE DATABASE STRATEGY</a> for more details.62 </p></dd><dt><span class="term"><code class="option">-T <em class="replaceable"><code>template</code></em></code><br /></span><span class="term"><code class="option">--template=<em class="replaceable"><code>template</code></em></code></span></dt><dd><p>63 Specifies the template database from which to build this64 database. (This name is processed as a double-quoted identifier.)65 </p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>66 Print the <span class="application">createdb</span> version and exit.67 </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>68 Show help about <span class="application">createdb</span> command line69 arguments, and exit.70 </p></dd></dl></div><p>71 </p><p>72 The options <code class="option">-D</code>, <code class="option">-l</code>, <code class="option">-E</code>,73 <code class="option">-O</code>, and74 <code class="option">-T</code> correspond to options of the underlying75 SQL command <a class="link" href="sql-createdatabase.html" title="CREATE DATABASE"><code class="command">CREATE DATABASE</code></a>; see there for more information76 about them.77 </p><p>78 <span class="application">createdb</span> also accepts the following79 command-line arguments for connection parameters:80 81 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-h <em class="replaceable"><code>host</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>host</code></em></code></span></dt><dd><p>82 Specifies the host name of the machine on which the83 server is running. If the value begins with a slash, it is used84 as the directory for the Unix domain socket.85 </p></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span></dt><dd><p>86 Specifies the TCP port or the local Unix domain socket file87 extension on which the server is listening for connections.88 </p></dd><dt><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>89 User name to connect as.90 </p></dd><dt><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span></dt><dd><p>91 Never issue a password prompt. If the server requires92 password authentication and a password is not available by93 other means such as a <code class="filename">.pgpass</code> file, the94 connection attempt will fail. This option can be useful in95 batch jobs and scripts where no user is present to enter a96 password.97 </p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span></dt><dd><p>98 Force <span class="application">createdb</span> to prompt for a99 password before connecting to a database.100 </p><p>101 This option is never essential, since102 <span class="application">createdb</span> will automatically prompt103 for a password if the server demands password authentication.104 However, <span class="application">createdb</span> will waste a105 connection attempt finding out that the server wants a password.106 In some cases it is worth typing <code class="option">-W</code> to avoid the extra107 connection attempt.108 </p></dd><dt><span class="term"><code class="option">--maintenance-db=<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>109 Specifies the name of the database to connect to when creating the110 new database. If not specified, the <code class="literal">postgres</code>111 database will be used; if that does not exist (or if it is the name112 of the new database being created), <code class="literal">template1</code> will113 be used.114 This can be a <a class="link" href="libpq-connect.html#LIBPQ-CONNSTRING" title="34.1.1. Connection Strings">connection115 string</a>. If so, connection string parameters will override any116 conflicting command line options.117 </p></dd></dl></div><p>118 </p></div><div class="refsect1" id="id-1.9.4.4.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGDATABASE</code></span></dt><dd><p>119 If set, the name of the database to create, unless overridden on120 the command line.121 </p></dd><dt><span class="term"><code class="envar">PGHOST</code><br /></span><span class="term"><code class="envar">PGPORT</code><br /></span><span class="term"><code class="envar">PGUSER</code></span></dt><dd><p>122 Default connection parameters. <code class="envar">PGUSER</code> also123 determines the name of the database to create, if it is not124 specified on the command line or by <code class="envar">PGDATABASE</code>.125 </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>126 Specifies whether to use color in diagnostic messages. Possible values127 are <code class="literal">always</code>, <code class="literal">auto</code> and128 <code class="literal">never</code>.129 </p></dd></dl></div><p>130 This utility, like most other <span class="productname">PostgreSQL</span> utilities,131 also uses the environment variables supported by <span class="application">libpq</span>132 (see <a class="xref" href="libpq-envars.html" title="34.15. Environment Variables">Section 34.15</a>).133 </p></div><div class="refsect1" id="id-1.9.4.4.8"><h2>Diagnostics</h2><p>134 In case of difficulty, see <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a>135 and <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> for136 discussions of potential problems and error messages.137 The database server must be running at the138 targeted host. Also, any default connection settings and environment139 variables used by the <span class="application">libpq</span> front-end140 library will apply.141 </p></div><div class="refsect1" id="id-1.9.4.4.9"><h2>Examples</h2><p>142 To create the database <code class="literal">demo</code> using the default143 database server:144</p><pre class="screen">145<code class="prompt">$ </code><strong class="userinput"><code>createdb demo</code></strong>146</pre><p>147 </p><p>148 To create the database <code class="literal">demo</code> using the149 server on host <code class="literal">eden</code>, port 5000, using the150 <code class="literal">template0</code> template database, here is the151 command-line command and the underlying SQL command:152</p><pre class="screen">153<code class="prompt">$ </code><strong class="userinput"><code>createdb -p 5000 -h eden -T template0 -e demo</code></strong>154<code class="computeroutput">CREATE DATABASE demo TEMPLATE template0;</code>155</pre></div><div class="refsect1" id="id-1.9.4.4.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-dropdb.html" title="dropdb"><span class="refentrytitle"><span class="application">dropdb</span></span></a>, <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</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="app-clusterdb.html" title="clusterdb">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-createuser.html" title="createuser">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">clusterdb</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">createuser</span></td></tr></table></div></body></html>