2

I'm setting following parameters in postgres.sql

log_destination = 'stderr' 
logging_collector = on 
log_directory = '/DGlogs/Postgres_Logs'
log_filename = 'postgresql-%y_%m_%d_%T.log'

Say when current timestamp is Wed Apr 11 12:56:23 CDT 2018, the generated logile is in some other timezone (please see the timestamp in the file postgresql-18_04_11_17:51:28.log). It is showing as 17:51 which is not local timestamp. Even the contents of this file is also in different timezone as the filename.

[root@PGSQL Postgres_Logs]# date
Wed Apr 11 12:56:23 CDT 2018

[root@PGSQL Postgres_Logs]#
[root@PGSQL Postgres_Logs]# ls -ltr
total 10172
-rwxrwx--- 1 root     kodiakgroup  790537 Apr  9 18:59 postgresql-18_04_09_21:49:16.log
-rwxrwx--- 1 root     kodiakgroup 6327854 Apr 10 11:20 postgresql-18_04_10_00:00:00.log
-rw------- 1 postgres kodiakgroup 2819464 Apr 10 18:55 postgresql-18_04_10_16:28:41.log
-rw------- 1 postgres kodiakgroup  103011 Apr 10 18:59 postgresql-18_04_10_23:55:29.log
-rw------- 1 postgres kodiakgroup  244131 Apr 11 12:05 postgresql-18_04_11_00:15:56.log
-rw------- 1 postgres kodiakgroup   15335 Apr 11 12:09 postgresql-18_04_11_17:05:56.log
-rw------- 1 postgres kodiakgroup   15954 Apr 11 12:20 postgresql-18_04_11_17:09:14.log
-rw------- 1 postgres kodiakgroup   15835 Apr 11 12:33 postgresql-18_04_11_17:20:05.log
-rw------- 1 postgres kodiakgroup   16092 Apr 11 12:48 postgresql-18_04_11_17:39:16.log
-rw------- 1 postgres kodiakgroup   18018 Apr 11 12:51 postgresql-18_04_11_17:48:28.log
-rw------- 1 postgres kodiakgroup    8233 Apr 11 12:51 postgresql-18_04_11_17:51:28.log

How can I set the logfile's timestamp to same as of local timezone?

  • Really should be using UTC on your logs. – TheFiddlerWins Apr 13 '18 at 15:22
1

How can I set the logfile's timestamp to same as of local timezone?

By setting log_timezone in postgresql.conf. For a Debian-based OS, you may set:

log_timezone = 'localtime'

(this works because debian has a softlink localtime in /usr/share/zoneinfo).

On other systems that don't have this, I guess you would put the actual name of your local timezone, such as for instance US/Central.

  • That parameter doesn't worked, getting following error while starting service. – Pratheej G C Apr 16 '18 at 12:52
  • Apr 16 18:22:05 PS1 postgres[13503]: [1-1] < 2018-04-16 12:52:05.757 GMT >LOG: invalid value for parameter "log_timezone": "localtime" Apr 16 18:22:05 PS1 pg_ctl: < 2018-04-16 12:52:05.757 GMT >LOG: invalid value for parameter "log_timezone": "localtime" – Pratheej G C Apr 16 '18 at 12:56
  • @PratheejGC: it happens to work primarily on debian, please see edit – Daniel Vérité Apr 16 '18 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.