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
SET parameter TO value;
RESET parameter;
parameter: the setting’s name, such asdatestyle, 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:
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
SELECT DATE '2026-11-27';
date
------------
2026-11-27
(1 row)
Step 3: Change the Setting
SET datestyle TO 'German';
SET
SELECT DATE '2026-11-27';
date
------------
27.11.2026
(1 row)
The same date now shows as day, month and year, with dots.
Step 4: Put It Back
RESET datestyle;
RESET
SELECT DATE '2026-11-27';
date
------------
2026-11-27
(1 row)
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| A value the setting doesn’t know | ERROR: invalid value for parameter "DateStyle": "Long", then DETAIL: Unrecognized key word: "long". | Check the setting’s allowed values in the documentation. |
Expecting SET to last | It 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
- PostgreSQL 19 documentation: SET (opens in a new tab)
- PostgreSQL 19 documentation: RESET (opens in a new tab)
- PostgreSQL 19 documentation: DateStyle (opens in a new tab)
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