postgres 默认时区 [英] postgres default timezone

查看:35
本文介绍了postgres 默认时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 PostgreSQL 9 并且它显示的时间比服务器时间晚 1 小时.

I installed PostgreSQL 9 and the time it is showing is 1 hour behind the server time.

运行 Select NOW() 显示:2011-07-12 11:51:50.453842+00

服务器日期显示:Tue Jul 12 12:51:40 BST 2011

虽然晚了 1 小时,但 phppgadmin 中显示的时区是:TimeZone Etc/GMT0

It is 1 hour behind but the timezone shown in phppgadmin is: TimeZone Etc/GMT0

我尝试进入 postgresql.conf 并设置

I have tried going into the postgresql.conf and setting

时区 = GMT

然后运行重新启动但没有变化.

then running a restart but no change.

我认为它会使用服务器时区但显然不会的任何想法?!

Any ideas I thought it would have just used the server timezone but obviously not?!

解决方案!:我之前确实设置为 GMT,但它晚了一个小时.四处搜索后发现我需要将其设置为Europe/London.这个考虑到英国夏令时的+1小时,GMT没有!

SOLUTION!: I did set to GMT before and it was an hour behind. after searching around turns out that I needed to set it to Europe/London. This takes into account the +1 hour in British summer time, GMT does not!

推荐答案

时区是一个会话参数.因此,您可以更改当前会话的时区.

The time zone is a session parameter. So, you can change the timezone for the current session.

请参阅文档.

set timezone TO 'GMT';

<小时>

或者,更接近于 SQL 标准,使用 SET TIME ZONE 命令.请注意TIME ZONE"的两个词,其中上面的代码使用了一个词timezone".


Or, more closely following the SQL standard, use the SET TIME ZONE command. Notice two words for "TIME ZONE" where the code above uses a single word "timezone".

SET TIME ZONE 'UTC';

文档解释了区别:

SET TIME ZONE 扩展了 SQL 标准中定义的语法.该标准只允许数字时区偏移,而 PostgreSQL 允许更灵活的时区规范.所有其他 SET 功能都是 PostgreSQL 扩展.

SET TIME ZONE extends syntax defined in the SQL standard. The standard allows only numeric time zone offsets while PostgreSQL allows more flexible time-zone specifications. All other SET features are PostgreSQL extensions.

这篇关于postgres 默认时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆