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

Commit8217cfb

Browse files
committed
Add support for an application_name parameter, which is displayed in
pg_stat_activity and recorded in log entries.Dave Page, reviewed by Andres Freund
1 parentcb98f61 commit8217cfb

File tree

16 files changed

+478
-94
lines changed

16 files changed

+478
-94
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.234 2009/11/2816:21:31 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.235 2009/11/2823:38:06 tgl Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -2882,6 +2882,26 @@ local0.* /var/log/postgresql
28822882

28832883
<variablelist>
28842884

2885+
<varlistentry id="guc-application-name" xreflabel="application_name">
2886+
<term><varname>application_name</varname> (<type>string</type>)</term>
2887+
<indexterm>
2888+
<primary><varname>application_name</> configuration parameter</primary>
2889+
</indexterm>
2890+
<listitem>
2891+
<para>
2892+
The <varname>application_name</varname> can be any string of less than
2893+
<symbol>NAMEDATALEN</> characters (64 characters in a standard build).
2894+
It is typically set by an application upon connection to the server.
2895+
The name will be displayed in the <structname>pg_stat_activity</> view
2896+
and included in CSV log entries. It can also be included in regular
2897+
log entries via the <xref linkend="guc-log-line-prefix"> parameter.
2898+
Only printable ASCII characters may be used in the
2899+
<varname>application_name</varname> value. Other characters will be
2900+
replaced with question marks (<literal>?</literal>).
2901+
</para>
2902+
</listitem>
2903+
</varlistentry>
2904+
28852905
<varlistentry>
28862906
<term><varname>debug_print_parse</varname> (<type>boolean</type>)</term>
28872907
<term><varname>debug_print_rewritten</varname> (<type>boolean</type>)</term>
@@ -3049,7 +3069,7 @@ local0.* /var/log/postgresql
30493069
that are replaced with status information as outlined below.
30503070
Unrecognized escapes are ignored. Other
30513071
characters are copied straight to the log line. Some escapes are
3052-
only recognized by session processes, anddo not apply to
3072+
only recognized by session processes, andare ignored by
30533073
background processes such as the main server process.
30543074
This parameter can only be set in the <filename>postgresql.conf</>
30553075
file or on the server command line. The default is an empty string.
@@ -3064,6 +3084,11 @@ local0.* /var/log/postgresql
30643084
</row>
30653085
</thead>
30663086
<tbody>
3087+
<row>
3088+
<entry><literal>%a</literal></entry>
3089+
<entry>Application name</entry>
3090+
<entry>yes</entry>
3091+
</row>
30673092
<row>
30683093
<entry><literal>%u</literal></entry>
30693094
<entry>User name</entry>
@@ -3287,19 +3312,35 @@ FROM pg_stat_activity;
32873312
<title>Using CSV-Format Log Output</title>
32883313

32893314
<para>
3290-
Including <literal>csvlog</> in the <varname>log_destination</> list
3291-
provides a convenient way to import log files into a database table.
3315+
Including <literal>csvlog</> in the <varname>log_destination</> list
3316+
provides a convenient way to import log files into a database table.
32923317
This option emits log lines in comma-separated-value format,
3293-
with these columns: timestamp with milliseconds, user name, database
3294-
name, process ID, host:port number, session ID, per-session or -process line
3295-
number, command tag, session start time, virtual transaction ID,
3296-
regular transaction id, error severity, SQL state code, error message,
3297-
error message detail, hint, internal query that led to the error (if
3298-
any), character count of the error position thereof, error context,
3318+
with these columns:
3319+
timestamp with milliseconds,
3320+
user name,
3321+
database name,
3322+
process ID,
3323+
client host:port number,
3324+
session ID,
3325+
per-session line number,
3326+
command tag,
3327+
session start time,
3328+
virtual transaction ID,
3329+
regular transaction ID,
3330+
error severity,
3331+
SQL state code,
3332+
error message,
3333+
error message detail,
3334+
hint,
3335+
internal query that led to the error (if any),
3336+
character count of the error position therein,
3337+
error context,
32993338
user query that led to the error (if any and enabled by
3300-
<varname>log_min_error_statement</>), character count of the error
3301-
position thereof, location of the error in the PostgreSQL source code
3302-
(if <varname>log_error_verbosity</> is set to <literal>verbose</>).
3339+
<varname>log_min_error_statement</>),
3340+
character count of the error position therein,
3341+
location of the error in the PostgreSQL source code
3342+
(if <varname>log_error_verbosity</> is set to <literal>verbose</>),
3343+
and application name.
33033344
Here is a sample table definition for storing CSV-format log output:
33043345

33053346
<programlisting>
@@ -3327,6 +3368,7 @@ CREATE TABLE postgres_log
33273368
query text,
33283369
query_pos integer,
33293370
location text,
3371+
application_name text,
33303372
PRIMARY KEY (session_id, session_line_num)
33313373
);
33323374
</programlisting>

‎doc/src/sgml/libpq.sgml

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.289 2009/05/2820:02:10 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.290 2009/11/2823:38:06 tgl Exp $ -->
22

33
<chapter id="libpq">
44
<title><application>libpq</application> - C Library</title>
@@ -249,6 +249,32 @@
249249
</listitem>
250250
</varlistentry>
251251

252+
<varlistentry id="libpq-connect-application-name" xreflabel="application_name">
253+
<term><literal>application_name</literal></term>
254+
<listitem>
255+
<para>
256+
Specifies a value for the <xref linkend="guc-application-name">
257+
configuration parameter.
258+
</para>
259+
</listitem>
260+
</varlistentry>
261+
262+
<varlistentry id="libpq-connect-fallback-application-name" xreflabel="fallback_application_name">
263+
<term><literal>fallback_application_name</literal></term>
264+
<listitem>
265+
<para>
266+
Specifies a fallback value for the <xref
267+
linkend="guc-application-name"> configuration parameter.
268+
This value will be used if no value has been given for
269+
<literal>application_name</> via a connection parameter or the
270+
<envar>PGAPPNAME</envar> environment variable. Specifying
271+
a fallback name is useful in generic utility programs that
272+
wish to set a default application name but allow it to be
273+
overridden by the user.
274+
</para>
275+
</listitem>
276+
</varlistentry>
277+
252278
<varlistentry id="libpq-connect-tty" xreflabel="tty">
253279
<term><literal>tty</literal></term>
254280
<listitem>
@@ -5672,7 +5698,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
56725698
<indexterm>
56735699
<primary><envar>PGHOST</envar></primary>
56745700
</indexterm>
5675-
<envar>PGHOST</envar> behaves the same as <xref
5701+
<envar>PGHOST</envar> behaves the same asthe<xref
56765702
linkend="libpq-connect-host"> connection parameter.
56775703
</para>
56785704
</listitem>
@@ -5682,7 +5708,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
56825708
<indexterm>
56835709
<primary><envar>PGHOSTADDR</envar></primary>
56845710
</indexterm>
5685-
<envar>PGHOSTADDR</envar> behaves the same as <xref
5711+
<envar>PGHOSTADDR</envar> behaves the same asthe<xref
56865712
linkend="libpq-connect-hostaddr"> connection parameter.
56875713
This can be set instead of or in addition to <envar>PGHOST</envar>
56885714
to avoid DNS lookup overhead.
@@ -5694,7 +5720,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
56945720
<indexterm>
56955721
<primary><envar>PGPORT</envar></primary>
56965722
</indexterm>
5697-
<envar>PGPORT</envar> behaves the same as <xref
5723+
<envar>PGPORT</envar> behaves the same asthe<xref
56985724
linkend="libpq-connect-port"> connection parameter.
56995725
</para>
57005726
</listitem>
@@ -5704,7 +5730,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
57045730
<indexterm>
57055731
<primary><envar>PGDATABASE</envar></primary>
57065732
</indexterm>
5707-
<envar>PGDATABASE</envar> behaves the same as <xref
5733+
<envar>PGDATABASE</envar> behaves the same asthe<xref
57085734
linkend="libpq-connect-dbname"> connection parameter.
57095735
</para>
57105736
</listitem>
@@ -5714,9 +5740,8 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
57145740
<indexterm>
57155741
<primary><envar>PGUSER</envar></primary>
57165742
</indexterm>
5717-
<envar>PGUSER</envar> behaves the same as <xref
5743+
<envar>PGUSER</envar> behaves the same asthe<xref
57185744
linkend="libpq-connect-user"> connection parameter.
5719-
database.
57205745
</para>
57215746
</listitem>
57225747

@@ -5725,12 +5750,12 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
57255750
<indexterm>
57265751
<primary><envar>PGPASSWORD</envar></primary>
57275752
</indexterm>
5728-
<envar>PGPASSWORD</envar> behaves the same as <xref
5753+
<envar>PGPASSWORD</envar> behaves the same asthe<xref
57295754
linkend="libpq-connect-password"> connection parameter.
57305755
Use of this environment variable
5731-
is not recommended for security reasons (some operating systems
5756+
is not recommended for security reasons, assome operating systems
57325757
allow non-root users to see process environment variables via
5733-
<application>ps</>); instead consider using the
5758+
<application>ps</>; instead consider using the
57345759
<filename>~/.pgpass</> file (see <xref linkend="libpq-pgpass">).
57355760
</para>
57365761
</listitem>
@@ -5751,7 +5776,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
57515776
<indexterm>
57525777
<primary><envar>PGSERVICE</envar></primary>
57535778
</indexterm>
5754-
<envar>PGSERVICE</envar> behaves the same as <xref
5779+
<envar>PGSERVICE</envar> behaves the same asthe<xref
57555780
linkend="libpq-connect-service"> connection parameter.
57565781
</para>
57575782
</listitem>
@@ -5777,17 +5802,27 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
57775802
<indexterm>
57785803
<primary><envar>PGOPTIONS</envar></primary>
57795804
</indexterm>
5780-
<envar>PGOPTIONS</envar> behaves the same as <xref
5805+
<envar>PGOPTIONS</envar> behaves the same asthe<xref
57815806
linkend="libpq-connect-options"> connection parameter.
57825807
</para>
57835808
</listitem>
57845809

5810+
<listitem>
5811+
<para>
5812+
<indexterm>
5813+
<primary><envar>PGAPPNAME</envar></primary>
5814+
</indexterm>
5815+
<envar>PGAPPNAME</envar> behaves the same as the <xref
5816+
linkend="libpq-connect-application-name"> connection parameter.
5817+
</para>
5818+
</listitem>
5819+
57855820
<listitem>
57865821
<para>
57875822
<indexterm>
57885823
<primary><envar>PGSSLMODE</envar></primary>
57895824
</indexterm>
5790-
<envar>PGSSLMODE</envar> behaves the same as <xref
5825+
<envar>PGSSLMODE</envar> behaves the same asthe<xref
57915826
linkend="libpq-connect-sslmode"> connection parameter.
57925827
</para>
57935828
</listitem>
@@ -5797,7 +5832,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
57975832
<indexterm>
57985833
<primary><envar>PGREQUIRESSL</envar></primary>
57995834
</indexterm>
5800-
<envar>PGREQUIRESSL</envar> behaves the same as <xref
5835+
<envar>PGREQUIRESSL</envar> behaves the same asthe<xref
58015836
linkend="libpq-connect-requiressl"> connection parameter.
58025837
</para>
58035838
</listitem>
@@ -5807,7 +5842,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
58075842
<indexterm>
58085843
<primary><envar>PGSSLCERT</envar></primary>
58095844
</indexterm>
5810-
<envar>PGSSLCERT</envar> behaves the same as <xref
5845+
<envar>PGSSLCERT</envar> behaves the same asthe<xref
58115846
linkend="libpq-connect-sslcert"> connection parameter.
58125847
</para>
58135848
</listitem>
@@ -5817,7 +5852,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
58175852
<indexterm>
58185853
<primary><envar>PGSSLKEY</envar></primary>
58195854
</indexterm>
5820-
<envar>PGSSLKEY</envar> behaves the same as <xref
5855+
<envar>PGSSLKEY</envar> behaves the same asthe<xref
58215856
linkend="libpq-connect-sslkey"> connection parameter.
58225857
</para>
58235858
</listitem>
@@ -5827,7 +5862,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
58275862
<indexterm>
58285863
<primary><envar>PGSSLROOTCERT</envar></primary>
58295864
</indexterm>
5830-
<envar>PGSSLROOTCERT</envar> behaves the same as <xref
5865+
<envar>PGSSLROOTCERT</envar> behaves the same asthe<xref
58315866
linkend="libpq-connect-sslrootcert"> connection parameter.
58325867
</para>
58335868
</listitem>
@@ -5837,7 +5872,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
58375872
<indexterm>
58385873
<primary><envar>PGSSLCRL</envar></primary>
58395874
</indexterm>
5840-
<envar>PGSSLCRL</envar> behaves the same as <xref
5875+
<envar>PGSSLCRL</envar> behaves the same asthe<xref
58415876
linkend="libpq-connect-sslcrl"> connection parameter.
58425877
</para>
58435878
</listitem>
@@ -5847,7 +5882,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
58475882
<indexterm>
58485883
<primary><envar>PGKRBSRVNAME</envar></primary>
58495884
</indexterm>
5850-
<envar>PGKRBSRVNAME</envar> behaves the same as <xref
5885+
<envar>PGKRBSRVNAME</envar> behaves the same asthe<xref
58515886
linkend="libpq-connect-krbsrvname"> connection parameter.
58525887
</para>
58535888
</listitem>
@@ -5857,7 +5892,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
58575892
<indexterm>
58585893
<primary><envar>PGGSSLIB</envar></primary>
58595894
</indexterm>
5860-
<envar>PGGSSLIB</envar> behaves the same as <xref
5895+
<envar>PGGSSLIB</envar> behaves the same asthe<xref
58615896
linkend="libpq-connect-gsslib"> connection parameter.
58625897
</para>
58635898
</listitem>
@@ -5867,7 +5902,7 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough)
58675902
<indexterm>
58685903
<primary><envar>PGCONNECT_TIMEOUT</envar></primary>
58695904
</indexterm>
5870-
<envar>PGCONNECT_TIMEOUT</envar> behaves the same as <xref
5905+
<envar>PGCONNECT_TIMEOUT</envar> behaves the same asthe<xref
58715906
linkend="libpq-connect-connect-timeout"> connection parameter.
58725907
</para>
58735908
</listitem>

‎doc/src/sgml/monitoring.sgml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.71 2009/06/26 22:08:17 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.72 2009/11/28 23:38:07 tgl Exp $ -->
22

33
<chapter id="monitoring">
44
<title>Monitoring Database Activity</title>
@@ -238,12 +238,12 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
238238
name, process <acronym>ID</>, user OID, user name, current query,
239239
query's waiting status, time at which the current transaction and
240240
current query began execution, time at which the process was
241-
started,andclient's address and port number. The columns that
242-
report data on the current query are available unless the parameter
243-
<varname>track_activities</varname> has been turned off.
244-
Furthermore, these columns are only visible if the user examining
245-
the view is a superuser or the same as the user owning the process
246-
being reported on.
241+
started, client's address and port number, and application name.
242+
The columns thatreport data on the current query are available unless
243+
the parameter<varname>track_activities</varname> has been turned off.
244+
Furthermore, these columnsand the application nameare only visible if
245+
theuser examining theview is a superuser or the same as the user
246+
owning the processbeing reported on.
247247
</entry>
248248
</row>
249249

‎src/backend/catalog/system_views.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 1996-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.61 2009/10/07 22:14:18 alvherre Exp $
6+
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.62 2009/11/28 23:38:07 tgl Exp $
77
*/
88

99
CREATEVIEWpg_rolesAS
@@ -339,7 +339,8 @@ CREATE VIEW pg_stat_activity AS
339339
S.query_start,
340340
S.backend_start,
341341
S.client_addr,
342-
S.client_port
342+
S.client_port,
343+
S.application_name
343344
FROM pg_database D, pg_stat_get_activity(NULL)AS S, pg_authid U
344345
WHERES.datid=D.oidAND
345346
S.usesysid=U.oid;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp