How to set timezone on postgresql jdbc connection created by flyway?

最后都变了- 提交于 2020-01-06 05:52:09

问题


I have a postgresql database that I deploy scripts to using flyway. I use the maven flyway plugin to launch the database build against the target database. In that build I have scripts that do things like:

create table my_table(
my_date_time timestamp with time zone not null
);

insert into my_table(my_date_time)
select '2000-01-01';

The postgresql database timezone is set to UTC. My client machine (that runs the maven/flyway build) is running CEST (UTC+2:00).

When the scripts run, the database interprets the string literal above as '1999-12-31 22:00:00+00:00' and writes that to storage.

It seems that the jdbc client connection created by flyway is not setting its client timezone to UTC, but is taking the timstamp string and interpreting it as '2000-01-01 00:00:00+02:00'.

How can I set the client timezone on the jdbc connection created by flyway to UTC? Is there a setting that can be placed in my flyway.conf file?

If I change my local machine timezone to UTC the problem goes away, but I'd rather not do that on my development workstation.


回答1:


Instead of just giving it a date, which postgres has to interpret, it would be better to fully specify the timestamp:

insert into my_table(my_date_time)
select '2000-01-01T00:00:00+00';

If that is not possible, you could try running mvn with -Duser.timezone=UTC but fully specifying the timestamp is the better option as it leaves no room for misinterpretation or misconfiguration.




回答2:


A colleague suggested the following

mvn -Duser.timezone=UTC flyway:migrate


来源:https://stackoverflow.com/questions/58285143/how-to-set-timezone-on-postgresql-jdbc-connection-created-by-flyway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!