4 ALTER DATABASE — change a database
8 ALTER DATABASE name [ [ WITH ] option [ ... ] ]
12 ALLOW_CONNECTIONS allowconn
13 CONNECTION LIMIT connlimit
14 IS_TEMPLATE istemplate
16 ALTER DATABASE name RENAME TO new_name
18 ALTER DATABASE name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION
21 ALTER DATABASE name SET TABLESPACE new_tablespace
23 ALTER DATABASE name REFRESH COLLATION VERSION
25 ALTER DATABASE name SET configuration_parameter { TO | = } { value | DEFAULT }
26 ALTER DATABASE name SET configuration_parameter FROM CURRENT
27 ALTER DATABASE name RESET configuration_parameter
28 ALTER DATABASE name RESET ALL
32 ALTER DATABASE changes the attributes of a database.
34 The first form changes certain per-database settings. (See below for
35 details.) Only the database owner or a superuser can change these
38 The second form changes the name of the database. Only the database
39 owner or a superuser can rename a database; non-superuser owners must
40 also have the CREATEDB privilege. The current database cannot be
41 renamed. (Connect to a different database if you need to do that.)
43 The third form changes the owner of the database. To alter the owner,
44 you must be able to SET ROLE to the new owning role, and you must have
45 the CREATEDB privilege. (Note that superusers have all these privileges
48 The fourth form changes the default tablespace of the database. Only
49 the database owner or a superuser can do this; you must also have
50 create privilege for the new tablespace. This command physically moves
51 any tables or indexes in the database's old default tablespace to the
52 new tablespace. The new default tablespace must be empty for this
53 database, and no one can be connected to the database. Tables and
54 indexes in non-default tablespaces are unaffected. The method used to
55 copy files to the new tablespace is affected by the file_copy_method
58 The remaining forms change the session default for a run-time
59 configuration variable for a PostgreSQL database. Whenever a new
60 session is subsequently started in that database, the specified value
61 becomes the session default value. The database-specific default
62 overrides whatever setting is present in postgresql.conf or has been
63 received from the postgres command line. Only the database owner or a
64 superuser can change the session defaults for a database. Certain
65 variables cannot be set this way, or can only be set by a superuser.
70 The name of the database whose attributes are to be altered.
73 If false then no one can connect to this database.
76 How many concurrent connections can be made to this database. -1
80 If true, then this database can be cloned by any user with
81 CREATEDB privileges; if false, then only superusers or the owner
82 of the database can clone it.
85 The new name of the database.
88 The new owner of the database.
91 The new default tablespace of the database.
93 This form of the command cannot be executed inside a transaction
96 REFRESH COLLATION VERSION
97 Update the database collation version. See Notes for background.
99 configuration_parameter
101 Set this database's session default for the specified
102 configuration parameter to the given value. If value is DEFAULT
103 or, equivalently, RESET is used, the database-specific setting
104 is removed, so the system-wide default setting will be inherited
105 in new sessions. Use RESET ALL to clear all database-specific
106 settings. SET FROM CURRENT saves the session's current value of
107 the parameter as the database-specific value.
109 See SET and Chapter 19 for more information about allowed
110 parameter names and values.
114 It is also possible to tie a session default to a specific role rather
115 than to a database; see ALTER ROLE. Role-specific settings override
116 database-specific ones if there is a conflict.
120 To disable index scans by default in the database test:
121 ALTER DATABASE test SET enable_indexscan TO off;
125 The ALTER DATABASE statement is a PostgreSQL extension.
129 CREATE DATABASE, DROP DATABASE, SET, CREATE TABLESPACE