[PATCH] Fix documentation bug in how to calculate the quasi-unique pg_log session_id - Mailing list pgsql-hackers

From Joel Jacobson
Subject [PATCH] Fix documentation bug in how to calculate the quasi-unique pg_log session_id
Date
Msg-id CAASwCXdKR5pH3wxbgNMyi9f4-L70nzSskXq+CsGzGi_zc=_drg@mail.gmail.com
Whole thread Raw
Responses Re: [PATCH] Fix documentation bug in how to calculate the quasi-unique pg_log session_id  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Fix documentation bug in how to calculate the quasi-unique pg_log session_id

While the code is truncating the backend_start time, the query example in the documentation is rouding.
Fix by doing the same thing in the documentation as in, i.e. truncating the backend_start.

elog.c:
snprintf(strfbuf, sizeof(strfbuf) - 1, "%lx.%x",
            (long) (MyStartTime), MyProcPid);

Example:

2015-06-02 16:50:29.045 CEST,"joel","gluepay",49262,"93.158.127.42:41093",556d7a0a.c06e,5062,"idle in transaction",2015-06-02 11:40:26 CEST,17/19970778,0,LOG,00000,"statement: select * from foo where bar = 'baz';",,,,,,,,"exec_simple_query, postgres.c:876","psql"

select backend_start, procpid, to_hex(EXTRACT(EPOCH FROM backend_start)::integer) || '.' || to_hex(procpid) as invalid_session_id from pg_stat_activity_log where procpid = 49262;
         backend_start         | procpid | invalid_session_id 
-------------------------------+---------+--------------------
 2015-06-02 11:40:26.516373+02 |   49262 | 556d7a0b.c06e

select backend_start, procpid, to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' || to_hex(procpid) as valid_session_id from pg_stat_activity_log where procpid = 49262;
         backend_start         | procpid | valid_session_id 
-------------------------------+---------+------------------
 2015-06-02 11:40:26.516373+02 |   49262 | 556d7a0a.c06e

---

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 5549b7d..1da7dfb 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -4707,7 +4707,7 @@ local0.*    /var/log/postgresql
          of printing those items.  For example, to generate the session
          identifier from <literal>pg_stat_activity</>, use this query:
 <programlisting>
-SELECT to_hex(EXTRACT(EPOCH FROM backend_start)::integer) || '.' ||
+SELECT to_hex(trunc(EXTRACT(EPOCH FROM backend_start))::integer) || '.' ||
        to_hex(pid)
 FROM pg_stat_activity;
 </programlisting>

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: checkpointer continuous flushing
Next
From: Andres Freund
Date:
Subject: Re: Re: [GENERAL] 9.4.1 -> 9.4.2 problem: could not access status of transaction 1