Thread: How to print application_name in log_line_prefix (using %a)?
Could anyone tell me how to specify the application_name as the log_line_prefix?
According to the manual at http://www.postgresql.org/docs/9.2/static/runtime-config-logging.html#GUC-APPLICATION-NAME:
"
application_name (string)
The application_name can be any string of less than NAMEDATALEN characters (64 characters in a standard build). It is typically set by an application upon connection to the server. The name will be displayed in the pg_stat_activity view and included in CSV log entries. It can also be included in regular log entries via the log_line_prefix parameter. Only printable ASCII characters may be used in the application_name value...
and also, the manual entry for log_line_prefix (http://www.postgresql.org/docs/9.2/static/runtime-config-logging.html#GUC-LOG-LINE-PREFIX)
"
log_line_prefix (string)
This is a
printf
-style string that is output at the beginning of each log line. % characters begin "escape sequences" that are replaced with status information as outlined below... %a Application name
"
However, I have the following configuration settings in postgresql.conf
application_name = 'mypostgres'
log_line_prefix = '[%a] '
But, my log line is prefixed as "[] " like
[] LOG: 00000: database system was shut down at 2012-10-28 22:15:08 PDT
[] LOCATION: StartupXLOG, xlog.c:6112
[] LOG: 00000: autovacuum launcher started
[] LOCATION: AutoVacLauncherMain, autovacuum.c:407
[] LOG: 00000: database system is ready to accept connections
[] LOCATION: reaper, postmaster.c:2408
Did I miss something?
Thanks a lot!
Tianyin
--
Tianyin XU,
http://cseweb.ucsd.edu/~tixu/
Could anyone tell me how to specify the application_name as the log_line_prefix?
According to the manual at http://www.postgresql.org/docs/9.2/static/runtime-config-logging.html#GUC-APPLICATION-NAME:
"
application_name (string)
The application_name can be any string of less than NAMEDATALEN characters (64 characters in a standard build). It is typically set by an application upon connection to the server. The name will be displayed in the pg_stat_activity view and included in CSV log entries. It can also be included in regular log entries via the log_line_prefix parameter. Only printable ASCII characters may be used in the application_name value...
and also, the manual entry for log_line_prefix (http://www.postgresql.org/docs/9.2/static/runtime-config-logging.html#GUC-LOG-LINE-PREFIX)
"
log_line_prefix (string)
This is a
printf
-style string that is output at the beginning of each log line. % characters begin "escape sequences" that are replaced with status information as outlined below... %a Application name
"
However, I have the following configuration settings in postgresql.conf
application_name = 'mypostgres'
log_line_prefix = '[%a] '
But, my log line is prefixed as "[] " like
[] LOG: 00000: database system was shut down at 2012-10-28 22:15:08 PDT
[] LOCATION: StartupXLOG, xlog.c:6112
[] LOG: 00000: autovacuum launcher started
[] LOCATION: AutoVacLauncherMain, autovacuum.c:407
[] LOG: 00000: database system is ready to accept connections
[] LOCATION: reaper, postmaster.c:2408
Did I miss something?
Thanks a lot!
Tianyin
--
Tianyin XU,
http://cseweb.ucsd.edu/~tixu/
On Mon, Oct 29, 2012 at 4:18 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote: > However, I have the following configuration settings in postgresql.conf > > application_name = 'mypostgres' > log_line_prefix = '[%a] ' > I'm not familiar with this usage of setting application_name in postgresql.conf - usually I set it as part of the database connection. For example: //In Pike: object db=Sql.Sql("pgsql://USER:PASSWORD@HOST/DATABASE",(["search_path":"SCHEMA,public","application_name":"APPLICATION"])); //In PHP: $db=pg_connect('dbname=DATABASE host=HOST user=USER password=PASSWORD'); pg_query($db,"set application_name='APPLICATION'"); pg_query($db,"set search_path to SCHEMA,public"); ChrisA
Yes, the manual said that "It is typically set by an application upon connection to the server." exactly your approach.
But the examples you gave me is to print the application_name in the query results, aren't they? Do you know how to make it as the prefix of the local log messages?
T
On Mon, Oct 29, 2012 at 4:18 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote:I'm not familiar with this usage of setting application_name in
> However, I have the following configuration settings in postgresql.conf
>
> application_name = 'mypostgres'
> log_line_prefix = '[%a] '
>
postgresql.conf - usually I set it as part of the database connection.
For example:
//In Pike:
object db=Sql.Sql("pgsql://USER:PASSWORD@HOST/DATABASE",(["search_path":"SCHEMA,public","application_name":"APPLICATION"]));
//In PHP:
$db=pg_connect('dbname=DATABASE host=HOST user=USER password=PASSWORD');
pg_query($db,"set application_name='APPLICATION'");
pg_query($db,"set search_path to SCHEMA,public");
ChrisA
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
Tianyin XU,
http://cseweb.ucsd.edu/~tixu/
On Mon, Oct 29, 2012 at 5:22 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote: > Thanks a lot, Chris! > > Yes, the manual said that "It is typically set by an application upon > connection to the server." exactly your approach. > > But the examples you gave me is to print the application_name in the query > results, aren't they? Do you know how to make it as the prefix of the local > log messages? The examples I gave configure the application_name for a given connection. Everything that connection does will then get logged with that name, if you use %a. You can also see that name in pg_stat_activity. ChrisA
I still wonder why application_name appears in the configuration file if it cannot take effort :-P
T
On Mon, Oct 29, 2012 at 5:22 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote:The examples I gave configure the application_name for a given
> Thanks a lot, Chris!
>
> Yes, the manual said that "It is typically set by an application upon
> connection to the server." exactly your approach.
>
> But the examples you gave me is to print the application_name in the query
> results, aren't they? Do you know how to make it as the prefix of the local
> log messages?
connection. Everything that connection does will then get logged with
that name, if you use %a. You can also see that name in
pg_stat_activity.
ChrisA
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
Tianyin XU,
http://cseweb.ucsd.edu/~tixu/
On Mon, Oct 29, 2012 at 5:44 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote: > Got it! Thanks, Chris! > > I still wonder why application_name appears in the configuration file if it > cannot take effort :-P Not sure what you mean by that, but my postgresql.conf doesn't have anything about application_name. But if it did, it would be a default that an application can override. ChrisA
On 10/29/2012 04:00 AM, Chris Angelico wrote: > On Mon, Oct 29, 2012 at 5:44 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote: >> Got it! Thanks, Chris! >> >> I still wonder why application_name appears in the configuration file if it >> cannot take effort :-P > > Not sure what you mean by that, but my postgresql.conf doesn't have > anything about application_name. But if it did, it would be a default > that an application can override. Actually it does: log_line_prefix = # %a = application name # %u = user name # %d = database name http://www.postgresql.org/docs/9.2/interactive/runtime-config-logging.html#GUC-APPLICATION-NAME .... It is a chicken and egg situation. See section 31.1.2. Parameter Key Words of below: http://www.postgresql.org/docs/9.2/interactive/libpq-connect.html "application_name Specifies a value for the application_name configuration parameter." > > ChrisA > > -- Adrian Klaver adrian.klaver@gmail.com
On Tue, Oct 30, 2012 at 12:53 AM, Adrian Klaver <adrian.klaver@gmail.com> wrote: > On 10/29/2012 04:00 AM, Chris Angelico wrote: >> >> Not sure what you mean by that, but my postgresql.conf doesn't have >> anything about application_name. But if it did, it would be a default >> that an application can override. > > > Actually it does: > > log_line_prefix = # %a = application name > # %u = user name > # %d = database name > > http://www.postgresql.org/docs/9.2/interactive/runtime-config-logging.html#GUC-APPLICATION-NAME Yep, but it doesn't have anything about _setting_ the app name. The original question involved a postgresql.conf directive "application_name = '....'", which I can't find any docs for, nor can I find in my well-commented default config from the openscg install. > It is a chicken and egg situation. See section 31.1.2. Parameter Key Words > of below: > > http://www.postgresql.org/docs/9.2/interactive/libpq-connect.html > > "application_name > Specifies a value for the application_name configuration parameter." That's on the connection, which is where I'm recommending setting it. There's no magic that picks up your application's executable name, but you can of course pass argv[0] to libpq as the application_name. ChrisA
Chris Angelico <rosuav@gmail.com> writes: > On Mon, Oct 29, 2012 at 5:44 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote: >> I still wonder why application_name appears in the configuration file if it >> cannot take effort :-P > Not sure what you mean by that, but my postgresql.conf doesn't have > anything about application_name. But if it did, it would be a default > that an application can override. The reason background processes don't print anything for %a is that it's presumed it couldn't possibly be set to anything meaningful. While in principle you can set it in the configuration file as a default for uninformed clients, it's not clear there's a good reason to do that. Even if you think that's a good idea, we'd still not want background processes to print it, because then you couldn't tell the difference between log entries from background processes and those from uninformed clients. regards, tom lane
On Mon, Oct 29, 2012 at 8:58 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote: > Chris Angelico <rosuav@gmail.com> writes: >> On Mon, Oct 29, 2012 at 5:44 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote: >>> I still wonder why application_name appears in the configuration file if it >>> cannot take effort :-P > >> Not sure what you mean by that, but my postgresql.conf doesn't have >> anything about application_name. But if it did, it would be a default >> that an application can override. > > The reason background processes don't print anything for %a is that it's > presumed it couldn't possibly be set to anything meaningful. Why wouldn't 'bgwriter', 'autovacuum', 'checkpointer', etc. be meaningful? Cheers, Jeff
Then it should not be included in postgresql.conf, since that makes no sense for setting it.
@Chris, it is in the docs, see the following PG-9.2 manual page:
http://www.postgresql.org/docs/9.2/interactive/runtime-config-logging.html#GUC-APPLICATION-NAME
T
Chris Angelico <rosuav@gmail.com> writes:
> On Mon, Oct 29, 2012 at 5:44 PM, Tianyin Xu <tixu@cs.ucsd.edu> wrote:>> I still wonder why application_name appears in the configuration file if itThe reason background processes don't print anything for %a is that it's
>> cannot take effort :-P
> Not sure what you mean by that, but my postgresql.conf doesn't have
> anything about application_name. But if it did, it would be a default
> that an application can override.
presumed it couldn't possibly be set to anything meaningful. While in
principle you can set it in the configuration file as a default for
uninformed clients, it's not clear there's a good reason to do that.
Even if you think that's a good idea, we'd still not want background
processes to print it, because then you couldn't tell the difference
between log entries from background processes and those from uninformed
clients.
regards, tom lane
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
Tianyin XU,
http://cseweb.ucsd.edu/~tixu/
On 10/29/2012 11:03 AM, Tianyin Xu wrote: > I see. > > Then it should not be included in postgresql.conf, since that makes no > sense for setting it. > How do you figure? AFAIK if you set it then it will be a default for all non-background connections. In the event a connection specifies a application_name then that will be used. > > -- > Tianyin XU, > http://cseweb.ucsd.edu/~tixu/ <http://cseweb.ucsd.edu/%7Etixu/> -- Adrian Klaver adrian.klaver@gmail.com