SET(7)
๐ SET(7) โ the glow-up your session params have been waiting for ๐
okay bestie, welcome to the PostgreSQL 18.6 era, where SET is literally the "change my settings rn" button and it's giving main character energy. this is the page that tells you how to tweak a run-time parameter on the fly. no cap. ๐ฆ
โจ SYNOPSIS โจ
SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | 'value' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { value | 'value' | LOCAL | DEFAULT }
๐ธ DESCRIPTION ๐ธ
so. the SET command changes run-time configuration parameters. periodt. tons of the run-time params listed in Chapter 19 can be changed on-the-fly with SET. ๐
quick reality check tho, because i love you and i want you informed:
- some parameters can only be changed by superusers, and by users who've been granted
SETprivilege on that parameter. - there are also parameters that cannot be changed after server or session start. soz.
SET only affects the value used by the current session. that's the whole vibe โ it's yours, it's local, it's not leaking anywhere else. โจ
now the transaction lore, because this is where people get caught slipping:
- if
SET(or, equivalently,SET SESSION) is issued inside a transaction that later gets aborted, the effects of theSETcommand disappear when the transaction is rolled back. poof. gone. ๐ - once the surrounding transaction is committed, the effects stick around until the end of the session โ unless something overrides them with another
SET.
the effects of SET LOCAL last only till the end of the current transaction, whether that's committed or not. that's its whole deal.
and here's the special case, the plot twist if you will: SET followed by SET LOCAL within a single transaction. in that scenario the SET LOCAL value is what you see until the end of the transaction, but afterwards (if the transaction is committed) the SET value takes effect. iconic behaviour honestly. ๐
also: the effects of SET or SET LOCAL are cancelled by rolling back to a savepoint that's earlier than the command. keep that in your notes app. ๐
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 โ meaning the value in effect when the function was called gets restored anyway. this is a feature bestie, it lets you use SET LOCAL for dynamic or repeated changes of a parameter inside a function while still having the convenience of using the SET option to save and restore the caller's value. ๐ซถ
however โ and i need you to hear me โ a regular SET command overrides any surrounding function's SET option. its effects will persist unless rolled back. no take-backs.
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. and honestly? they were so right for that.
๐ PARAMETERS ๐
SESSIONโ says the command takes effect for the current session. this is the default if neitherSESSIONnorLOCALshows up. it's just here, being chill.LOCALโ says the command takes effect for only the current transaction. afterCOMMITorROLLBACK, the session-level setting takes effect again. โ ๏ธ if you issue this outside of a transaction block, it emits a warning and otherwise has no effect. so, like, do it inside a transaction or don't bother.configuration_parameterโ the name of a settable run-time parameter. the available parameters are documented in Chapter 19 and below. ๐valueโ the new value of the parameter. values can be specified as string constants, identifiers, numbers, or comma-separated lists of these, as appropriate for the particular parameter.DEFAULTcan be written to specify resetting the parameter to its default value โ that is, whatever value it would have had if noSEThad been executed in the current session. โจ
๐ the special-syntax squad ๐
besides the configuration parameters documented in Chapter 19, there are a few that can only be adjusted using the SET command, or that have a special syntax. meet the crew:
๐ SCHEMA
SET SCHEMA 'value' is an alias for SET search_path TO value. only one schema can be specified using this syntax. one. singular. don't push it.
๐ NAMES
SET NAMES 'value' is an alias for SET client_encoding TO value. cute, short, does the thing.
๐ 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);
๐ 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, and yes, every single one slays in its own way:
'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).LOCALDEFAULTโ Set the time zone to your local time zone (that is, the server's default value oftimezone).
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. yes that's a real output, no i will not explain the angle brackets, that's just what it does. ๐
โ ๏ธ time zone abbreviations are not supported bySET; see Section 8.5.3 for more information about time zones. lowercasepdtwill not save you here bestie.
๐ NOTES ๐
the function set_config provides equivalent functionality โ see Section 9.28.1. ๐ซถ
also, it's possible to UPDATE the pg_settings system view to perform the equivalent of SET. yes really. there's always another way.
๐ฅ 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';
look at that. four examples. all of them correct. we love to see it. ๐ โจ
๐ 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. so we're built different, respectfully. ๐
all other SET features are PostgreSQL extensions.
๐ SEE ALSO ๐
iykyk. go read those next, they're the sibling pages and they ate.
and that's the whole page, bestie!! ๐ this was PostgreSQL 18.6, dated 2026, and you just read the SET(7) manual page top to bottom like a scholar. i'm so proud of you. go change a parameter, you've earned it. ๐โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms