Skip to main content
0 reactions

How to Change a Setting with SET in PostgreSQL

Featured card for How to Change a Setting with SET in PostgreSQL, with a terminal window listing SET datestyle TO ‘German’;, the date 27.11.2026 and RESET datestyle;.
How to change a setting with SET in PostgreSQL.

SET changes one of PostgreSQL’s settings for your session only, the connection you’re using now. Other connections, and your next one, keep the server’s value. RESET puts it back.

Every command and output on this page is real, from PostgreSQL 19 on macOS.

Syntax

SyntaxSQL
SET parameter TO value;
RESET parameter;
  • parameter: the setting’s name, such as datestyle, the way dates are shown.
  • value: the new value, often text in single quotes.
  • RESET parameter: back to the value your session started with.

See SET (opens in a new tab) and RESET (opens in a new tab) in the PostgreSQL documentation. A few settings have their own form, such as SET TIME ZONE.

The Example

The same date, shown in two styles by changing datestyle.

Step 1: Connect

Open Terminal and connect to your PostgreSQL server with psql as the postgres user:

TerminalBash
psql -U postgres

Type the user’s password when psql asks for it. psql connects you to the postgres database, and its prompt is postgres=#.

Step 2: See a Date in the Default Style

postgres=#SQL
SELECT DATE '2026-11-27';
OutputPlain text
    date
------------
 2026-11-27
(1 row)

Step 3: Change the Setting

postgres=#SQL
SET datestyle TO 'German';
OutputPlain text
SET
postgres=#SQL
SELECT DATE '2026-11-27';
OutputPlain text
    date
------------
 27.11.2026
(1 row)

The same date now shows as day, month and year, with dots.

Step 4: Put It Back

postgres=#SQL
RESET datestyle;
OutputPlain text
RESET
postgres=#SQL
SELECT DATE '2026-11-27';
OutputPlain text
    date
------------
 2026-11-27
(1 row)

Common Mistakes

MistakeWhat happensDo this instead
A value the setting doesn’t knowERROR: invalid value for parameter "DateStyle": "Long", then DETAIL: Unrecognized key word: "long".Check the setting’s allowed values in the documentation.
Expecting SET to lastIt ends with your session: the next connection starts with the server’s value.Change the server’s configuration for a lasting change.

FAQ

Does SET affect other users?

No. It changes only your own session.

Conclusion

SET changes a setting for your session, and RESET puts it back. Nobody else is affected, and the change ends when you disconnect.

Additional Resources

Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada, and used with their permission.

0 comments