PostgreSQL how to set time zone Time Zone

PostgreSQL how to set time zone Time Zone

Hello colleagues.

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:

  1. View the current timezone.
  2. Set timezone in session.
  3. 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.

  • timezone
  • log_timezone

Save and close.


 

Restart the database.

 

Thank you all, I hope my article was of some help to you.

SIMILAR ARTICLES

PostgreSQL - How to determine which files on disk correspond to tables in a database
PostgreSQL - How to determine which files on disk correspond to tables in a database
POSTGRESQL
Read more
PostgreSQL - How to find out the size of tables in a database
PostgreSQL - How to find out the size of tables in a database
POSTGRESQL
Read more
PostgreSQL - How to check user privileges
PostgreSQL - How to check user privileges
POSTGRESQL
Read more