]> begriffs open source - ai-pg/blob - full-docs/html/sql-alterdatabase.html
Include latest toc output
[ai-pg] / full-docs / html / sql-alterdatabase.html
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>ALTER DATABASE</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="sql-alterconversion.html" title="ALTER CONVERSION" /><link rel="next" href="sql-alterdefaultprivileges.html" title="ALTER DEFAULT PRIVILEGES" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">ALTER DATABASE</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-alterconversion.html" title="ALTER CONVERSION">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-alterdefaultprivileges.html" title="ALTER DEFAULT PRIVILEGES">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-ALTERDATABASE"><div class="titlepage"></div><a id="id-1.9.3.7.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ALTER DATABASE</span></h2><p>ALTER DATABASE — change a database</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 ALTER DATABASE <em class="replaceable"><code>name</code></em> [ [ WITH ] <em class="replaceable"><code>option</code></em> [ ... ] ]
4
5 <span class="phrase">where <em class="replaceable"><code>option</code></em> can be:</span>
6
7     ALLOW_CONNECTIONS <em class="replaceable"><code>allowconn</code></em>
8     CONNECTION LIMIT <em class="replaceable"><code>connlimit</code></em>
9     IS_TEMPLATE <em class="replaceable"><code>istemplate</code></em>
10
11 ALTER DATABASE <em class="replaceable"><code>name</code></em> RENAME TO <em class="replaceable"><code>new_name</code></em>
12
13 ALTER DATABASE <em class="replaceable"><code>name</code></em> OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
14
15 ALTER DATABASE <em class="replaceable"><code>name</code></em> SET TABLESPACE <em class="replaceable"><code>new_tablespace</code></em>
16
17 ALTER DATABASE <em class="replaceable"><code>name</code></em> REFRESH COLLATION VERSION
18
19 ALTER DATABASE <em class="replaceable"><code>name</code></em> SET <em class="replaceable"><code>configuration_parameter</code></em> { TO | = } { <em class="replaceable"><code>value</code></em> | DEFAULT }
20 ALTER DATABASE <em class="replaceable"><code>name</code></em> SET <em class="replaceable"><code>configuration_parameter</code></em> FROM CURRENT
21 ALTER DATABASE <em class="replaceable"><code>name</code></em> RESET <em class="replaceable"><code>configuration_parameter</code></em>
22 ALTER DATABASE <em class="replaceable"><code>name</code></em> RESET ALL
23 </pre></div><div class="refsect1" id="id-1.9.3.7.5"><h2>Description</h2><p>
24    <code class="command">ALTER DATABASE</code> changes the attributes
25    of a database.
26   </p><p>
27    The first form changes certain per-database settings.  (See below for
28    details.)  Only the database owner or a superuser can change these settings.
29   </p><p>
30    The second form changes the name of the database.  Only the database
31    owner or a superuser can rename a database; non-superuser owners must
32    also have the
33    <code class="literal">CREATEDB</code> privilege.  The current database cannot
34    be renamed.  (Connect to a different database if you need to do
35    that.)
36   </p><p>
37    The third form changes the owner of the database.
38    To alter the owner, you must be able to <code class="literal">SET ROLE</code> to the
39    new owning role, and you must have the
40    <code class="literal">CREATEDB</code> privilege.
41    (Note that superusers have all these privileges automatically.)
42   </p><p>
43    The fourth form changes the default tablespace of the database.
44    Only the database owner or a superuser can do this; you must also have
45    create privilege for the new tablespace.
46    This command physically moves any tables or indexes in the database's old
47    default tablespace to the new tablespace.  The new default tablespace
48    must be empty for this database, and no one can be connected to
49    the database.  Tables and indexes in non-default tablespaces are
50    unaffected.  The method used to copy files to the new tablespace
51    is affected by the <a class="xref" href="runtime-config-resource.html#GUC-FILE-COPY-METHOD">file_copy_method</a> setting.
52   </p><p>
53    The remaining forms change the session default for a run-time
54    configuration variable for a <span class="productname">PostgreSQL</span>
55    database. Whenever a new session is subsequently started in that
56    database, the specified value becomes the session default value.
57    The database-specific default overrides whatever setting is present
58    in <code class="filename">postgresql.conf</code> or has been received from the
59    <code class="command">postgres</code> command line.  Only the database
60    owner or a superuser can change the session defaults for a
61    database.  Certain variables cannot be set this way, or can only be
62    set by a superuser.
63   </p></div><div class="refsect1" id="id-1.9.3.7.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
64         The name of the database whose attributes are to be altered.
65        </p></dd><dt><span class="term"><em class="replaceable"><code>allowconn</code></em></span></dt><dd><p>
66          If false then no one can connect to this database.
67         </p></dd><dt><span class="term"><em class="replaceable"><code>connlimit</code></em></span></dt><dd><p>
68         How many concurrent connections can be made
69         to this database.  -1 means no limit.
70        </p></dd><dt><span class="term"><em class="replaceable"><code>istemplate</code></em></span></dt><dd><p>
71          If true, then this database can be cloned by any user with <code class="literal">CREATEDB</code>
72          privileges; if false, then only superusers or the owner of the
73          database can clone it.
74         </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>
75       The new name of the database.
76      </p></dd><dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt><dd><p>
77       The new owner of the database.
78      </p></dd><dt><span class="term"><em class="replaceable"><code>new_tablespace</code></em></span></dt><dd><p>
79       The new default tablespace of the database.
80      </p><p>
81       This form of the command cannot be executed inside a transaction block.
82      </p></dd><dt><span class="term"><code class="literal">REFRESH COLLATION VERSION</code></span></dt><dd><p>
83       Update the database collation version.  See <a class="xref" href="sql-altercollation.html#SQL-ALTERCOLLATION-NOTES" title="Notes">Notes</a> for background.
84      </p></dd><dt><span class="term"><em class="replaceable"><code>configuration_parameter</code></em><br /></span><span class="term"><em class="replaceable"><code>value</code></em></span></dt><dd><p>
85         Set this database's session default for the specified configuration
86         parameter to the given value.  If
87         <em class="replaceable"><code>value</code></em> is <code class="literal">DEFAULT</code>
88         or, equivalently, <code class="literal">RESET</code> is used, the
89         database-specific setting is removed, so the system-wide default
90         setting will be inherited in new sessions.  Use <code class="literal">RESET
91         ALL</code> to clear all database-specific settings.
92         <code class="literal">SET FROM CURRENT</code> saves the session's current value of
93         the parameter as the database-specific value.
94        </p><p>
95         See <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a> and <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a>
96         for more information about allowed parameter names
97         and values.
98        </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.7.7"><h2>Notes</h2><p>
99    It is also possible to tie a session default to a specific role
100    rather than to a database; see
101    <a class="xref" href="sql-alterrole.html" title="ALTER ROLE"><span class="refentrytitle">ALTER ROLE</span></a>.
102    Role-specific settings override database-specific
103    ones if there is a conflict.
104   </p></div><div class="refsect1" id="id-1.9.3.7.8"><h2>Examples</h2><p>
105    To disable index scans by default in the database
106    <code class="literal">test</code>:
107
108 </p><pre class="programlisting">
109 ALTER DATABASE test SET enable_indexscan TO off;
110 </pre></div><div class="refsect1" id="id-1.9.3.7.9"><h2>Compatibility</h2><p>
111    The <code class="command">ALTER DATABASE</code> statement is a
112    <span class="productname">PostgreSQL</span> extension.
113   </p></div><div class="refsect1" id="id-1.9.3.7.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a>, <a class="xref" href="sql-dropdatabase.html" title="DROP DATABASE"><span class="refentrytitle">DROP DATABASE</span></a>, <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a>, <a class="xref" href="sql-createtablespace.html" title="CREATE TABLESPACE"><span class="refentrytitle">CREATE TABLESPACE</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="sql-alterconversion.html" title="ALTER CONVERSION">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-alterdefaultprivileges.html" title="ALTER DEFAULT PRIVILEGES">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ALTER CONVERSION </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> ALTER DEFAULT PRIVILEGES</td></tr></table></div></body></html>