Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 95DCC1E62E85 for ; Wed, 25 Apr 2012 14:54:34 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SN6QC-0002Uz-WB for pgsql-bugs@postgresql.org; Wed, 25 Apr 2012 17:54:34 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q3PHsHJt009541; Wed, 25 Apr 2012 13:54:17 -0400 (EDT) To: Peter Eisentraut cc: i+pgbugs@avdd.tk, pgsql-bugs@postgresql.org Subject: Re: BUG #6602: concurrent psql session clobbers history In-reply-to: <1334866539.24114.10.camel@vanquo.pezone.net> References: <20805.1334862057@sss.pgh.pa.us> <1334866539.24114.10.camel@vanquo.pezone.net> Comments: In-reply-to Peter Eisentraut message dated "Thu, 19 Apr 2012 23:15:39 +0300" Date: Wed, 25 Apr 2012 13:54:16 -0400 Message-ID: <9540.1335376456@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/146 X-Sequence-Number: 32897 Peter Eisentraut writes: > On tor, 2012-04-19 at 15:00 -0400, Tom Lane wrote: >> i+pgbugs@avdd.tk writes: >>> A concurrent psql session will overwrite the history of the first. This >>> does not look good: a database tool causing me to lose my data! >> Works okay for me. I suspect you need to take this up with whoever >> packages libreadline for Ubuntu, because it's going to be libreadline's >> problem not ours. > It's probably actually using libedit for the history part. [ after further research... ] Mmm, maybe. I can reproduce the misbehavior on a Mac build using libedit. There is a relevant-looking comment in psql's saveHistory function: * On newer versions of libreadline, truncate the history file as * needed and then append what we've added. This avoids overwriting * history from other concurrent sessions (although there are still * race conditions when two sessions exit at about the same time). If * we don't have those functions, fall back to write_history(). A check of the configure output shows that Apple's libedit lacks append_history(), so that the fallback code path is used. The phrasing of this comment suggests that older versions of libreadline might be lacking as well. There's not a lot we can do about this issue when using a libreadline or libedit that lacks the necessary support functions, I think. regards, tom lane