'dml' value for log_statement

Started by Sawada Masahikoalmost 12 years ago2 messages
#1Sawada Masahiko
sawada.mshk@gmail.com
1 attachment(s)

Hi all,

Attaching patch provides new value 'dml' for log_statement.
Currently, The server logs modification statements AND data definition
statements if log_statement is set 'mod'.
So we need to set the 'all' value for log_statement and remove
unnecessary information
if we would like to log only DML.

This patch allows the user to set in detail the setting.
The server logs statement only when INSERT. UPDATE, DELETE and TRUNCATE
statement are executed.
( same as 'mod' value which does not log the DDL)

Comments?

Regards,

-------
Sawada Masahiko

Attachments:

log_statement_dml.patchapplication/octet-stream; name=log_statement_dml.patchDownload
*** a/src/backend/tcop/postgres.c
--- b/src/backend/tcop/postgres.c
***************
*** 2025,2033 **** check_log_statement(List *stmt_list)
  	foreach(stmt_item, stmt_list)
  	{
  		Node	   *stmt = (Node *) lfirst(stmt_item);
! 
! 		if (GetCommandLogLevel(stmt) <= log_statement)
! 			return true;
  	}
  
  	return false;
--- 2025,2042 ----
  	foreach(stmt_item, stmt_list)
  	{
  		Node	   *stmt = (Node *) lfirst(stmt_item);
! 		
! 		if (log_statement == LOGSTMT_MOD)
! 		{
! 			if (GetCommandLogLevel(stmt) <= log_statement)
! 				return true;
! 		}
! 		else
! 		{
! 			/* DDL or DML */
! 			if (GetCommandLogLevel(stmt) == log_statement)
! 				return true;
! 		}
  	}
  
  	return false;
*** a/src/backend/tcop/utility.c
--- b/src/backend/tcop/utility.c
***************
*** 2482,2488 **** GetCommandLogLevel(Node *parsetree)
  		case T_InsertStmt:
  		case T_DeleteStmt:
  		case T_UpdateStmt:
! 			lev = LOGSTMT_MOD;
  			break;
  
  		case T_SelectStmt:
--- 2482,2488 ----
  		case T_InsertStmt:
  		case T_DeleteStmt:
  		case T_UpdateStmt:
! 			lev = LOGSTMT_DML;
  			break;
  
  		case T_SelectStmt:
***************
*** 2549,2555 **** GetCommandLogLevel(Node *parsetree)
  			break;
  
  		case T_TruncateStmt:
! 			lev = LOGSTMT_MOD;
  			break;
  
  		case T_CommentStmt:
--- 2549,2555 ----
  			break;
  
  		case T_TruncateStmt:
! 			lev = LOGSTMT_DML;
  			break;
  
  		case T_CommentStmt:
***************
*** 2867,2873 **** GetCommandLogLevel(Node *parsetree)
  					case CMD_UPDATE:
  					case CMD_INSERT:
  					case CMD_DELETE:
! 						lev = LOGSTMT_MOD;
  						break;
  
  					default:
--- 2867,2873 ----
  					case CMD_UPDATE:
  					case CMD_INSERT:
  					case CMD_DELETE:
! 						lev = LOGSTMT_DML;
  						break;
  
  					default:
***************
*** 2893,2899 **** GetCommandLogLevel(Node *parsetree)
  					case CMD_UPDATE:
  					case CMD_INSERT:
  					case CMD_DELETE:
! 						lev = LOGSTMT_MOD;
  						break;
  
  					case CMD_UTILITY:
--- 2893,2899 ----
  					case CMD_UPDATE:
  					case CMD_INSERT:
  					case CMD_DELETE:
! 						lev = LOGSTMT_DML;
  						break;
  
  					case CMD_UTILITY:
*** a/src/backend/utils/misc/guc.c
--- b/src/backend/utils/misc/guc.c
***************
*** 282,287 **** static const struct config_enum_entry log_error_verbosity_options[] = {
--- 282,288 ----
  static const struct config_enum_entry log_statement_options[] = {
  	{"none", LOGSTMT_NONE, false},
  	{"ddl", LOGSTMT_DDL, false},
+ 	{"dml", LOGSTMT_DML, false},
  	{"mod", LOGSTMT_MOD, false},
  	{"all", LOGSTMT_ALL, false},
  	{NULL, 0, false}
*** a/src/include/tcop/tcopprot.h
--- b/src/include/tcop/tcopprot.h
***************
*** 40,45 **** typedef enum
--- 40,46 ----
  {
  	LOGSTMT_NONE,				/* log no statements */
  	LOGSTMT_DDL,				/* log data definition statements */
+ 	LOGSTMT_DML,				/* log data modification statements */
  	LOGSTMT_MOD,				/* log modification statements, plus DDL */
  	LOGSTMT_ALL					/* log all statements */
  } LogStmtLevel;
#2David Johnston
polobo@yahoo.com
In reply to: Sawada Masahiko (#1)
Re: 'dml' value for log_statement

Sawada Masahiko wrote

Hi all,

Attaching patch provides new value 'dml' for log_statement.
Currently, The server logs modification statements AND data definition
statements if log_statement is set 'mod'.
So we need to set the 'all' value for log_statement and remove
unnecessary information
if we would like to log only DML.

This patch allows the user to set in detail the setting.
The server logs statement only when INSERT. UPDATE, DELETE and TRUNCATE
statement are executed.
( same as 'mod' value which does not log the DDL)

Comments?

Regards,

-------
Sawada Masahiko

-1

I'm not fully versed on what log levels provide what data but if you care
about changes to data then "ALTER TABLE table" is just as important an
activity as "UPDATE table" so "mod" exhibits the recommended behavior and
"dml" provides something that should be of minimal value.

DML by itself has value since monitoring schema changes without worrying
about transient data updates is understandable. But a schema-change, by
definition, alters data.

Maybe further description of why you find "mod" unsatisfactory would be
helpful.

Though it is simple enough to just let people use their own judgement....

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/dml-value-for-log-statement-tp5790895p5790925.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers