1ALTER DATABASE(7) PostgreSQL 12.2 Documentation ALTER DATABASE(7)
2
3
4
6 ALTER_DATABASE - change a database
7
9 ALTER DATABASE name [ [ WITH ] option [ ... ] ]
10
11 where option can be:
12
13 ALLOW_CONNECTIONS allowconn
14 CONNECTION LIMIT connlimit
15 IS_TEMPLATE istemplate
16
17 ALTER DATABASE name RENAME TO new_name
18
19 ALTER DATABASE name OWNER TO { new_owner | CURRENT_USER | SESSION_USER }
20
21 ALTER DATABASE name SET TABLESPACE new_tablespace
22
23 ALTER DATABASE name SET configuration_parameter { TO | = } { value | DEFAULT }
24 ALTER DATABASE name SET configuration_parameter FROM CURRENT
25 ALTER DATABASE name RESET configuration_parameter
26 ALTER DATABASE name RESET ALL
27
29 ALTER DATABASE changes the attributes of a database.
30
31 The first form changes certain per-database settings. (See below for
32 details.) Only the database owner or a superuser can change these
33 settings.
34
35 The second form changes the name of the database. Only the database
36 owner or a superuser can rename a database; non-superuser owners must
37 also have the CREATEDB privilege. The current database cannot be
38 renamed. (Connect to a different database if you need to do that.)
39
40 The third form changes the owner of the database. To alter the owner,
41 you must own the database and also be a direct or indirect member of
42 the new owning role, and you must have the CREATEDB privilege. (Note
43 that superusers have all these privileges automatically.)
44
45 The fourth form changes the default tablespace of the database. Only
46 the database owner or a superuser can do this; you must also have
47 create privilege for the new tablespace. This command physically moves
48 any tables or indexes in the database's old default tablespace to the
49 new tablespace. The new default tablespace must be empty for this
50 database, and no one can be connected to the database. Tables and
51 indexes in non-default tablespaces are unaffected.
52
53 The remaining forms change the session default for a run-time
54 configuration variable for a PostgreSQL database. Whenever a new
55 session is subsequently started in that database, the specified value
56 becomes the session default value. The database-specific default
57 overrides whatever setting is present in postgresql.conf or has been
58 received from the postgres command line. Only the database owner or a
59 superuser can change the session defaults for a database. Certain
60 variables cannot be set this way, or can only be set by a superuser.
61
63 name
64 The name of the database whose attributes are to be altered.
65
66 allowconn
67 If false then no one can connect to this database.
68
69 connlimit
70 How many concurrent connections can be made to this database. -1
71 means no limit.
72
73 istemplate
74 If true, then this database can be cloned by any user with CREATEDB
75 privileges; if false, then only superusers or the owner of the
76 database can clone it.
77
78 new_name
79 The new name of the database.
80
81 new_owner
82 The new owner of the database.
83
84 new_tablespace
85 The new default tablespace of the database.
86
87 This form of the command cannot be executed inside a transaction
88 block.
89
90 configuration_parameter
91 value
92 Set this database's session default for the specified configuration
93 parameter to the given value. If value is DEFAULT or, equivalently,
94 RESET is used, the database-specific setting is removed, so the
95 system-wide default setting will be inherited in new sessions. Use
96 RESET ALL to clear all database-specific settings. SET FROM
97 CURRENT saves the session's current value of the parameter as the
98 database-specific value.
99
100 See SET(7) and Chapter 19 for more information about allowed
101 parameter names and values.
102
104 It is also possible to tie a session default to a specific role rather
105 than to a database; see ALTER ROLE (ALTER_ROLE(7)). Role-specific
106 settings override database-specific ones if there is a conflict.
107
109 To disable index scans by default in the database test:
110
111 ALTER DATABASE test SET enable_indexscan TO off;
112
114 The ALTER DATABASE statement is a PostgreSQL extension.
115
117 CREATE DATABASE (CREATE_DATABASE(7)), DROP DATABASE (DROP_DATABASE(7)),
118 SET(7), CREATE TABLESPACE (CREATE_TABLESPACE(7))
119
120
121
122PostgreSQL 12.2 2020 ALTER DATABASE(7)