如何将 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 连接到它并通过执行查询来完成:

  1. 转到控制台上的 SQL 页面并找到您的 PostgreSQL 实例。
  2. 在实例的详细记录中,您会在末尾找到三个点。单击 select 选项 Connect VM。在 window 的右侧,您会看到一个教程。
  3. 按照教程步骤设置将连接到您的 PostgreSQLCompute Engine VM Instance
  4. 完成教程中的所有步骤后。转到 Compute Engine 页面并通过 SSH 连接到您创建的用于连接 PostgreSQL.
  5. 的实例
  6. 执行 psql "sslmode=disable dbname=postgres user=postgres hostaddr=[POSTGRESQL_PUBLIC_IP]" 连接到实例。
  7. 执行 SELECT NOW(); 查看当前时区,你的 PostgreSQL 是 运行 at.
  8. 执行SET timezone to 'UTC';PostgreSQL的时区设置为UTC
  9. 执行SELECT NOW(); 验证默认时区服务器更新成功。

您还可以从云 Shell 连接到 PostgreSQL 并跳过 VM Instance 创建部分。