SET(7)

πŸ“¦ version 15.19, in opensuse-leap 16.0

πŸ’… SET(7) β€” the PostgreSQL one, bestie ✨

okay so this is SET(7) from the PostgreSQL 15.19 manual, and no cap it's lowkey one of the most useful pages in the whole book. it changes a run-time parameter. that's the whole vibe. let's get into it πŸŽ€


🌸 NAME 🌸

SET β€” change a run-time parameter. that's it. that's the girl. she sets things. πŸ’…


✨ SYNOPSIS ✨

SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | 'value' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { value | 'value' | LOCAL | DEFAULT }

literally just pick your scope, pick your parameter, and yeet a value at it 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

The SET command changes run-time configuration parameters. Many of the run-time parameters listed in Chapter 20 can be changed on-the-fly with SET. (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.) SET only affects the value used by the current session.

so like β€” not everyone can set everything, bestie. permissions check first, always. πŸ‘‘

If SET (or equivalently SET SESSION) is issued within a transaction that is later aborted, the effects of the SET 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 SET.

tl;dr: rollback = your SET ghosted you 😭. commit = it stays till the session ends, unless something else comes along.

The effects of SET LOCAL last only till the end of the current transaction, whether committed or not. A special case is SET followed by SET LOCAL within a single transaction: the SET LOCAL value will be seen until the end of the transaction, but afterwards (if the transaction is committed) the SET value will take effect.

SET LOCAL is giving temporary main character energy. it's here for a good time, not a long time. ⏳

The effects of SET or SET LOCAL are also canceled by rolling back to a savepoint that is earlier than the command.

If SET LOCAL is used within a function that has a SET option for the same variable (see CREATE FUNCTION (CREATE_FUNCTION(7))), the effects of the SET LOCAL command disappear at function exit; that is, the value in effect when the function was called is restored anyway. This allows SET LOCAL 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's value. However, a regular SET command overrides any surrounding function's SET option; its effects will persist unless rolled back.

like, SET LOCAL inside a function is a little gremlin that cleans up after herself on the way out 🧚. but a plain SET? she does NOT clean up. she leaves her stuff everywhere until you roll back.

Note πŸ“Œ In PostgreSQL versions 8.0 through 8.2, the effects of a SET LOCAL 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. yeah. they fixed it. it was weird. we don't talk about 8.0–8.2. πŸ™ˆ

πŸŽ€ PARAMETERS πŸŽ€

  • SESSION β€” Specifies that the command takes effect for the current session. (This is the default if neither SESSION nor LOCAL appears.) the default bestie fr fr.
  • LOCAL β€” Specifies that the command takes effect for only the current transaction. After COMMIT or ROLLBACK, the session-level setting takes effect again. Issuing this outside of a transaction block emits a warning and otherwise has no effect. so if you're not in a transaction, she'll warn you and then do literally nothing πŸ’€
  • configuration_parameter β€” Name of a settable run-time parameter. Available parameters are documented in Chapter 20 and below. this is the what you're tweaking ✨
  • value β€” 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 SET had been executed in the current session). DEFAULT = the "never mind, forget I said anything" option 🫢

Besides the configuration parameters documented in Chapter 20, there are a few that can only be adjusted using the SET command or that have a special syntax:

πŸ’œ SCHEMA πŸ’œ

SET SCHEMA 'value' is an alias for SET search_path TO value. Only one schema can be specified using this syntax.

one schema only. she does not do plurals in this form. 🚫

πŸ’œ NAMES πŸ’œ

SET NAMES value is an alias for SET client_encoding TO value.

short and iconic, honestly.

πŸ’œ SEED πŸ’œ

Sets the internal seed for the random number generator (the function random). Allowed values are floating-point numbers between -1 and 1 inclusive.

The seed can also be set by invoking the function setseed:

SELECT setseed(value);

inclusive, bestie β€” -1 and 1 both count. 🌈

πŸ’œ TIME ZONE πŸ’œ

SET TIME ZONE 'value' is an alias for SET timezone TO 'value'. The syntax SET TIME ZONE allows special syntax for the time zone specification. Here are examples of valid values:

  • 'America/Los_Angeles' β€” The time zone for Berkeley, California. 🌴
  • 'Europe/Rome' β€” The time zone for Italy. 🍝
  • -7 β€” The time zone 7 hours west from UTC (equivalent to PDT). Positive values are east from UTC.
  • INTERVAL '-08:00' HOUR TO MINUTE β€” The time zone 8 hours west from UTC (equivalent to PST).
  • LOCAL
  • DEFAULT β€” Set the time zone to your local time zone (that is, the server's default value of timezone). (LOCAL and DEFAULT are listed together above in the original, and both do this same thing πŸ’–)

Timezone settings given as numbers or intervals are internally translated to POSIX timezone syntax. For example, after SET TIME ZONE -7, SHOW TIME ZONE would report <-07>+07.

ngl that transformation is a little jump scare the first time you see it 😭

Time zone abbreviations are not supported by SET; see Section 8.5.3 for more information about time zones.

sorry babe, 'PST' is not invited to this party. 🚫


⭐ NOTES ⭐

The function set_config provides equivalent functionality; see Section 9.27.1. Also, it is possible to UPDATE the pg_settings system view to perform the equivalent of SET.

three ways to do the same thing. pick your fighter. πŸ‘‘


πŸ”₯ EXAMPLES πŸ”₯

Set the schema search path:

SET search_path TO my_schema, public;

Set the style of date to traditional POSTGRES with "day before month" input convention:

SET datestyle TO postgres, dmy;

Set the time zone for Berkeley, California:

SET TIME ZONE 'America/Los_Angeles';

Set the time zone for Italy:

SET TIME ZONE 'Europe/Rome';

copy these, they're literally free ✨


🌈 COMPATIBILITY 🌈

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.

so PostgreSQL said "the standard is a suggestion" and honestly? ate. πŸ’…


🫢 SEE ALSO 🫢


k that's the whole page, bestie. you're now academically and spiritually educated on SET. go forth and set your parameters responsibly πŸ’–βœ¨

PostgreSQL 15.19 Β· 2026 Β· SET(7) β€” mwah, love u, see u in the next man page πŸŽ€πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from