Index: src/backend/commands/vacuumlazy.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/commands/vacuumlazy.c,v
retrieving revision 1.85
diff -c -p -r1.85 vacuumlazy.c
*** src/backend/commands/vacuumlazy.c	21 Feb 2007 22:47:45 -0000	1.85
--- src/backend/commands/vacuumlazy.c	17 Apr 2007 17:48:24 -0000
***************
*** 47,55 ****
--- 47,57 ----
  #include "access/genam.h"
  #include "access/heapam.h"
  #include "access/transam.h"
+ #include "commands/dbcommands.h"
  #include "commands/vacuum.h"
  #include "miscadmin.h"
  #include "pgstat.h"
+ #include "postmaster/autovacuum.h"
  #include "storage/freespace.h"
  #include "utils/lsyscache.h"
  #include "utils/memutils.h"
*************** typedef struct LVRelStats
*** 90,95 ****
--- 92,98 ----
  	int			max_free_pages; /* # slots allocated in array */
  	PageFreeSpaceInfo *free_pages;		/* array or heap of blkno/avail */
  	BlockNumber tot_free_pages; /* total pages with >= threshold space */
+ 	int			num_index_scans;
  } LVRelStats;
  
  
*************** lazy_vacuum_rel(Relation onerel, VacuumS
*** 141,146 ****
--- 144,152 ----
  	Relation   *Irel;
  	int			nindexes;
  	BlockNumber possibly_freeable;
+ 	PGRUsage	ru0;
+ 
+ 	pg_rusage_init(&ru0);
  
  	if (vacstmt->verbose)
  		elevel = INFO;
*************** lazy_vacuum_rel(Relation onerel, VacuumS
*** 156,161 ****
--- 162,169 ----
  	/* XXX should we scale it up or down?  Adjust vacuum.c too, if so */
  	vacrelstats->threshold = GetAvgFSMRequestSize(&onerel->rd_node);
  
+ 	vacrelstats->num_index_scans = 0;
+ 
  	/* Open all indexes of the relation */
  	vac_open_indexes(onerel, RowExclusiveLock, &nindexes, &Irel);
  	vacrelstats->hasindex = (nindexes > 0);
*************** lazy_vacuum_rel(Relation onerel, VacuumS
*** 200,205 ****
--- 208,228 ----
  	/* report results to the stats collector, too */
  	pgstat_report_vacuum(RelationGetRelid(onerel), onerel->rd_rel->relisshared,
  						 vacstmt->analyze, vacrelstats->rel_tuples);
+ 
+ 	/* and log the action if appropriate */
+ 	if (Log_autovacuum && IsAutoVacuumWorkerProcess())
+ 		ereport(LOG,
+ 				(errmsg("automatic vacuum of table \"%s.%s.%s\": index scans: %d\n"
+ 						"pages: removed %d, %d remain\n"
+ 						"tuples: %.0f removed, %.0f remain\n"
+ 						"system usage: %s",
+ 						get_database_name(MyDatabaseId),
+ 						get_namespace_name(RelationGetNamespace(onerel)),
+ 						RelationGetRelationName(onerel),
+ 						vacrelstats->num_index_scans,
+ 						vacrelstats->pages_removed, vacrelstats->rel_pages,
+ 						vacrelstats->tuples_deleted, vacrelstats->rel_tuples, 
+ 						pg_rusage_show(&ru0))));
  }
  
  
*************** lazy_scan_heap(Relation onerel, LVRelSta
*** 282,287 ****
--- 305,311 ----
  			lazy_vacuum_heap(onerel, vacrelstats);
  			/* Forget the now-vacuumed tuples, and press on */
  			vacrelstats->num_dead_tuples = 0;
+ 			vacrelstats->num_index_scans++;
  		}
  
  		buf = ReadBuffer(onerel, blkno);
*************** lazy_scan_heap(Relation onerel, LVRelSta
*** 490,495 ****
--- 514,520 ----
  							  vacrelstats);
  		/* Remove tuples from heap */
  		lazy_vacuum_heap(onerel, vacrelstats);
+ 		vacrelstats->num_index_scans++;
  	}
  
  	/* Do post-vacuum cleanup and statistics update for each index */
Index: src/backend/postmaster/autovacuum.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/postmaster/autovacuum.c,v
retrieving revision 1.41
diff -c -p -r1.41 autovacuum.c
*** src/backend/postmaster/autovacuum.c	16 Apr 2007 18:29:52 -0000	1.41
--- src/backend/postmaster/autovacuum.c	17 Apr 2007 17:21:56 -0000
*************** int			autovacuum_freeze_max_age;
*** 71,76 ****
--- 71,78 ----
  int			autovacuum_vac_cost_delay;
  int			autovacuum_vac_cost_limit;
  
+ bool		Log_autovacuum = false;
+ 
  /* Flags to tell if we are in an autovacuum process */
  static bool am_autovacuum_launcher = false;
  static bool am_autovacuum_worker = false;
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.385
diff -c -p -r1.385 guc.c
*** src/backend/utils/misc/guc.c	16 Apr 2007 18:29:55 -0000	1.385
--- src/backend/utils/misc/guc.c	17 Apr 2007 17:33:47 -0000
*************** static struct config_bool ConfigureNames
*** 593,598 ****
--- 593,606 ----
  		false, NULL, NULL
  	},
  	{
+ 		{"log_autovacuum", PGC_BACKEND, LOGGING_WHAT,
+ 			gettext_noop("Logs duration and statistics of a VACUUM run by the autovacuum daemon."),
+ 			NULL
+ 		},
+ 		&Log_autovacuum,
+ 		false, NULL, NULL
+ 	},
+ 	{
  		{"debug_assertions", PGC_USERSET, DEVELOPER_OPTIONS,
  			gettext_noop("Turns on various assertion checks."),
  			gettext_noop("This is a debugging aid."),
Index: src/include/postmaster/autovacuum.h
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/include/postmaster/autovacuum.h,v
retrieving revision 1.9
diff -c -p -r1.9 autovacuum.h
*** src/include/postmaster/autovacuum.h	16 Apr 2007 18:30:03 -0000	1.9
--- src/include/postmaster/autovacuum.h	17 Apr 2007 17:21:10 -0000
*************** extern int	autovacuum_vac_cost_limit;
*** 31,36 ****
--- 31,38 ----
  /* autovacuum launcher PID, only valid when worker is shutting down */
  extern int	AutovacuumLauncherPid;
  
+ extern bool Log_autovacuum;
+ 
  /* Status inquiry functions */
  extern bool AutoVacuumingActive(void);
  extern bool IsAutoVacuumLauncherProcess(void);
