pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #16049: log_line_prefix=%a and log_connections - application_name missing
5+ messages / 4 participants
[nested] [flat]
* BUG #16049: log_line_prefix=%a and log_connections - application_name missing
@ 2019-10-11 14:12 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 5+ messages in thread
From: PG Bug reporting form @ 2019-10-11 14:12 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: deathlock13@gmail.com
The following bug has been logged on the website:
Bug reference: 16049
Logged by: death lock
Email address: deathlock13@gmail.com
PostgreSQL version: 9.5.19
Operating system: Debian 11
Description:
[unknown] LOCATION: BackendRun, postmaster.c:4300
[unknown] DEBUG: 00000: InitPostgres
[unknown] LOCATION: InitPostgres, postinit.c:555
[unknown] DEBUG: 00000: my backend ID is 4
[unknown] LOCATION: SharedInvalBackendInit, sinvaladt.c:324
[unknown] DEBUG: 00000: StartTransaction
[unknown] LOCATION: ShowTransactionState, xact.c:4975
[unknown] DEBUG: 00000: name: unnamed; blockState: DEFAULT; state:
INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
[unknown] LOCATION: ShowTransactionStateRec, xact.c:5004
# log_connections - application_name MIA
[unknown] LOG: 00000: connection authorized: user=postgres
database=postgres
[unknown] LOCATION: PerformAuthentication, postinit.c:257
psql DEBUG: 00000: CommitTransaction
psql LOCATION: ShowTransactionState, xact.c:4975
psql DEBUG: 00000: name: unnamed; blockState: STARTED; state:
INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
...
psql DEBUG: 00000: proc_exit(0): 4 callbacks to make
psql LOCATION: proc_exit_prepare, ipc.c:187
# log_disconnections=on
psql LOG: 00000: disconnection: session time: 0:00:10.280 user=postgres
database=postgres host=[local]
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #16049: log_line_prefix=%a and log_connections - application_name missing
@ 2019-10-11 14:36 Tom Lane <tgl@sss.pgh.pa.us>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 2 replies; 5+ messages in thread
From: Tom Lane @ 2019-10-11 14:36 UTC (permalink / raw)
To: deathlock13@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org
PG Bug reporting form <noreply@postgresql.org> writes:
> # log_connections - application_name MIA
> [unknown] LOG: 00000: connection authorized: user=postgres
> database=postgres
This was changed about a year ago, see
https://www.postgresql.org/message-id/flat/CAHJZqBB_Pxv8HRfoh%2BAB4KxSQQuPVvtYCzMg7woNR3r7dfmopw%40m...
so v12 will do what you want.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #16049: log_line_prefix=%a and log_connections - application_name missing
@ 2019-10-15 12:34 death lock <deathlock13@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 5+ messages in thread
From: death lock @ 2019-10-15 12:34 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@lists.postgresql.org
"will do what you want." Not exactly - I want it to appear according
to my log_line_prefix - 4 ex. ='%t|%p|%a|%d|%u|%h| '
I've used that patch on 9.5.19
In elog.c there's : const char *appname = application_name; // line 2357
other cases have : const char *username = MyProcPort->user_name;
After adding 'MyProcPort->' to %a case '|psql|' shows up like I
wanted .. but connection process Segfaults :/
I've tracked it to postinit.c - process_startup_options() - this loop
: while (gucopts) {...}
gucopts = list_head(port->guc_options);
ereport(LOG, (errmsg(" +++ process_startup_options : [%s] ",
gucopts))); // adding this line returns :
2019-10-15 14:28:03 CEST|9760|psql|postgres|postgres|[local]|
LOCATION: PerformAuthentication, postinit.c:257
2019-10-15 14:28:03 CEST|9760|psql|postgres|postgres|[local]| LOG:
00000: +++ process_startup_options : [local all
all trust]
2019-10-15 14:28:03 CEST|9760|psql|postgres|postgres|[local]|
LOCATION: process_startup_options, postinit.c:1066
Sorry 4 nagging , any pointers much appreciated
On 10/11/19, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> This was changed about a year ago, see
>
> https://www.postgresql.org/message-id/flat/CAHJZqBB_Pxv8HRfoh%2BAB4KxSQQuPVvtYCzMg7woNR3r7dfmopw%40m...
>
> so v12 will do what you want.
>
> regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #16049: log_line_prefix=%a and log_connections - application_name missing
@ 2019-10-16 11:42 death lock <deathlock13@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 5+ messages in thread
From: death lock @ 2019-10-16 11:42 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@lists.postgresql.org
Not sure where I messed up yesterday , slimmed patch in attachment
inline patch 1: postgresql-9.5.19/src/backend/utils/error/elog.c (+3/-1 lines) download inline-1.patch
--- postgresql-9.5.19/src/backend/utils/error/elog.c
+++ postgresql-9.5.19/src/backend/utils/error/elog.c
@@ -2354,7 +2354,9 @@
case 'a':
if (MyProcPort)
{
- const char *appname = application_name;
+
+ // ereport(LOG, (errmsg(" ++ MyProcPort : [%s] ", application_name)));
+ const char *appname = MyProcPort->application_name;
adding 'MyProcPort->' works great for me
1. why appname =application_name doesn't produce err , but trying to
print application_name value -> SegFault ?
Patches and attachments: download all (2 files, .tar.gz)
pg95appname.patch (text/x-patch, 2.1K) download
--- postgresql-9.5.19/src/include/libpq/libpq-be.h
+++ postgresql-9.5.19/src/include/libpq/libpq-be.h
@@ -139,6 +139,8 @@
char *user_name;
char *cmdline_options;
List *guc_options;
+ char *application_name;
/*
* Information that needs to be held during the authentication cycle.
--- postgresql-9.5.19/src/include/common/string.h
+++ postgresql-9.5.19/src/include/common/string.h
@@ -11,5 +11,6 @@
#define COMMON_STRING_H
extern bool pg_str_endswith(const char *str, const char *end);
+extern void pg_clean_ascii(char *str);
#endif /* COMMON_STRING_H */
--- postgresql-9.5.19/src/common/string.c
+++ postgresql-9.5.19/src/common/string.c
@@ -41,3 +41,16 @@
str += slen - elen;
return strcmp(str, end) == 0;
}
+
+void
+pg_clean_ascii(char *str)
+{
+/* Only allow clean ASCII chars in the string */
+ char *p;
+
+ for (p = str; *p != '\0'; p++)
+ {
+ if (*p < 32 || *p > 126)
+ *p = '?';
+ }
+}
--- postgresql-9.5.19/src/backend/postmaster/postmaster.c
+++ postgresql-9.5.19/src/backend/postmaster/postmaster.c
@@ -95,6 +95,7 @@
#include "access/xlog.h"
#include "bootstrap/bootstrap.h"
#include "catalog/pg_control.h"
+#include "common/string.h"
#include "lib/ilist.h"
#include "libpq/auth.h"
#include "libpq/ip.h"
@@ -2094,6 +2095,16 @@
pstrdup(nameptr));
port->guc_options = lappend(port->guc_options,
pstrdup(valptr));
+
+ if (strcmp(nameptr, "application_name") == 0)
+ {
+ char *tmp_app_name = pstrdup(valptr);
+ pg_clean_ascii(tmp_app_name);
+ port->application_name = tmp_app_name;
+ }
+
}
offset = valoffset + strlen(valptr) + 1;
}
--- postgresql-9.5.19/src/backend/utils/error/elog.c
+++ postgresql-9.5.19/src/backend/utils/error/elog.c
@@ -2354,7 +2354,9 @@
case 'a':
if (MyProcPort)
{
- const char *appname = application_name;
+
+ // ereport(LOG, (errmsg(" ++ MyProcPort : [%s] ", application_name)));
+ const char *appname = MyProcPort->application_name;
if (appname == NULL || *appname == '\0')
appname = _("[unknown]");
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #16049: log_line_prefix=%a and log_connections - application_name missing
@ 2019-10-17 05:40 Michael Paquier <michael@paquier.xyz>
parent: death lock <deathlock13@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Michael Paquier @ 2019-10-17 05:40 UTC (permalink / raw)
To: death lock <deathlock13@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs@lists.postgresql.org
On Wed, Oct 16, 2019 at 01:42:20PM +0200, death lock wrote:
> Not sure where I messed up yesterday , slimmed patch in attachment
As Tom has mentioned on this thread, this has been committed to v12,
and it seems that this qualifies as a new feature so it won't be
back-patched. FWIW, here is the actual commit, your patch could be
more refined based on it I guess:
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=8bddc86400
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2019-10-17 05:40 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 14:12 BUG #16049: log_line_prefix=%a and log_connections - application_name missing PG Bug reporting form <noreply@postgresql.org>
2019-10-11 14:36 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-10-15 12:34 ` death lock <deathlock13@gmail.com>
2019-10-16 11:42 ` death lock <deathlock13@gmail.com>
2019-10-17 05:40 ` Michael Paquier <michael@paquier.xyz>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox