如何将psql的时区设置为默认值(US/Central)之外的其他值?以下是我迄今为止try 过的:

$ psql
psql (9.1.4, server 9.0.4)
...

$ psql -c 'show timezone'
  TimeZone  
------------
 US/Central

$ psql --set=timezone=US/Eastern -c 'show timezone'
  TimeZone  
------------
 US/Central

$ psql --variable=timezone=US/Eastern -c 'show timezone'
  TimeZone  
------------
 US/Central

Edit:我不想更改服务器时区,只想更改客户端.

Edit #2:我希望它处于非交互模式.

推荐答案

psql号文件说:

-v assignment
--set=assignment
--variable=assignment
Perform a variable assignment, like the \set internal command. Note that 
you must separate name and value, if any, by an equal sign on the command line....

但对于时区,它似乎不起作用,可能是因为:

 These assignments are done during a very early stage of start-up, 
 so variables reserved for internal purposes might get overwritten later.

因此,似乎必须在psql中使用SET命令,或者设置PGTZ环境变量:

PGTZ=PST8PDT psql -c 'show timezone'

当然,如果您同意为用户全局设置时区(不仅仅是针对这个单独的psql实例),那么可以在其.bashrc文件中设置该变量(如果在Linux中)

Postgresql相关问答推荐

PostgreSQL数据文件是否仅在判断点期间写入磁盘?

Postgr不列出运算符和函数

在Docker Compose中获取CSV文件数据?

包含JSONB属性的过滤器的索引策略

时间戳的postgreSQL-to_char如果为零,则不显示微秒

Gorm 创建表单数据文件上传错误

使用来自 docker 图像的 postgres 设置 Keycloak 21

在连接字符串并将其附加到 PostgreSQL 中的 where 子句时出现语法错误.怎么修?

如何包装 record_out() 函数?

PostgreSQL:在timestamp::DATE 上创建索引

UPDATE implies move across partitions

获取 OperationalError: FATAL: sorry, too many clients already using psycopg2

PostgreSQL:根据排序顺序仅 Select 每个 id 的第一条记录

Select 日期最高的行

LAG 函数和 GROUP BY

sql语句错误:column .. does not exist

为什么 rake db:migrate 有时会在 structure.sql 中添加尾随空格?

Postgresql varchar 是否使用 unicode 字符长度或 ASCII 字符长度计算?

如何在创建数据库时安装 Postgres 扩展?

Rails ActiveRecord:PG::Error:错误:column reference "created_at" is ambiguous