Updated on 2025-10-23 GMT+08:00

SET

Description

Modifies GUC parameters.

Precautions

Most GUC parameters can be modified at runtime by using SET, but some parameters cannot be modified after a service or session starts.

Syntax

  • Set the time zone.
    SET [ SESSION | LOCAL ] TIME ZONE { timezone | LOCAL | DEFAULT };
  • Set the schema.
    SET [ SESSION | LOCAL ] 
        {CURRENT_SCHEMA { TO | = } { schema | DEFAULT }
        | SCHEMA 'schema'};
  • Set the client character set.
    SET [ SESSION | LOCAL ] NAMES {'charset_name' [COLLATE 'collation_name'] | DEFAULT};
  • Set other GUC parameters.
    SET [ SESSION | LOCAL ]
          {config_parameter { TO | = } { value | DEFAULT } | FROM CURRENT }};

Parameters

  • SESSION

    Specifies that the specified parameters take effect only for the current session. If neither SESSION nor LOCAL appears, SESSION is the default value.

    If this command is executed in a transaction, the effect of the command disappears after the transaction is rolled back. Once the surrounding transaction is committed, the effect will persist until the end of the session, unless the parameters are reset by another SET statement.

  • LOCAL

    Specifies that the specified parameters take effect only for the current transaction. After COMMIT or ROLLBACK, session-level settings will take effect again.

    The effect of this command lasts only until the end of the current transaction, whether the transaction is committed or not. A special case is where SET is followed by SET LOCAL within a single transaction. In this case, SET LOCAL will take effect until the end of the transaction, but after the transaction is committed, SET will take effect.

  • TIME ZONE

    Specifies the local time zone for the current session.

    Value range: a valid local time zone. The corresponding GUC parameter is TimeZone. The default value is PRC.

  • CURRENT_SCHEMA

    Specifies the current schema.

    Value range: an existing schema name.

  • SCHEMA

    Same as CURRENT_SCHEMA. The schema here is a string.

    Example: set schema 'public';

  • NAMES {'charset_name' [COLLATE 'collation_name'] | DEFAULT};

    Specifies the client character encoding name. It is equivalent to set client_encoding to charset_name.

    It is equivalent to:

    set client_encoding = charset_name; set character_set_connection = charset_name;
    set collation_connection = collation_name; set character_set_results = charset_name;

    Value range: character sets and collations supported in M-compatible mode. Currently, charset_name must be one of the character sets specified for the database.

  • config_parameter

    Specifies the name of the configurable GUC parameter. You can use SHOW ALL to view the available GUC parameters.

    Some parameters viewed by SHOW ALL cannot be set by using SET. For example, max_datanodes.

  • value

    Specifies the new value of config_parameter. You can specify the parameter as a string constant, identifier, number, or comma-separated list. When DEFAULT is specified, the parameter is set to its default value.

Examples

-- Set the schema search path.
m_db=# SET search_path TO tpcds, public;

-- Set the date style to the traditional POSTGRES style (date placed before month).
m_db=# SET datestyle TO postgres,dmy;

Helpful Links

RESET and SHOW