In Postgresql how do I get localtime as the TimeZone to work on FreeBSD?

The question:

PostgreSQL: 9.4
FreeBSD: 11.2

When I set my TimeZone parameter in postgresql.conf to localtime I receive the following error when trying to start PostgreSQL.

service postgresql restart
<2022-06-02 11:18:27.612 EDT> LOG:  invalid value for parameter "TimeZone": "localtime"
<2022-06-02 11:18:27.613 EDT> FATAL:  configuration file "/usr/local/pgsql/data/postgresql.conf" contains errors
pg_ctl: could not start server
Examine the log output.

During my searches I’ve found this correspondence which seems to indicate that /etc/localtime should be a symlink. Mine isn’t so I tried changing it to a symlink and it still didn’t work as I get the same error as above.

mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/America/Yellowknife
shutdown -r now
ls -la /etc/localtime
lrwxr-xr-x  1 root  wheel  35 Jun  2 11:04 /etc/localtime -> /usr/share/zoneinfo/America/Yellowknife

Is it possible to get TimeZone set to localtime working on FreeBSD?

Note that I also found this discussion where it mentions creating a symlink to /etc/localtime in /usr/share/zoneinfo. I tried that as well and it did not work as I still get the same error as above.

Using pg_config --configure I see that it was not configured with --with-system-tzdata. Is this a requirement to using localtime?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

The way you configured PostgreSQL, it does not use the operating system’s time zone database, but its own copy, which is located in pg_config --sharedir. So your symbolic link has no effect.

You’d have to create that symbolic link in PostgreSQL’s copy of the timezone database, but the correct solution is different: set timezone to America/Yellowknife.

Do not use unsupported PostgreSQL versions.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment