2 .\" Title: ALTER DATABASE
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "ALTER DATABASE" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 ALTER_DATABASE \- change a database
35 ALTER DATABASE \fIname\fR [ [ WITH ] \fIoption\fR [ \&.\&.\&. ] ]
37 where \fIoption\fR can be:
39 ALLOW_CONNECTIONS \fIallowconn\fR
40 CONNECTION LIMIT \fIconnlimit\fR
41 IS_TEMPLATE \fIistemplate\fR
43 ALTER DATABASE \fIname\fR RENAME TO \fInew_name\fR
45 ALTER DATABASE \fIname\fR OWNER TO { \fInew_owner\fR | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
47 ALTER DATABASE \fIname\fR SET TABLESPACE \fInew_tablespace\fR
49 ALTER DATABASE \fIname\fR REFRESH COLLATION VERSION
51 ALTER DATABASE \fIname\fR SET \fIconfiguration_parameter\fR { TO | = } { \fIvalue\fR | DEFAULT }
52 ALTER DATABASE \fIname\fR SET \fIconfiguration_parameter\fR FROM CURRENT
53 ALTER DATABASE \fIname\fR RESET \fIconfiguration_parameter\fR
54 ALTER DATABASE \fIname\fR RESET ALL
59 changes the attributes of a database\&.
61 The first form changes certain per\-database settings\&. (See below for details\&.) Only the database owner or a superuser can change these settings\&.
63 The second form changes the name of the database\&. Only the database owner or a superuser can rename a database; non\-superuser owners must also have the
65 privilege\&. The current database cannot be renamed\&. (Connect to a different database if you need to do that\&.)
67 The third form changes the owner of the database\&. To alter the owner, you must be able to
69 to the new owning role, and you must have the
71 privilege\&. (Note that superusers have all these privileges automatically\&.)
73 The fourth form changes the default tablespace of the database\&. Only the database owner or a superuser can do this; you must also have create privilege for the new tablespace\&. This command physically moves any tables or indexes in the database\*(Aqs old default tablespace to the new tablespace\&. The new default tablespace must be empty for this database, and no one can be connected to the database\&. Tables and indexes in non\-default tablespaces are unaffected\&. The method used to copy files to the new tablespace is affected by the
77 The remaining forms change the session default for a run\-time configuration variable for a
79 database\&. Whenever a new session is subsequently started in that database, the specified value becomes the session default value\&. The database\-specific default overrides whatever setting is present in
81 or has been received from the
83 command line\&. Only the database owner or a superuser can change the session defaults for a database\&. Certain variables cannot be set this way, or can only be set by a superuser\&.
88 The name of the database whose attributes are to be altered\&.
93 If false then no one can connect to this database\&.
98 How many concurrent connections can be made to this database\&. \-1 means no limit\&.
103 If true, then this database can be cloned by any user with
105 privileges; if false, then only superusers or the owner of the database can clone it\&.
110 The new name of the database\&.
115 The new owner of the database\&.
120 The new default tablespace of the database\&.
122 This form of the command cannot be executed inside a transaction block\&.
125 REFRESH COLLATION VERSION
127 Update the database collation version\&. See
132 \fIconfiguration_parameter\fR
136 Set this database\*(Aqs session default for the specified configuration parameter to the given value\&. If
142 is used, the database\-specific setting is removed, so the system\-wide default setting will be inherited in new sessions\&. Use
144 to clear all database\-specific settings\&.
146 saves the session\*(Aqs current value of the parameter as the database\-specific value\&.
152 for more information about allowed parameter names and values\&.
156 It is also possible to tie a session default to a specific role rather than to a database; see
157 ALTER ROLE (\fBALTER_ROLE\fR(7))\&. Role\-specific settings override database\-specific ones if there is a conflict\&.
160 To disable index scans by default in the database
167 ALTER DATABASE test SET enable_indexscan TO off;
180 CREATE DATABASE (\fBCREATE_DATABASE\fR(7)), DROP DATABASE (\fBDROP_DATABASE\fR(7)), \fBSET\fR(7), CREATE TABLESPACE (\fBCREATE_TABLESPACE\fR(7))