Jason
Jason

Reputation: 2076

How do I set Google Cloud SQL - PostgreSQL timezone to UTC

I see Cloud SQL - MySQL has a Database Flag to set the default_time_zone. I cannot however, find how to do the same for Cloud SQL - PostgreSQL. I need my time zone to be UTC.

Upvotes: 1

Views: 4525

Answers (1)

Andrei Cusnir
Andrei Cusnir

Reputation: 2805

The flags that you see in Cloud SQL - MySQL in 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 documentation, are provided by PostgreSQL, therefore they don't expose this flag or any similar flag like this.

To change the timezone of the PostgreSQL instance, you have to SSH into it and do it by executing query:

  1. Go to the SQL page on the console and find your PostgreSQL instance.
  2. On the instance's details record you will find three dots at the end. Click and select the option Connect VM. On the right side of your window you will see a tutorial.
  3. Follow the tutorial steps to set up a Compute Engine VM Instance that will be connecting to your PostgreSQL.
  4. After you finish all the steps form the tutorial. Go to the Compute Engine page and SSH to the instance that you created for connecting to the PostgreSQL.
  5. Execute the psql "sslmode=disable dbname=postgres user=postgres hostaddr=[POSTGRESQL_PUBLIC_IP]" to connect to the instance.
  6. Execute the SELECT NOW(); to see the current timezone, that your PostgreSQL is running at.
  7. Execute the SET timezone to 'UTC'; to set the timezone of the PostgreSQL to UTC.
  8. Execute the SELECT NOW(); to verify that the default timezone server updated successfully.

You can also connect to the PostgreSQL from Cloud Shell and skip the part of the VM Instance creation.

Upvotes: 2

Related Questions