1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.55 2007/11/28 15:42:31 petere Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.56 2008/03/25 22:50:27 neilc Exp $ -->
2
2
3
3
<chapter id="monitoring">
4
4
<title>Monitoring Database Activity</title>
@@ -947,26 +947,26 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
947
947
</para>
948
948
949
949
<para>
950
- A number of trace points, often called probes, are already inserted
951
- into the source code. By default these probes are disabled, and
952
- the user needs to explicitly tell the configure script to make the
953
- probes available in <productname>PostgreSQL</productname>.
950
+ A number of probes or trace points are already inserted
951
+ into the source code. By default these probes are not compiled into the
952
+ binary, and the user needs to explicitly tell the configure script to make
953
+ the probes available in <productname>PostgreSQL</productname>.
954
954
</para>
955
955
956
956
<para>
957
- Currently, only the DTrace utility is supported, which is only available
958
- on Solaris Express and Solaris 10+ . It is expected that DTrace will
959
- be available in the future on FreeBSD and Mac OS X .
957
+ Currently, only the DTrace utility is supported, which is available
958
+ on Solaris Express, Solaris 10, and Mac OS X Leopard . It is expected that
959
+ DTrace will be available in the future on FreeBSD.
960
960
Supporting other dynamic tracing utilities is theoretically possible by
961
- changing the definitions for the <literal>PG_TRACE</> macros in
962
- <filename>src/include/pg_trace .h</>.
961
+ changing the definitions for the macros in
962
+ <filename>src/include/utils/probes .h</>.
963
963
</para>
964
964
965
965
<sect2 id="compiling-for-trace">
966
966
<title>Compiling for Dynamic Tracing</title>
967
967
968
968
<para>
969
- By default, trace points are disabled , so you will need to
969
+ By default, probes are not available , so you will need to
970
970
explicitly tell the configure script to make the probes available
971
971
in <productname>PostgreSQL</productname>. To include DTrace support
972
972
specify <option>--enable-dtrace</> to configure. See <xref
@@ -975,16 +975,16 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
975
975
</sect2>
976
976
977
977
<sect2 id="trace-points">
978
- <title>Built-in Trace Points </title>
978
+ <title>Built-in Probes </title>
979
979
980
980
<para>
981
- A few standard trace points are provided in the source code
981
+ A few standard probes are provided in the source code
982
982
(of course, more can be added as needed for a particular problem).
983
983
These are shown in <xref linkend="trace-point-table">.
984
984
</para>
985
985
986
986
<table id="trace-point-table">
987
- <title>Built-in Trace Points </title>
987
+ <title>Built-in Probes </title>
988
988
<tgroup cols="3">
989
989
<thead>
990
990
<row>
@@ -996,67 +996,67 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
996
996
997
997
<tbody>
998
998
<row>
999
- <entry>transaction__start </entry>
999
+ <entry>transaction-start </entry>
1000
1000
<entry>(int transactionId)</entry>
1001
1001
<entry>The start of a new transaction.</entry>
1002
1002
</row>
1003
1003
<row>
1004
- <entry>transaction__commit </entry>
1004
+ <entry>transaction-commit </entry>
1005
1005
<entry>(int transactionId)</entry>
1006
1006
<entry>The successful completion of a transaction.</entry>
1007
1007
</row>
1008
1008
<row>
1009
- <entry>transaction__abort </entry>
1009
+ <entry>transaction-abort </entry>
1010
1010
<entry>(int transactionId)</entry>
1011
1011
<entry>The unsuccessful completion of a transaction.</entry>
1012
1012
</row>
1013
1013
1014
1014
<row>
1015
- <entry>lwlock__acquire </entry>
1015
+ <entry>lwlock-acquire </entry>
1016
1016
<entry>(int lockid, int mode)</entry>
1017
1017
<entry>An LWLock has been acquired.</entry>
1018
1018
</row>
1019
1019
<row>
1020
- <entry>lwlock__release </entry>
1020
+ <entry>lwlock-release </entry>
1021
1021
<entry>(int lockid, int mode)</entry>
1022
1022
<entry>An LWLock has been released.</entry>
1023
1023
</row>
1024
1024
<row>
1025
- <entry>lwlock__startwait </entry>
1025
+ <entry>lwlock-startwait </entry>
1026
1026
<entry>(int lockid, int mode)</entry>
1027
1027
<entry>An LWLock was not immediately available and a backend
1028
1028
has begun to wait for the lock to become available.
1029
1029
</entry>
1030
1030
</row>
1031
1031
<row>
1032
- <entry>lwlock__endwait </entry>
1032
+ <entry>lwlock-endwait </entry>
1033
1033
<entry>(int lockid, int mode)</entry>
1034
1034
<entry>A backend has been released from its wait for an LWLock.
1035
1035
</entry>
1036
1036
</row>
1037
1037
<row>
1038
- <entry>lwlock__condacquire </entry>
1038
+ <entry>lwlock-condacquire </entry>
1039
1039
<entry>(int lockid, int mode)</entry>
1040
1040
<entry>An LWLock was successfully acquired when the caller specified no
1041
1041
waiting.
1042
1042
</entry>
1043
1043
</row>
1044
1044
<row>
1045
- <entry>lwlock__condacquire__fail </entry>
1045
+ <entry>lwlock-condacquire-fail </entry>
1046
1046
<entry>(int lockid, int mode)</entry>
1047
1047
<entry>An LWLock was not successfully acquired when the caller specified
1048
1048
no waiting.
1049
1049
</entry>
1050
1050
</row>
1051
1051
<row>
1052
- <entry>lock__startwait </entry>
1052
+ <entry>lock-startwait </entry>
1053
1053
<entry>(int locktag_field2, int lockmode)</entry>
1054
1054
<entry>A request for a heavyweight lock (lmgr lock) has begun to wait
1055
1055
because the lock is not available.
1056
1056
</entry>
1057
1057
</row>
1058
1058
<row>
1059
- <entry>lock__endwait </entry>
1059
+ <entry>lock-endwait </entry>
1060
1060
<entry>(int locktag_field2, int lockmode)</entry>
1061
1061
<entry>A request for a heavyweight lock (lmgr lock) has finished waiting
1062
1062
(i.e., has acquired the lock).
@@ -1068,7 +1068,7 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
1068
1068
</sect2>
1069
1069
1070
1070
<sect2 id="using-trace-points">
1071
- <title>Using Trace Points </title>
1071
+ <title>Using Probes </title>
1072
1072
1073
1073
<para>
1074
1074
The example below shows a DTrace script for analyzing transaction
@@ -1096,11 +1096,9 @@ postgresql$1:::transaction-commit
1096
1096
self->ts=0;
1097
1097
}
1098
1098
</programlisting>
1099
- Note how the double underline in trace point names needs to
1100
- be replaced by a hyphen when using D script.
1101
1099
When executed, the example D script gives output such as:
1102
1100
<screen>
1103
- # ./txn_count.d `pgrep -n postgres`
1101
+ # ./txn_count.d `pgrep -n postgres` or ./txn_count.d <PID>
1104
1102
^C
1105
1103
1106
1104
Start 71
@@ -1109,7 +1107,7 @@ Total time (ns) 2312105013
1109
1107
</screen>
1110
1108
</para>
1111
1109
<para>
1112
- You should remember that trace programs need to be carefully written and
1110
+ You should remember that DTrace scripts need to be carefully written and
1113
1111
debugged prior to their use, otherwise the trace information collected might
1114
1112
be meaningless. In most cases where problems are found it is the
1115
1113
instrumentation that is at fault, not the underlying system. When
@@ -1119,75 +1117,127 @@ Total time (ns) 2312105013
1119
1117
</sect2>
1120
1118
1121
1119
<sect2 id="defining-trace-points">
1122
- <title>Defining Trace Points </title>
1120
+ <title>Defining New Probes </title>
1123
1121
1124
1122
<para>
1125
- New trace points can be defined within the code wherever the developer
1126
- desires, though this will require a recompilation.
1123
+ New probes can be defined within the code wherever the developer
1124
+ desires, though this will require a recompilation. Below are the steps
1125
+ for inserting new probes:
1127
1126
</para>
1128
1127
1129
- <para>
1130
- A trace point can be inserted by using one of the
1131
- trace macros. These are chosen according to how many variables will
1132
- be made available for inspection at that trace point. Tracing the
1133
- occurrence of an event can be achieved with a single line, using
1134
- just the trace point name, e.g.:
1135
- <programlisting>
1136
- PG_TRACE (my__new__trace__point);
1137
- </programlisting>
1138
- More complex trace points can be provided with one or more variables
1139
- for inspection by the dynamic tracing utility by using the
1140
- <literal>PG_TRACE</><replaceable>n</> macro that corresponds to the number
1141
- of parameters after the trace point name:
1128
+ <procedure>
1129
+ <step>
1130
+ <para>
1131
+ Decide on probe names and data to be made available through the probes
1132
+ </para>
1133
+ </step>
1134
+
1135
+ <step>
1136
+ <para>
1137
+ Add the probe definitons to <filename>src/backend/src/utils/probes.d</>
1138
+ </para>
1139
+ </step>
1140
+
1141
+ <step>
1142
+ <para>
1143
+ Insert a one-line probe macros at the desired locations in the source code
1144
+ </para>
1145
+ </step>
1146
+
1147
+ <step>
1148
+ <para>
1149
+ Recompile and verify that the new probes are available
1150
+ </para>
1151
+ </step>
1152
+ </procedure>
1153
+
1154
+ <formalpara>
1155
+ <title>Example:</title>
1156
+ <para>
1157
+ Here is an example of how you would add a probe to trace all new transactions by transaction ID.
1158
+ </para>
1159
+ </formalpara>
1160
+
1161
+ <procedure>
1162
+ <step>
1163
+ <para>
1164
+ Name the probe transaction-start and give it a parameter of type integer (type of transaction ID)
1165
+ </para>
1166
+ </step>
1167
+
1168
+ <step>
1169
+ <para>
1170
+ Add <quote>probe transaction__start(int);</quote> to
1171
+ <filename>src/backend/src/utils/probes.d</>, and it should look like the following:
1142
1172
<programlisting>
1143
- PG_TRACE3 (my__complex__event, varX, varY, varZ);
1173
+ provider postgresql {
1174
+ ...
1175
+ probe transaction__start(int);
1176
+ ...
1177
+ };
1144
1178
</programlisting>
1145
- The definition of the transaction__start trace point is shown below:
1179
+ Note the use of the double underline in the probe name. In the DTrace
1180
+ script, the double underline needs to be replaced with a hyphen.
1181
+ </para>
1182
+
1183
+ <para>
1184
+ You should take care that the data types specified for the probe arguments
1185
+ match the data types of the variables used in the macro. Otherwise, you
1186
+ will get compilation errors.
1187
+ </para>
1188
+ </step>
1189
+
1190
+ <step>
1191
+ <para>
1192
+ At compile time, transaction__start is converted to a macro called
1193
+ TRACE_POSTGRESQL_TRANSACTION_START, and it resides in
1194
+ <filename>src/backend/src/utils/probes.h</>. Before recompiling, add
1195
+ the single line macro to the appropriate location in the source code.
1196
+ In this case, it looks like the following:
1197
+ </para>
1198
+
1199
+ <para>
1146
1200
<programlisting>
1147
1201
static void
1148
1202
StartTransaction(void)
1149
1203
{
1150
1204
...
1151
1205
1152
1206
/*
1153
- * generate a new transaction id
1207
+ * Advertise it in the proc array. We assume assignment of
1208
+ * LocalTransactionID is atomic, and the backendId should be set already.
1154
1209
*/
1155
- s->transactionId = GetNewTransactionId(false);
1210
+ Assert(MyProc->backendId == vxid.backendId);
1211
+ MyProc->lxid = vxid.localTransactionId;
1156
1212
1157
- XactLockTableInsert(s->transactionId);
1158
-
1159
- PG_TRACE1(transaction__start, s->transactionId);
1213
+ TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
1160
1214
1161
1215
...
1162
1216
}
1163
1217
</programlisting>
1164
- Note how the transaction ID is made available to the dynamic tracing
1165
- utility.
1166
- </para>
1218
+ Note how the transaction ID is made available to the dynamic tracing
1219
+ utility.
1220
+ </para>
1221
+ </step>
1167
1222
1168
- <para>
1169
- The dynamic tracing utility might require you to further define these trace
1170
- points. For example, DTrace requires you to add new probes to the file
1171
- <filename>src/backend/utils/probes.d</> as shown here:
1172
- <programlisting>
1173
- provider postgresql {
1174
- ...
1175
- probe transaction__start(int);
1176
- ...
1177
- };
1178
- </programlisting>
1179
- </para>
1223
+ <step>
1224
+ <para>
1225
+ After recompiling and running the new binary, check that your newly added
1226
+ probe is available by executing the following DTrace command, and you
1227
+ should see similar output.
1228
+ <screen>
1229
+ # dtrace -ln transaction-start
1230
+ ID PROVIDER MODULE FUNCTION NAME
1231
+ 18705 postgresql49878 postgres StartTransactionCommand transaction-start
1232
+ 18755 postgresql49877 postgres StartTransactionCommand transaction-start
1233
+ 18805 postgresql49876 postgres StartTransactionCommand transaction-start
1234
+ 18855 postgresql49875 postgres StartTransactionCommand transaction-start
1235
+ 18986 postgresql49873 postgres StartTransactionCommand transaction-start
1236
+ </screen>
1237
+ </para>
1238
+ </step>
1239
+ </procedure>
1180
1240
1181
- <para>
1182
- You should take care that the data types specified for the probe arguments
1183
- match the data types of the variables used in the <literal>PG_TRACE</>
1184
- macro. This is not checked at compile time. You can check that your newly
1185
- added trace point is available by recompiling, then running the new binary,
1186
- and as root, executing a DTrace command such as:
1187
- <programlisting>
1188
- dtrace -l -n transaction-start
1189
- </programlisting>
1190
- </para>
1191
1241
</sect2>
1192
1242
1193
1243
</sect1>
0 commit comments