如何将 Google Cloud SQL - PostgreSQL 时区设置为 UTC
How do I set Google Cloud SQL - PostgreSQL timezone to UTC
我看到 Cloud SQL - MySQL 有一个数据库标志来设置 default_time_zone。但是,我无法找到如何为 Cloud SQL - PostgreSQL 做同样的事情。我需要我的时区是 UTC。
您在 Configuring Database Flags documentation are provided by MySQL
. If you click on the flag default_time_zone
that you are referring to, then you will see that you will be redirected to MySQL documentation page. For the Cloud SQL - PostgreSQL
the flags that you see in the Configuring Database Flags 文档的 Cloud SQL - MySQL
中看到的标志由 PostgreSQL
提供,因此它们不会公开此标志或任何类似的标志。
要更改 PostgreSQL
实例的时区,您必须通过 SSH 连接到它并通过执行查询来完成:
- 转到控制台上的
SQL
页面并找到您的 PostgreSQL
实例。
- 在实例的详细记录中,您会在末尾找到三个点。单击 select 选项
Connect VM
。在 window 的右侧,您会看到一个教程。
- 按照教程步骤设置将连接到您的
PostgreSQL
的 Compute Engine VM Instance
。
- 完成教程中的所有步骤后。转到
Compute Engine
页面并通过 SSH 连接到您创建的用于连接 PostgreSQL
. 的实例
- 执行
psql "sslmode=disable dbname=postgres user=postgres hostaddr=[POSTGRESQL_PUBLIC_IP]"
连接到实例。
- 执行
SELECT NOW();
查看当前时区,你的 PostgreSQL
是 运行 at.
- 执行
SET timezone to 'UTC';
将PostgreSQL
的时区设置为UTC
。
- 执行
SELECT NOW();
验证默认时区服务器更新成功。
您还可以从云 Shell 连接到 PostgreSQL
并跳过 VM Instance
创建部分。
我看到 Cloud SQL - MySQL 有一个数据库标志来设置 default_time_zone。但是,我无法找到如何为 Cloud SQL - PostgreSQL 做同样的事情。我需要我的时区是 UTC。
您在 Configuring Database Flags documentation are provided by MySQL
. If you click on the flag default_time_zone
that you are referring to, then you will see that you will be redirected to MySQL documentation page. For the Cloud SQL - PostgreSQL
the flags that you see in the Configuring Database Flags 文档的 Cloud SQL - MySQL
中看到的标志由 PostgreSQL
提供,因此它们不会公开此标志或任何类似的标志。
要更改 PostgreSQL
实例的时区,您必须通过 SSH 连接到它并通过执行查询来完成:
- 转到控制台上的
SQL
页面并找到您的PostgreSQL
实例。 - 在实例的详细记录中,您会在末尾找到三个点。单击 select 选项
Connect VM
。在 window 的右侧,您会看到一个教程。 - 按照教程步骤设置将连接到您的
PostgreSQL
的Compute Engine VM Instance
。 - 完成教程中的所有步骤后。转到
Compute Engine
页面并通过 SSH 连接到您创建的用于连接PostgreSQL
. 的实例
- 执行
psql "sslmode=disable dbname=postgres user=postgres hostaddr=[POSTGRESQL_PUBLIC_IP]"
连接到实例。 - 执行
SELECT NOW();
查看当前时区,你的PostgreSQL
是 运行 at. - 执行
SET timezone to 'UTC';
将PostgreSQL
的时区设置为UTC
。 - 执行
SELECT NOW();
验证默认时区服务器更新成功。
您还可以从云 Shell 连接到 PostgreSQL
并跳过 VM Instance
创建部分。