1ALTER DATABASE(7)        PostgreSQL 15.4 Documentation       ALTER DATABASE(7)
2
3
4

NAME

6       ALTER_DATABASE - change a database
7

SYNOPSIS

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_ROLE | CURRENT_USER | SESSION_USER }
20
21       ALTER DATABASE name SET TABLESPACE new_tablespace
22
23       ALTER DATABASE name REFRESH COLLATION VERSION
24
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
29

DESCRIPTION

31       ALTER DATABASE changes the attributes of a database.
32
33       The first form changes certain per-database settings. (See below for
34       details.) Only the database owner or a superuser can change these
35       settings.
36
37       The second form changes the name of the database. Only the database
38       owner or a superuser can rename a database; non-superuser owners must
39       also have the CREATEDB privilege. The current database cannot be
40       renamed. (Connect to a different database if you need to do that.)
41
42       The third form changes the owner of the database. To alter the owner,
43       you must own the database and also be a direct or indirect member of
44       the new owning role, and you must have the CREATEDB privilege. (Note
45       that superusers have all these privileges automatically.)
46
47       The fourth form changes the default tablespace of the database. Only
48       the database owner or a superuser can do this; you must also have
49       create privilege for the new tablespace. This command physically moves
50       any tables or indexes in the database's old default tablespace to the
51       new tablespace. The new default tablespace must be empty for this
52       database, and no one can be connected to the database. Tables and
53       indexes in non-default tablespaces are unaffected.
54
55       The remaining forms change the session default for a run-time
56       configuration variable for a PostgreSQL database. Whenever a new
57       session is subsequently started in that database, the specified value
58       becomes the session default value. The database-specific default
59       overrides whatever setting is present in postgresql.conf or has been
60       received from the postgres command line. Only the database owner or a
61       superuser can change the session defaults for a database. Certain
62       variables cannot be set this way, or can only be set by a superuser.
63

PARAMETERS

65       name
66           The name of the database whose attributes are to be altered.
67
68       allowconn
69           If false then no one can connect to this database.
70
71       connlimit
72           How many concurrent connections can be made to this database. -1
73           means no limit.
74
75       istemplate
76           If true, then this database can be cloned by any user with CREATEDB
77           privileges; if false, then only superusers or the owner of the
78           database can clone it.
79
80       new_name
81           The new name of the database.
82
83       new_owner
84           The new owner of the database.
85
86       new_tablespace
87           The new default tablespace of the database.
88
89           This form of the command cannot be executed inside a transaction
90           block.
91
92       REFRESH COLLATION VERSION
93           Update the database collation version. See Notes for background.
94
95       configuration_parameter
96       value
97           Set this database's session default for the specified configuration
98           parameter to the given value. If value is DEFAULT or, equivalently,
99           RESET is used, the database-specific setting is removed, so the
100           system-wide default setting will be inherited in new sessions. Use
101           RESET ALL to clear all database-specific settings.  SET FROM
102           CURRENT saves the session's current value of the parameter as the
103           database-specific value.
104
105           See SET(7) and Chapter 20 for more information about allowed
106           parameter names and values.
107

NOTES

109       It is also possible to tie a session default to a specific role rather
110       than to a database; see ALTER ROLE (ALTER_ROLE(7)). Role-specific
111       settings override database-specific ones if there is a conflict.
112

EXAMPLES

114       To disable index scans by default in the database test:
115
116           ALTER DATABASE test SET enable_indexscan TO off;
117

COMPATIBILITY

119       The ALTER DATABASE statement is a PostgreSQL extension.
120

SEE ALSO

122       CREATE DATABASE (CREATE_DATABASE(7)), DROP DATABASE (DROP_DATABASE(7)),
123       SET(7), CREATE TABLESPACE (CREATE_TABLESPACE(7))
124
125
126
127PostgreSQL 15.4                      2023                    ALTER DATABASE(7)
Impressum