]> begriffs open source - ai-pg/blob - full-docs/man7/ALTER_DATABASE.7
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man7 / ALTER_DATABASE.7
1 '\" t
2 .\"     Title: ALTER DATABASE
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 ALTER_DATABASE \- change a database
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 ALTER DATABASE \fIname\fR [ [ WITH ] \fIoption\fR [ \&.\&.\&. ] ]
36
37 where \fIoption\fR can be:
38
39     ALLOW_CONNECTIONS \fIallowconn\fR
40     CONNECTION LIMIT \fIconnlimit\fR
41     IS_TEMPLATE \fIistemplate\fR
42
43 ALTER DATABASE \fIname\fR RENAME TO \fInew_name\fR
44
45 ALTER DATABASE \fIname\fR OWNER TO { \fInew_owner\fR | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
46
47 ALTER DATABASE \fIname\fR SET TABLESPACE \fInew_tablespace\fR
48
49 ALTER DATABASE \fIname\fR REFRESH COLLATION VERSION
50
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
55 .fi
56 .SH "DESCRIPTION"
57 .PP
58 \fBALTER DATABASE\fR
59 changes the attributes of a database\&.
60 .PP
61 The first form changes certain per\-database settings\&. (See below for details\&.) Only the database owner or a superuser can change these settings\&.
62 .PP
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
64 CREATEDB
65 privilege\&. The current database cannot be renamed\&. (Connect to a different database if you need to do that\&.)
66 .PP
67 The third form changes the owner of the database\&. To alter the owner, you must be able to
68 SET ROLE
69 to the new owning role, and you must have the
70 CREATEDB
71 privilege\&. (Note that superusers have all these privileges automatically\&.)
72 .PP
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
74 file_copy_method
75 setting\&.
76 .PP
77 The remaining forms change the session default for a run\-time configuration variable for a
78 PostgreSQL
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
80 postgresql\&.conf
81 or has been received from the
82 \fBpostgres\fR
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\&.
84 .SH "PARAMETERS"
85 .PP
86 \fIname\fR
87 .RS 4
88 The name of the database whose attributes are to be altered\&.
89 .RE
90 .PP
91 \fIallowconn\fR
92 .RS 4
93 If false then no one can connect to this database\&.
94 .RE
95 .PP
96 \fIconnlimit\fR
97 .RS 4
98 How many concurrent connections can be made to this database\&. \-1 means no limit\&.
99 .RE
100 .PP
101 \fIistemplate\fR
102 .RS 4
103 If true, then this database can be cloned by any user with
104 CREATEDB
105 privileges; if false, then only superusers or the owner of the database can clone it\&.
106 .RE
107 .PP
108 \fInew_name\fR
109 .RS 4
110 The new name of the database\&.
111 .RE
112 .PP
113 \fInew_owner\fR
114 .RS 4
115 The new owner of the database\&.
116 .RE
117 .PP
118 \fInew_tablespace\fR
119 .RS 4
120 The new default tablespace of the database\&.
121 .sp
122 This form of the command cannot be executed inside a transaction block\&.
123 .RE
124 .PP
125 REFRESH COLLATION VERSION
126 .RS 4
127 Update the database collation version\&. See
128 Notes
129 for background\&.
130 .RE
131 .PP
132 \fIconfiguration_parameter\fR
133 .br
134 \fIvalue\fR
135 .RS 4
136 Set this database\*(Aqs session default for the specified configuration parameter to the given value\&. If
137 \fIvalue\fR
138 is
139 DEFAULT
140 or, equivalently,
141 RESET
142 is used, the database\-specific setting is removed, so the system\-wide default setting will be inherited in new sessions\&. Use
143 RESET ALL
144 to clear all database\-specific settings\&.
145 SET FROM CURRENT
146 saves the session\*(Aqs current value of the parameter as the database\-specific value\&.
147 .sp
148 See
149 \fBSET\fR(7)
150 and
151 Chapter\ \&19
152 for more information about allowed parameter names and values\&.
153 .RE
154 .SH "NOTES"
155 .PP
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\&.
158 .SH "EXAMPLES"
159 .PP
160 To disable index scans by default in the database
161 test:
162 .sp
163 .if n \{\
164 .RS 4
165 .\}
166 .nf
167 ALTER DATABASE test SET enable_indexscan TO off;
168 .fi
169 .if n \{\
170 .RE
171 .\}
172 .SH "COMPATIBILITY"
173 .PP
174 The
175 \fBALTER DATABASE\fR
176 statement is a
177 PostgreSQL
178 extension\&.
179 .SH "SEE ALSO"
180 CREATE DATABASE (\fBCREATE_DATABASE\fR(7)), DROP DATABASE (\fBDROP_DATABASE\fR(7)), \fBSET\fR(7), CREATE TABLESPACE (\fBCREATE_TABLESPACE\fR(7))