1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
'\" t
.\" Title: SET
.\" Author: The PostgreSQL Global Development Group
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 2024
.\" Manual: PostgreSQL 16.3 Documentation
.\" Source: PostgreSQL 16.3
.\" Language: English
.\"
.TH "SET" "7" "2024" "PostgreSQL 16.3" "PostgreSQL 16.3 Documentation"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
SET \- change a run\-time parameter
.SH "SYNOPSIS"
.sp
.nf
SET [ SESSION | LOCAL ] \fIconfiguration_parameter\fR { TO | = } { \fIvalue\fR | \*(Aq\fIvalue\fR\*(Aq | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { \fIvalue\fR | \*(Aq\fIvalue\fR\*(Aq | LOCAL | DEFAULT }
.fi
.SH "DESCRIPTION"
.PP
The
\fBSET\fR
command changes run\-time configuration parameters\&. Many of the run\-time parameters listed in
Chapter\ \&20
can be changed on\-the\-fly with
\fBSET\fR\&. (Some parameters can only be changed by superusers and users who have been granted
SET
privilege on that parameter\&. There are also parameters that cannot be changed after server or session start\&.)
\fBSET\fR
only affects the value used by the current session\&.
.PP
If
\fBSET\fR
(or equivalently
\fBSET SESSION\fR) is issued within a transaction that is later aborted, the effects of the
\fBSET\fR
command disappear when the transaction is rolled back\&. Once the surrounding transaction is committed, the effects will persist until the end of the session, unless overridden by another
\fBSET\fR\&.
.PP
The effects of
\fBSET LOCAL\fR
last only till the end of the current transaction, whether committed or not\&. A special case is
\fBSET\fR
followed by
\fBSET LOCAL\fR
within a single transaction: the
\fBSET LOCAL\fR
value will be seen until the end of the transaction, but afterwards (if the transaction is committed) the
\fBSET\fR
value will take effect\&.
.PP
The effects of
\fBSET\fR
or
\fBSET LOCAL\fR
are also canceled by rolling back to a savepoint that is earlier than the command\&.
.PP
If
\fBSET LOCAL\fR
is used within a function that has a
SET
option for the same variable (see
CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))), the effects of the
\fBSET LOCAL\fR
command disappear at function exit; that is, the value in effect when the function was called is restored anyway\&. This allows
\fBSET LOCAL\fR
to be used for dynamic or repeated changes of a parameter within a function, while still having the convenience of using the
SET
option to save and restore the caller\*(Aqs value\&. However, a regular
\fBSET\fR
command overrides any surrounding function\*(Aqs
SET
option; its effects will persist unless rolled back\&.
.if n \{\
.sp
.\}
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBNote\fR
.ps -1
.br
.PP
In
PostgreSQL
versions 8\&.0 through 8\&.2, the effects of a
\fBSET LOCAL\fR
would be canceled by releasing an earlier savepoint, or by successful exit from a
PL/pgSQL
exception block\&. This behavior has been changed because it was deemed unintuitive\&.
.sp .5v
.RE
.SH "PARAMETERS"
.PP
SESSION
.RS 4
Specifies that the command takes effect for the current session\&. (This is the default if neither
SESSION
nor
LOCAL
appears\&.)
.RE
.PP
LOCAL
.RS 4
Specifies that the command takes effect for only the current transaction\&. After
\fBCOMMIT\fR
or
\fBROLLBACK\fR, the session\-level setting takes effect again\&. Issuing this outside of a transaction block emits a warning and otherwise has no effect\&.
.RE
.PP
\fIconfiguration_parameter\fR
.RS 4
Name of a settable run\-time parameter\&. Available parameters are documented in
Chapter\ \&20
and below\&.
.RE
.PP
\fIvalue\fR
.RS 4
New value of parameter\&. Values can be specified as string constants, identifiers, numbers, or comma\-separated lists of these, as appropriate for the particular parameter\&.
DEFAULT
can be written to specify resetting the parameter to its default value (that is, whatever value it would have had if no
\fBSET\fR
had been executed in the current session)\&.
.RE
.PP
Besides the configuration parameters documented in
Chapter\ \&20, there are a few that can only be adjusted using the
\fBSET\fR
command or that have a special syntax:
.PP
SCHEMA
.RS 4
SET SCHEMA \*(Aq\fIvalue\fR\*(Aq
is an alias for
SET search_path TO \fIvalue\fR\&. Only one schema can be specified using this syntax\&.
.RE
.PP
NAMES
.RS 4
SET NAMES \fIvalue\fR
is an alias for
SET client_encoding TO \fIvalue\fR\&.
.RE
.PP
SEED
.RS 4
Sets the internal seed for the random number generator (the function
\fBrandom\fR)\&. Allowed values are floating\-point numbers between \-1 and 1 inclusive\&.
.sp
The seed can also be set by invoking the function
\fBsetseed\fR:
.sp
.if n \{\
.RS 4
.\}
.nf
SELECT setseed(\fIvalue\fR);
.fi
.if n \{\
.RE
.\}
.RE
.PP
TIME ZONE
.RS 4
SET TIME ZONE \*(Aq\fIvalue\fR\*(Aq
is an alias for
SET timezone TO \*(Aq\fIvalue\fR\*(Aq\&. The syntax
SET TIME ZONE
allows special syntax for the time zone specification\&. Here are examples of valid values:
.PP
\*(AqPST8PDT\*(Aq
.RS 4
The time zone for Berkeley, California\&.
.RE
.PP
\*(AqEurope/Rome\*(Aq
.RS 4
The time zone for Italy\&.
.RE
.PP
\-7
.RS 4
The time zone 7 hours west from UTC (equivalent to PDT)\&. Positive values are east from UTC\&.
.RE
.PP
INTERVAL \*(Aq\-08:00\*(Aq HOUR TO MINUTE
.RS 4
The time zone 8 hours west from UTC (equivalent to PST)\&.
.RE
.PP
LOCAL
.br
DEFAULT
.RS 4
Set the time zone to your local time zone (that is, the server\*(Aqs default value of
\fItimezone\fR)\&.
.RE
.sp
Timezone settings given as numbers or intervals are internally translated to POSIX timezone syntax\&. For example, after
SET TIME ZONE \-7,
\fBSHOW TIME ZONE\fR
would report
<\-07>+07\&.
.sp
Time zone abbreviations are not supported by
\fBSET\fR; see
Section\ \&8.5.3
for more information about time zones\&.
.RE
.SH "NOTES"
.PP
The function
\fBset_config\fR
provides equivalent functionality; see
Section\ \&9.27.1\&. Also, it is possible to UPDATE the
pg_settings
system view to perform the equivalent of
\fBSET\fR\&.
.SH "EXAMPLES"
.PP
Set the schema search path:
.sp
.if n \{\
.RS 4
.\}
.nf
SET search_path TO my_schema, public;
.fi
.if n \{\
.RE
.\}
.PP
Set the style of date to traditional
POSTGRES
with
\(lqday before month\(rq
input convention:
.sp
.if n \{\
.RS 4
.\}
.nf
SET datestyle TO postgres, dmy;
.fi
.if n \{\
.RE
.\}
.PP
Set the time zone for Berkeley, California:
.sp
.if n \{\
.RS 4
.\}
.nf
SET TIME ZONE \*(AqPST8PDT\*(Aq;
.fi
.if n \{\
.RE
.\}
.PP
Set the time zone for Italy:
.sp
.if n \{\
.RS 4
.\}
.nf
SET TIME ZONE \*(AqEurope/Rome\*(Aq;
.fi
.if n \{\
.RE
.\}
.SH "COMPATIBILITY"
.PP
SET TIME ZONE
extends syntax defined in the SQL standard\&. The standard allows only numeric time zone offsets while
PostgreSQL
allows more flexible time\-zone specifications\&. All other
SET
features are
PostgreSQL
extensions\&.
.SH "SEE ALSO"
\fBRESET\fR(7), \fBSHOW\fR(7)
|