Tuesday, 3 June 2014

Changing the Timezone of PostGreSQL DB

Steps to change the Timezone of PostGres DB are:

1. Log into the Machine which has the PostGres DB.

2. Log into the DB:
    psql -U postgres -d <db_name>

3. Check the time zone of the DB using the below command:
    # show timezone;

4. Log out from the DB.
 
5. Switch to postgres user:
    su - postgres

6. Open the 'postgresql.conf' file in edit mode. This file is usually located inside 'pgdata' folder. Search for the string 'timezone'. Change the value of 'timezone' as desired. The valid timezone values are listed at this link. In this case, we have changed the timezone value to 'Europe/London'.

#intervalstyle = 'postgres'

timezone = 'Europe/London'

7. Save the file.

8. Restart the PG DB. The commands I used are listed below. It depends on the location of the installation.

To Stop:

/usr/pgsql-9.3/bin/pg_ctl -D /ebs/pgdata/ -m fast stop

To Start:
/usr/pgsql-9.3/bin/pg_ctl -D /ebs/pgdata/ -l logfile start

9. Log into the DB again. And check the Timezone:
    #show timezone;

     TimeZone
     ---------------
     Europe/London



No comments:

Post a Comment