Thread: Limiting the size of log files
Hi,
I want to limit the size of the log files since it's going into GB's. I used the option "log_rotation_size = 1024" but the size went much ahead the specified 1MB. The detailed configuration of the postgresql.conf file is as follows:
log_destination = 'stderr'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql.log'
log_rotation_age = 0
log_rotation_size = 1024
log_min_error_statement = debug5
log_min_duration_statement = 0
All the other flags related to the "ERROR REPORTING AND LOGGING" are commented. In-spite of this configuration (which I think is correct) the log size goes beyond 1MB. Could there be some kind of combination of flags that I am missing. Also following details might be helpful in debugging:
postgres=# select name, setting from pg_settings where name ~ '^log_';
name | setting
-----------------------------+----------------
log_autovacuum_min_duration | -1
log_checkpoints | off
log_connections | off
log_destination | stderr
log_directory | pg_log
log_disconnections | off
log_duration | off
log_error_verbosity | default
log_executor_stats | off
log_filename | postgresql.log
log_hostname | off
log_line_prefix |
log_lock_waits | off
log_min_duration_statement | 0
log_min_error_statement | debug5
log_min_messages | warning
log_parser_stats | off
log_planner_stats | off
log_rotation_age | 0
log_rotation_size | 1024
log_statement | none
log_statement_stats | off
log_temp_files | -1
log_timezone | Asia/Kolkata
log_truncate_on_rotation | off
(25 rows)
Please take a look.
Thanks & Regards,
Amit
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
I want to limit the size of the log files since it's going into GB's. I used the option "log_rotation_size = 1024" but the size went much ahead the specified 1MB. The detailed configuration of the postgresql.conf file is as follows:
log_destination = 'stderr'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql.log'
log_rotation_age = 0
log_rotation_size = 1024
log_min_error_statement = debug5
log_min_duration_statement = 0
All the other flags related to the "ERROR REPORTING AND LOGGING" are commented. In-spite of this configuration (which I think is correct) the log size goes beyond 1MB. Could there be some kind of combination of flags that I am missing. Also following details might be helpful in debugging:
postgres=# select name, setting from pg_settings where name ~ '^log_';
name | setting
-----------------------------+----------------
log_autovacuum_min_duration | -1
log_checkpoints | off
log_connections | off
log_destination | stderr
log_directory | pg_log
log_disconnections | off
log_duration | off
log_error_verbosity | default
log_executor_stats | off
log_filename | postgresql.log
log_hostname | off
log_line_prefix |
log_lock_waits | off
log_min_duration_statement | 0
log_min_error_statement | debug5
log_min_messages | warning
log_parser_stats | off
log_planner_stats | off
log_rotation_age | 0
log_rotation_size | 1024
log_statement | none
log_statement_stats | off
log_temp_files | -1
log_timezone | Asia/Kolkata
log_truncate_on_rotation | off
(25 rows)
Please take a look.
Thanks & Regards,
Amit
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
On 18 August 2010 08:52, Amit Soni <get.amitsoni@gmail.com> wrote: > Hi, > I want to limit the size of the log files since it's going into GB's. I used > the option "log_rotation_size = 1024" but the size went much ahead the > specified 1MB. Did you "reload" PostgreSQL after you changed that option? -- Thom Brown Registered Linux user: #516935
On 18 August 2010 10:14, Amit Soni <get.amitsoni@gmail.com> wrote: > @Thom: Yes, I restarted the postgresql service, that's how I got the > configuration in the pg_settings table. I even rebooted the machine just to > be sure. > Please copy in the group in your responses otherwise only I can see your replies. Ah of course, that's kind of obvious that you did the reload. Apologies. What is the name of the lastest log file it's emitted and what size was it? -- Thom Brown Registered Linux user: #516935
Sorry for not copying the group in my previous response. The name of the largest and the only log file is "postgresql.log" and its size is 32900151B (32M) with the current settings.
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
Regards,
Amit
On Wed, Aug 18, 2010 at 2:56 PM, Thom Brown <thom@linux.com> wrote:
On 18 August 2010 10:14, Amit Soni <get.amitsoni@gmail.com> wrote:Please copy in the group in your responses otherwise only I can see
> @Thom: Yes, I restarted the postgresql service, that's how I got the
> configuration in the pg_settings table. I even rebooted the machine just to
> be sure.
>
your replies.
Ah of course, that's kind of obvious that you did the reload. Apologies.
What is the name of the lastest log file it's emitted and what size was it?
--Thom Brown
Registered Linux user: #516935
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
On 18 August 2010 10:32, Amit Soni <get.amitsoni@gmail.com> wrote: > Sorry for not copying the group in my previous response. The name of the > largest and the only log file is "postgresql.log" and its size is 32900151B > (32M) with the current settings. > I believe it might be because you haven't set up a pattern for the filename, you've just specified a plain name. So change log_filename from "postgresql.log" to "postgresql-%Y-%m-%d_%H%M%S.log" -- Thom Brown Registered Linux user: #516935
I tried this and the limit on the log file size works.
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
The reason I didn't tried this before is that, I would probably have GB's of logs and the space consumed on the disk would be same in this case also with only difference in the number of file. Do we have some kind of pattern that would repeat itself so that we can have let's say only five log files which rotate themselves.
Regards,
Amit
On Wed, Aug 18, 2010 at 3:07 PM, Thom Brown <thom@linux.com> wrote:
On 18 August 2010 10:32, Amit Soni <get.amitsoni@gmail.com> wrote:I believe it might be because you haven't set up a pattern for the
> Sorry for not copying the group in my previous response. The name of the
> largest and the only log file is "postgresql.log" and its size is 32900151B
> (32M) with the current settings.
>
filename, you've just specified a plain name.
So change log_filename from "postgresql.log" to "postgresql-%Y-%m-%d_%H%M%S.log"
--Thom Brown
Registered Linux user: #516935
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
On 18 August 2010 10:54, Amit Soni <get.amitsoni@gmail.com> wrote: > I tried this and the limit on the log file size works. > The reason I didn't tried this before is that, I would probably have GB's of > logs and the space consumed on the disk would be same in this case also with > only difference in the number of file. Do we have some kind of pattern that > would repeat itself so that we can have let's say only five log files which > rotate themselves. > Yes, you can set "log_truncate_on_rotation" to "on" and adjust the filename pattern. However, I'd recommend not using size-based rotation, but rather time-based. So change: log_filename to "postgresql-%H" log_rotation_age to 60 log_rotation_size to 0 The log files will start being rotated after 24 hours as it will start overwriting previous hours. However, I'm not entirely sure how PostgreSQL decides to rotate "after 60 minutes". If you start PostgreSQL at, say, 12:44, it would create: postgresql-12.sql At 13:44 I guess it would say "I need to rotate", so creates: postgresql-13,.sql So postgresql-12.sql contains log entries from 12:44 to 13:43. If this is the case, just bear it in mind and don't assume something like "postgresql-15.sql" contains log entries from 15:00:00 to 15:59:59. -- Thom Brown Registered Linux user: #516935
Sorry for not stating this earlier. It's possible for me to have ~20GB of logs in one day. So, per day rotation is not the best option here. And since limiting the size of the file is only possible when we use some time related pattern in the filename (which I should have deduced from "log_truncate_on_rotation" not working on the size driven rotation), I see the chances of getting what I need as very slim.
Any other suggestion would be greatly appreciated.
Thanks & Regards,
Amit
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
On Wed, Aug 18, 2010 at 3:41 PM, Thom Brown <thom@linux.com> wrote:
On 18 August 2010 10:54, Amit Soni <get.amitsoni@gmail.com> wrote:Yes, you can set "log_truncate_on_rotation" to "on" and adjust the
> I tried this and the limit on the log file size works.
> The reason I didn't tried this before is that, I would probably have GB's of
> logs and the space consumed on the disk would be same in this case also with
> only difference in the number of file. Do we have some kind of pattern that
> would repeat itself so that we can have let's say only five log files which
> rotate themselves.
>
filename pattern. However, I'd recommend not using size-based
rotation, but rather time-based.
So change:
log_filename to "postgresql-%H"
log_rotation_age to 60
log_rotation_size to 0
The log files will start being rotated after 24 hours as it will start
overwriting previous hours.
However, I'm not entirely sure how PostgreSQL decides to rotate "after
60 minutes". If you start PostgreSQL at, say, 12:44, it would create:
postgresql-12.sql
At 13:44 I guess it would say "I need to rotate", so creates:
postgresql-13,.sql
So postgresql-12.sql contains log entries from 12:44 to 13:43. If
this is the case, just bear it in mind and don't assume something like
"postgresql-15.sql" contains log entries from 15:00:00 to 15:59:59.
--Thom Brown
Registered Linux user: #516935
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
On 18 August 2010 11:34, Amit Soni <get.amitsoni@gmail.com> wrote: > Sorry for not stating this earlier. It's possible for me to have ~20GB of > logs in one day. So, per day rotation is not the best option here. And since > limiting the size of the file is only possible when we use some time related > pattern in the filename (which I should have deduced from > "log_truncate_on_rotation" not working on the size driven rotation), I see > the chances of getting what I need as very slim. > Any other suggestion would be greatly appreciated. > Thanks & Regards, > Amit > Just change it so that it wraps after an hour then: log_filename to "postgresql-%M.log" log_rotation_age to 1 log_rotation_size to 0 log_truncate_on_rotation to on Or just go back to "postgresql.log" and use a separate log rotator to do the task for you, like logrotate. -- Thom Brown Registered Linux user: #516935
Le Wed, 18 Aug 2010 16:04:14 +0530, Amit Soni <get.amitsoni@gmail.com> a écrit : > Sorry for not stating this earlier. It's possible for me to have ~20GB of > logs in one day. So, per day rotation is not the best option here. And may be checking/modifying (in postgresql.conf): client_min_messages log_min_messages log_error_verbosity log_min_error_statement end "debug_print_xxx" lines too looks like you turned a debug logging on and didn't switched it off. JY --
Amit Soni wrote: > I want to limit the size of the log files since it's going into GB's. Perhaps you should log fewer events. See the "When to Log" section of postgresql.conf
Yes, sorry for that, but it was deliberate. It was just to fill the log file fast so that testing the configuration doesn't take much time.
Thanks
Amit
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
On Wed, Aug 18, 2010 at 4:23 PM, Jean-Yves F. Barbier <12ukwn@gmail.com> wrote:
Le Wed, 18 Aug 2010 16:04:14 +0530,
Amit Soni <get.amitsoni@gmail.com> a écrit :may be checking/modifying (in postgresql.conf):
> Sorry for not stating this earlier. It's possible for me to have ~20GB of
> logs in one day. So, per day rotation is not the best option here. And
client_min_messages
log_min_messages
log_error_verbosity
log_min_error_statement
end "debug_print_xxx" lines too
looks like you turned a debug logging on and didn't switched it off.
JY
--
--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
Thanks for the logrotate. Will try the linux logrotate utiliy.
Regards,
Amit
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com
On Wed, Aug 18, 2010 at 4:13 PM, Thom Brown <thom@linux.com> wrote:
On 18 August 2010 11:34, Amit Soni <get.amitsoni@gmail.com> wrote:Just change it so that it wraps after an hour then:
> Sorry for not stating this earlier. It's possible for me to have ~20GB of
> logs in one day. So, per day rotation is not the best option here. And since
> limiting the size of the file is only possible when we use some time related
> pattern in the filename (which I should have deduced from
> "log_truncate_on_rotation" not working on the size driven rotation), I see
> the chances of getting what I need as very slim.
> Any other suggestion would be greatly appreciated.
> Thanks & Regards,
> Amit
>
log_filename to "postgresql-%M.log"
log_rotation_age to 1log_rotation_size to 0log_truncate_on_rotation to onOr just go back to "postgresql.log" and use a separate log rotator to
do the task for you, like logrotate.
--Thom Brown
Registered Linux user: #516935
--
Amit Soni
Software Engineer
Avaya India Pvt. Ltd.
Phone: +91-9579615149
Email-id: get.amitsoni@gmail.com, get.amitsoni@hotmail.com