'How to change pgsql now() time?
I'm having an error on my system with some timescale matherialized views, but this only happens after 22 hrs.
I can´t access the office's computer at that hour and I should not be working at that time, so for me to debug the problem I would like to change the computer's time to pretend it's 22 at 9 am.
I changed the computer's time and restarted the psql docker image, but it still marks the current time when select now().
I can find many posts and documentation about changing the timezone, but I just want the server to belive that current time is today's late night.
Is there any way for doing this?
thanks
ps: I'm working on windows 10, and pg12.
Solution 1:[1]
You can change the time of your session, so that you can perform your tests, e.g. current time - 5 hours
SELECT now();
now
-------------------------------
2022-02-03 13:01:35.580786+00
(1 row)
SET timezone = -5;
SELECT now();
now
-------------------------------
2022-02-03 08:01:47.569613-05
(1 row)
Demo: db<>fiddle
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jim Jones |
