PostgreSQL – Set and Get Timezone

There is a timezone configuration on PostgreSQL server. If you want to change the default globally, you can edit the postgresql.conf. On Ubuntu, it is located at

  • /etc/postgresql/<version>/main/postgresql.conf
# - Locale and Formatting -

datestyle = 'iso, mdy'
#intervalstyle = 'postgres'
#timezone = 'Hongkong'
timezone = 'UTC'

 

We could also tweak the timezone only in your current PostgreSQL session.

1. Get the current timezone.

SELECT current_setting('TIMEZONE');

 

2. Set the timezone to Hong Kong.

set timezone='Asia/Hong_Kong';

 

Here is the timezone list on Wikipedia.

 

Done =)

Reference:

Advertisements

One thought on “PostgreSQL – Set and Get Timezone”

  1. Cambiar la zona horaria a PostgreSQL (timezone)

    pgAdmin III

    Menu: Tools
    > Server Configuration >> postgresql.conf
    Setting name: double click on “timezone” & “log_timezone”
    Value: America/Santo_Domingo
    Click on [OK]
    Click on [Disc button] to Save changes.
    Click on [Yes] to Apply changes.
    Click on [Play button] to Reload Server to apply configuration changes.
    Click on [Yes] to Confirm.

    Reference link:
    https://www.postgresql.org/docs/8.1/static/datetime-keywords.html

    Test:
    SHOW timezone;
    SELECT now();

    DO25L26JN17H2137LR

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s