CentOS 7, PostgreSQL 12 permanently set timezone
-
Permanently set timezone
If you’d like to permanently change the default PostgreSQL time zone for all of your databases, you’ll need to modify the postgresql.conf file.
Find postgresql.conf file.# find / -name postgresql.conf /var/lib/pgsql/12/data/postgresql.conf
Change timezone in the postgresql.conf file# vi /var/lib/pgsql/12/data/postgresql.conf ... log_timezone = 'posix/Singapore' ... timezone = 'posix/Singapore' :wq
Restart database service after committing the change.# sudo systemctl restart postgresql-12 # systemctl status postgresql-12
-
Find PostgreSQL timezone info.
Use psql to connect to a database.# psql -h 192.168.1.x -p 5432 -U postgres -d postgres
Show timezone of the database.postgres=# SHOW TIMEZONE TimeZone -------------- Asia/Singapore postgres=# SELECT now();
Get time zone list, and get the exact name of your time zone.SELECT * FROM pg_timezone_names where name like '%Singapore%'; name | abbrev | utc_offset | is_dst ----------------------+--------+------------+-------- Asia/Singapore | +08 | 08:00:00 | f posix/Asia/Singapore | +08 | 08:00:00 | f posix/Singapore | +08 | 08:00:00 | f Singapore | +08 | 08:00:00 | f (4 rows)