PostgreSQL how to set time zone Time Zone
Last updated: Feb 20, 2022
In today's article, I will tell you how to set the SQL date and time type in Postgresql. Time zones are usually associated with something incredibly complicated, however, as is often the case, if you sit down and calmly figure everything out, the problem turns out to be not so big.
The content of the article:
- View the current timezone.
- Set timezone in session.
- Set timezone in postgresql.conf
1. View the current timezone.
And so, in order to see what time zone you have currently set in postgresql, run the command in the console:
psql> SHOW TIME ZONE;
Now we have set the time zone Europe\Kiev.
2. Set timezone in session.
To change the time zone, run the command:
psql> set time zone 'Europe/Moscow';
With this command, we set the time zone Europe \ Moscow. But as soon as we restart the server or database, the time zone will be reset to the one you had when you installed the database.
3. Set timezone in postgresql.conf
If we want the time zone in the database not to change, then it must be set in the postgresql.conf configuration file.
You need to find two parameters in postgresql.conf that are responsible for the time zone and change to the one you need.
Save and close.
Restart the database.
Thank you all, I hope my article was of some help to you.