Site icon JD Bots

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

Syntax

SET parameter TO value;
RESET parameter;

See SET and RESET 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:

Terminal

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=#

SELECT DATE '2026-11-27';

Output

    date
------------
 2026-11-27
(1 row)

Step 3: Change the Setting

postgres=#

SET datestyle TO 'German';

Output

SET

postgres=#

SELECT DATE '2026-11-27';

Output

    date
------------
 27.11.2026
(1 row)

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

Step 4: Put It Back

postgres=#

RESET datestyle;

Output

RESET

postgres=#

SELECT DATE '2026-11-27';

Output

    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.

Exit mobile version