Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit44b5efb

Browse files
committed
Reduce memory requirements for writing CSVlogs, so it will work with about
the same amount of memory in ErrorContext as standard logs.
1 parent1535f26 commit44b5efb

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.194 2007/08/19 01:41:25 adunstan Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.195 2007/08/23 01:24:43 adunstan Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -133,7 +133,8 @@ static const char *error_severity(int elevel);
133133
staticvoidappend_with_tabs(StringInfobuf,constchar*str);
134134
staticboolis_log_level_output(intelevel,intlog_min_level);
135135
staticvoidwrite_pipe_chunks(char*data,intlen,intdest);
136-
staticvoidget_error_message(StringInfobuf,ErrorData*edata);
136+
staticvoidget_csv_error_message(StringInfobuf,ErrorData*edata);
137+
staticvoidwrite_csvlog(ErrorData*edata);
137138

138139
/*
139140
* errstart --- begin an error-reporting cycle
@@ -1809,9 +1810,7 @@ write_csvlog(ErrorData *edata)
18091810
appendStringInfoChar(&buf,',');
18101811

18111812
/* Error message and cursor position if any */
1812-
get_error_message(&msgbuf,edata);
1813-
1814-
appendCSVLiteral(&buf,msgbuf.data);
1813+
get_csv_error_message(&buf,edata);
18151814

18161815
appendStringInfoChar(&buf,'\n');
18171816

@@ -1826,22 +1825,32 @@ write_csvlog(ErrorData *edata)
18261825
}
18271826

18281827
/*
1829-
* Appends the buffer with the error message and the cursor position.
1828+
* Appends the buffer with the error message and the cursor position, all
1829+
* CSV escaped.
18301830
*/
18311831
staticvoid
1832-
get_error_message(StringInfobuf,ErrorData*edata)
1832+
get_csv_error_message(StringInfobuf,ErrorData*edata)
18331833
{
1834-
if (edata->message)
1835-
appendStringInfo(buf,"%s",edata->message);
1836-
else
1837-
appendStringInfo(buf,"%s",_("missing error text"));
1834+
char*msg=edata->message ?edata->message :_("missing error text");
1835+
charc;
1836+
1837+
appendStringInfoCharMacro(buf,'"');
1838+
1839+
while ( (c=*msg++)!='\0' )
1840+
{
1841+
if (c=='"')
1842+
appendStringInfoCharMacro(buf,'"');
1843+
appendStringInfoCharMacro(buf,c);
1844+
}
18381845

18391846
if (edata->cursorpos>0)
18401847
appendStringInfo(buf,_(" at character %d"),
18411848
edata->cursorpos);
18421849
elseif (edata->internalpos>0)
18431850
appendStringInfo(buf,_(" at character %d"),
18441851
edata->internalpos);
1852+
1853+
appendStringInfoCharMacro(buf,'"');
18451854
}
18461855

18471856
/*
@@ -2032,13 +2041,19 @@ send_message_to_server_log(ErrorData *edata)
20322041
write(fileno(stderr),buf.data,buf.len);
20332042
}
20342043

2044+
/* If in the syslogger process, try to write messages direct to file */
2045+
if (am_syslogger)
2046+
write_syslogger_file(buf.data,buf.len,LOG_DESTINATION_STDERR);
2047+
2048+
/* Write to CSV log if enabled */
20352049
if (Log_destination&LOG_DESTINATION_CSVLOG)
20362050
{
20372051
if (redirection_done||am_syslogger)
20382052
{
20392053
/* send CSV data if it's safe to do so (syslogger doesn't need
2040-
* the pipe)
2054+
* the pipe). First get back the space in the message buffer.
20412055
*/
2056+
pfree(buf.data);
20422057
write_csvlog(edata);
20432058
}
20442059
else
@@ -2051,14 +2066,13 @@ send_message_to_server_log(ErrorData *edata)
20512066
/* write message to stderr unless we just sent it above */
20522067
write(fileno(stderr),buf.data,buf.len);
20532068
}
2069+
pfree(buf.data);
20542070
}
20552071
}
2056-
2057-
/* If in the syslogger process, try to write messages direct to file */
2058-
if (am_syslogger)
2059-
write_syslogger_file(buf.data,buf.len,LOG_DESTINATION_STDERR);
2060-
2061-
pfree(buf.data);
2072+
else
2073+
{
2074+
pfree(buf.data);
2075+
}
20622076
}
20632077

20642078
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp