Обсуждение: [PATCH] Fix documentation bug in how to calculate the quasi-unique pg_log session_id

Поиск
Список
Период
Сортировка

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

От
Joel Jacobson
Дата:
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>

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

От
Robert Haas
Дата:
On Tue, Jun 2, 2015 at 11:22 AM, Joel Jacobson <joel@trustly.com> wrote:
> Fix documentation bug in how to calculate the quasi-unique pg_log session_id

Committed.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company