]> begriffs open source - ai-pg/blob - full-docs/txt/sql-alterdatabase.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-alterdatabase.txt
1
2 ALTER DATABASE
3
4    ALTER DATABASE — change a database
5
6 Synopsis
7
8 ALTER DATABASE name [ [ WITH ] option [ ... ] ]
9
10 where option can be:
11
12     ALLOW_CONNECTIONS allowconn
13     CONNECTION LIMIT connlimit
14     IS_TEMPLATE istemplate
15
16 ALTER DATABASE name RENAME TO new_name
17
18 ALTER DATABASE name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION
19 _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
30 Description
31
32    ALTER DATABASE changes the attributes of a database.
33
34    The first form changes certain per-database settings. (See below for
35    details.) Only the database owner or a superuser can change these
36    settings.
37
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.)
42
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
46    automatically.)
47
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
56    setting.
57
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.
66
67 Parameters
68
69    name
70           The name of the database whose attributes are to be altered.
71
72    allowconn
73           If false then no one can connect to this database.
74
75    connlimit
76           How many concurrent connections can be made to this database. -1
77           means no limit.
78
79    istemplate
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.
83
84    new_name
85           The new name of the database.
86
87    new_owner
88           The new owner of the database.
89
90    new_tablespace
91           The new default tablespace of the database.
92
93           This form of the command cannot be executed inside a transaction
94           block.
95
96    REFRESH COLLATION VERSION
97           Update the database collation version. See Notes for background.
98
99    configuration_parameter
100           value
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.
108
109           See SET and Chapter 19 for more information about allowed
110           parameter names and values.
111
112 Notes
113
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.
117
118 Examples
119
120    To disable index scans by default in the database test:
121 ALTER DATABASE test SET enable_indexscan TO off;
122
123 Compatibility
124
125    The ALTER DATABASE statement is a PostgreSQL extension.
126
127 See Also
128
129    CREATE DATABASE, DROP DATABASE, SET, CREATE TABLESPACE