Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t57MI-0047aw-OA for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Oct 2024 17:47:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t57MH-000DDA-1N for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Oct 2024 17:47:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t57MF-000DCc-L3 for pgsql-hackers@lists.postgresql.org; Sun, 27 Oct 2024 17:47:21 +0000 Received: from relay3-d.mail.gandi.net ([2001:4b98:dc4:8::223]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t57MC-0038xu-L3 for pgsql-hackers@lists.postgresql.org; Sun, 27 Oct 2024 17:47:18 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 483C160003 for ; Sun, 27 Oct 2024 17:47:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1730051232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Rmt7LxRhthsMRznZDeIqgArdS0FCSXI5UISdDQqrklA=; b=KX1+O8yHpQks9b6zC2VO1SyJfocgH0ESrosd1ZEy0sgYlYNMIxzGyE/rEvcc20N8cl48uC b6K0d/3x2FoWKTapOEbKpuh8XQ/B/Wn7BA7gvzbZq0H7BIZFEK61dztqDn1F3y4Z2CNIb7 EfB8763GAgDO1ytQmLrFOB+aUff158j5QiYU+SPgT5X/AGe4svRlEhfwodsvgBMQtgd+TB YpILAj2tMD7WpKZsR2EGPDkFXTvPfQDU8SDwPpC35lmeeOrsvfxjk1+igMh6bmH3pzc9Ak 1Havro3GZBPxzgA+0p2LlrMktjpl8YUdEtkPENVQlpUypY5Lk5KB3mKakE1b8w== Message-ID: <665e2b50-8969-42e1-b691-aabb9ea5ada5@vondra.me> Date: Sun, 27 Oct 2024 18:47:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: pgsql-hackers@lists.postgresql.org Content-Language: en-US From: Tomas Vondra Subject: libedit history seems to be misbehaving / broken Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I accidentally built master with libedit (instead of the readline I use most of the time, due to missing readline-devel package). And for a while it was working fine, but then I realized the history is not working anymore, and is broken in a weird way :-( I'm not terribly familiar with libedit, so can't say if it's a bug in libedit, or if we're just using it wrong in some way. I investigated that while on a flight from pgconf.eu, but can't look into this further. So let me at least share the behavior I observed, and what I found. Note: All of this is with libedit-3.1-53.20240808cvs.fc40.x86_64, which is what I currently get in Fedora 40. Initially, history seems to work - more or less. Except for the detail that we always "repeat" the last command from the history. So if you do "SELECT 1" then the first query added to the history by the *next* psql session is going to be "SELECT 1". And this happens even if you don't do anything in psql. So if you enter & immediately exit 10x, you get 10 copies of the last query. Which is rather weird, and it also makes it less convenient to walk the history (ctrl-r search is fine, ofc). But there comes the following issue. Libedit identifies the history file by adding _HiStOrY_V2_ as the first line. But it also limits the history to 500 lines, and after adding the 501st line, it gets confused, attempts to enforce the 500-line limit, and removes the first line, which is the _HiStOrY_V2_ header. At which point the history stops to work, more or less - psql can't access the history, apparently due the header missing. We still append new entries at the end, can access earlier commands from the same session, but nothing from the file. And it stays broken forever, of course :-( regards -- Tomas Vondra