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

From: Joel Jacobson <joel(at)trustly(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Fix documentation bug in how to calculate the quasi-unique pg_log session_id
Date: 2015-06-02 15:22:58
Message-ID: CAASwCXdKR5pH3wxbgNMyi9f4-L70nzSskXq+CsGzGi_zc=_drg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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>

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2015-06-02 15:27:33 Re: Re: [GENERAL] 9.4.1 -> 9.4.2 problem: could not access status of transaction 1
Previous Message Andres Freund 2015-06-02 15:16:59 Re: checkpointer continuous flushing