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

Commit77c166b

Browse files
committed
Add virtual transaction IDs to CSVLOG output, so that messages coming from
the same transaction can be identified even when no regular XID was assigned.This seems essential after addition of the lazy-XID patch. Also someminor code cleanup in write_csvlog().
1 parenta62a359 commit77c166b

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.148 2007/09/26 22:36:30 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.149 2007/09/27 18:15:36 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -3123,32 +3123,32 @@ SELECT * FROM parent WHERE key = 2400;
31233123
This option emits log lines in comma-separated-value format,
31243124
with these columns: timestamp with milliseconds, username, database
31253125
name, session id, host:port number, process id, per-process line
3126-
number, command tag, session start time, transaction id, error
3127-
severity, SQL state code,statement/error message.
3126+
number, command tag, session start time,virtualtransaction id,
3127+
regular transaction id, errorseverity, SQL state code, error message.
31283128
Here is a sample table definition for storing CSV-format log output:
31293129
</para>
31303130

31313131
<programlisting>
31323132
CREATE TABLE postgres_log
31333133
(
31343134
log_time timestamp with time zone,
3135-
username text,
3135+
user_name text,
31363136
database_name text,
3137-
sessionid text,
3137+
session_id text,
31383138
connection_from text,
31393139
process_id integer,
31403140
process_line_num bigint,
31413141
command_tag text,
31423142
session_start_time timestamp with time zone,
3143+
virtual_transaction_id text,
31433144
transaction_id bigint,
31443145
error_severity text,
31453146
sql_state_code text,
3146-
statement text,
3147-
PRIMARY KEY (sessionid, process_line_num)
3147+
message text,
3148+
PRIMARY KEY (session_id, process_line_num)
31483149
);
31493150
</programlisting>
31503151

3151-
31523152
<para>
31533153
To import a log file into this table, use the <command>COPY FROM</>
31543154
command:

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

Lines changed: 17 additions & 26 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.196 2007/09/05 18:10:48 tgl Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.197 2007/09/27 18:15:36 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -1636,10 +1636,9 @@ appendCSVLiteral(StringInfo buf, const char* data)
16361636

16371637
/*
16381638
* Constructs the error message, depending on the Errordata it gets,
1639-
* in CSV (commaseperated values) format. The COPY command
1639+
* in CSV (commaseparated values) format. The COPY command
16401640
* can then be used to load the messages into a table.
16411641
*/
1642-
16431642
staticvoid
16441643
write_csvlog(ErrorData*edata)
16451644
{
@@ -1672,8 +1671,8 @@ write_csvlog(ErrorData *edata)
16721671
* The format of the log output in CSV format:
16731672
* timestamp with milliseconds, username, databasename, session id,
16741673
* host and port number, process id, process line number, command tag,
1675-
* session start time, transaction id,error severity, sql state code,
1676-
* statement or error message.
1674+
* session start time,virtualtransaction id,regular transaction id,
1675+
* error severity, sql state code, error message.
16771676
*/
16781677

16791678
/* timestamp_with_milliseconds */
@@ -1737,29 +1736,25 @@ write_csvlog(ErrorData *edata)
17371736
appendStringInfoChar(&buf,',');
17381737

17391738
/* session id */
1740-
appendStringInfo(&buf,"%lx.%x",
1741-
(long)MyStartTime,MyProcPid);
1739+
appendStringInfo(&buf,"%lx.%x", (long)MyStartTime,MyProcPid);
17421740
appendStringInfoChar(&buf,',');
17431741

1744-
/* Remote host and port */
1742+
/* Remote host and port(is it safe to not quote this?)*/
17451743
if (MyProcPort&&MyProcPort->remote_host)
17461744
{
17471745
appendStringInfo(&buf,"%s",MyProcPort->remote_host);
17481746
if (MyProcPort->remote_port&&MyProcPort->remote_port[0]!='\0')
17491747
appendStringInfo(&buf,":%s",MyProcPort->remote_port);
17501748
}
1751-
17521749
appendStringInfoChar(&buf,',');
17531750

17541751
/* Process id */
17551752
if (MyProcPid!=0)
17561753
appendStringInfo(&buf,"%d",MyProcPid);
1757-
17581754
appendStringInfoChar(&buf,',');
17591755

17601756
/* Line number */
17611757
appendStringInfo(&buf,"%ld",log_line_number);
1762-
17631758
appendStringInfoChar(&buf,',');
17641759

17651760
/* PS display */
@@ -1773,16 +1768,13 @@ write_csvlog(ErrorData *edata)
17731768
appendCSVLiteral(&buf,msgbuf.data);
17741769
resetStringInfo(&msgbuf);
17751770
}
1776-
17771771
appendStringInfoChar(&buf,',');
17781772

17791773
/* session start timestamp */
17801774
if (formatted_start_time[0]=='\0')
17811775
{
17821776
pg_time_tstamp_time= (pg_time_t)MyStartTime;
1783-
pg_tz*tz;
1784-
1785-
tz=log_timezone ?log_timezone :gmt_timezone;
1777+
pg_tz*tz=log_timezone ?log_timezone :gmt_timezone;
17861778

17871779
pg_strftime(formatted_start_time,FORMATTED_TS_LEN,
17881780
"%Y-%m-%d %H:%M:%S %Z",
@@ -1791,22 +1783,21 @@ write_csvlog(ErrorData *edata)
17911783
appendStringInfoString(&buf,formatted_start_time);
17921784
appendStringInfoChar(&buf,',');
17931785

1786+
/* Virtual transaction id */
1787+
/* keep VXID format in sync with lockfuncs.c */
1788+
if (MyProc!=NULL)
1789+
appendStringInfo(&buf,"%d/%u",MyProc->backendId,MyProc->lxid);
1790+
appendStringInfoChar(&buf,',');
1791+
17941792
/* Transaction id */
17951793
appendStringInfo(&buf,"%u",GetTopTransactionIdIfAny());
1796-
17971794
appendStringInfoChar(&buf,',');
17981795

17991796
/* Error severity */
1800-
if (error_severity(edata->elevel)!=NULL)
1801-
appendStringInfo(&buf,"%s,",error_severity(edata->elevel));
1802-
else
1803-
appendStringInfoString(&buf,",");
1804-
1797+
appendStringInfo(&buf,"%s,",error_severity(edata->elevel));
1798+
18051799
/* SQL state code */
1806-
if (Log_error_verbosity >=PGERROR_VERBOSE)
1807-
appendStringInfo(&buf,"%s",
1808-
unpack_sql_state(edata->sqlerrcode));
1809-
appendStringInfoChar(&buf,',');
1800+
appendStringInfo(&buf,"%s,",unpack_sql_state(edata->sqlerrcode));
18101801

18111802
/* Error message and cursor position if any */
18121803
get_csv_error_message(&buf,edata);
@@ -1830,7 +1821,7 @@ write_csvlog(ErrorData *edata)
18301821
staticvoid
18311822
get_csv_error_message(StringInfobuf,ErrorData*edata)
18321823
{
1833-
char*msg=edata->message ?edata->message :_("missing error text");
1824+
char*msg=edata->message ?edata->message :_("missing error text");
18341825
charc;
18351826

18361827
appendStringInfoCharMacro(buf,'"');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp