$ date Thu Nov 17 17:53:26 MSK 2016 

This is true, that is, on the OS side, everything is in order. Then it is specifically PostgreSQL.

Time in the records of the tables is 3 hours behind. How to fix it?

  • I suppose you have dates recorded in the database in the UTC zone, this is even a more correct approach. Just when getting the date, substitute the desired timezone. - spopovru
  • @spopovru thanks, you're right. It's even better, just indicated the Time Zone in the project settings. - Colibri

2 answers 2

In PostgreeSQL, the time and timestamp types can be declared as time zone sensitive.

 timestamp with time zone 

never taking into account

 timestamp without time zone 

or simply

 timestamp 

If the field is declared as taking into account the time zone, then when writing data to the table, the time is recorded in UTC based on the current time zone of the user, and is given in local time, again based on the current time zone of the user.

If the time zone is not taken into account, then no manipulations with time are made. What is recorded, then read.

You can change the current user's time zone by setting the TIMEZONE parameter for a user session.

  • Thanks for the detailed answer. I solved the situation by specifying the Time Zone in the project settings, but I did not touch anything in the database. - Colibri

Specifically, in my case, the database was used in the RoR project and, as @spopovru suggested, it was enough to specify the Time Zone in the RoR configuration. After that, time was displayed on the site as it should.

This approach is still good because you can allow users to change the time zone (city) to their own, then the site will display the time for the user.