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.96) (envelope-from ) id 1vl14C-005lDx-2E for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jan 2026 08:38:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vl14B-000XTf-1E for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jan 2026 08:38:23 +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.96) (envelope-from ) id 1vl14A-000XTW-36 for pgsql-hackers@lists.postgresql.org; Wed, 28 Jan 2026 08:38:23 +0000 Received: from mail-dl1-x1229.google.com ([2607:f8b0:4864:20::1229]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vl148-002hvk-0b for pgsql-hackers@lists.postgresql.org; Wed, 28 Jan 2026 08:38:22 +0000 Received: by mail-dl1-x1229.google.com with SMTP id a92af1059eb24-124a1b4dd40so303790c88.0 for ; Wed, 28 Jan 2026 00:38:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769589499; x=1770194299; darn=lists.postgresql.org; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=YgILgCzo9zrlpGbbKiqHtoeaL3cyMZTrkAjq3lsWUSw=; b=kClJmuh/WL5nCF+8hI/JeLIu9h8x2jKA9yx8rxZeon1lZeAIeaV7S9025NSAV2SKO1 e/3DXSSy37RA57L+CgA7tQ5vT3fqh52dyaW4v3iJStIde/A4bg9dQ9OzzM5HrJbuvhKg tqIBMsJ9EPHlFEtLPgGUuTkzoK/Bjjf9fpGcSdIjLNur9SK7X5vPC/SgWzvjAU5y5xlk sSKY+cTXOQ5jrMbdgoof1l5gLPWkXabZyeGPpyeO6lgZI9OPzqPRIMCKT7fLTUUyqcpW 9EWqulBxIprwurodm093g+JAoPURe9pfIaNrPcyvhSjNckXhbQ8ubpSxdr28o1o0QRsC s+QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769589499; x=1770194299; h=to:date:message-id:subject:mime-version:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YgILgCzo9zrlpGbbKiqHtoeaL3cyMZTrkAjq3lsWUSw=; b=mr9b8LTxKdi5m8fkpUKTfESrgGV+gQNjrDxDQrVZvJuvXxjVIogZcAz/QBTLceom01 rifxYvhsu5IBnvWs6kZlkcci5Ent/NBUkohYRGXK/koFRU+xdXMYbWa1iv7eQr/5D4rA I2M91w8Et2qrL9Us9liM7XTyrN9T5jjtSFYW6czZ0ukTEGJWCSfcEg9Qfr4CCi9mPBZs 7I59BhNyvXzlxPHaDEwTzNfahGpEWy5Sk4EN5mLx46YrG3IvugAT01bgwASv24BF1Cuy DsvIOQ2WubDM+yY/oeelGm5gllij39mqlMCjlBZc3I4RBH/ndd7jC4VJNR7VPAi5ND+f Sgqg== X-Gm-Message-State: AOJu0YwA2ys+OHvQple9/tTQaeMcJ8hX1+lG//G1jOvs4cXjdRRbEeIJ 8p5F7Vzj1fvH7DYBxRKfH+CkXqDS6wF+sOwAXi7xpooYWzqoF3Vn/uLWNNEDWw== X-Gm-Gg: AZuq6aLUx4wOWBKNkwGsanx/bkys/SW8IipMDKPMCvDDf3ycnI/9+Qz9XSC9kM+PiDL 0dUPb9E3MNndGnpi9jxjLiJhRLR+jTKDkp+a9STWzkR1yqPhbbI0Vo2Ei0u42acUiyNl1/sznL3 MSz+lNdEIHcf4AgbGMxTceGjwM0Gxe89MwTd/eJpQTKtZma3yifZrnQZjX9xjpSO9SyBwpjw6I1 I6nCz6vC+fdapvq6zohnAXouSNUhQcnHbZ2XUUXhNTQJHr2nmrxK8cmch/kLMdHWPc8ZtNCK19e ClkUx5EML/jLQ4RqtXOZq5l2W42Jhe+wQZmorklJLSlfqu7M+yNfaT8uAsAmS0PRt2PmDWNebeV 4+DMJSPrRUB6StvrUHcBCN2zxYpX+iQ9KxJJwmlopOjbnSCTAjzAVOYl9T+UjLi3/1lXsOfmt3l gSYBuxTdGJBraNsq2oM2SZ X-Received: by 2002:a05:7022:6982:b0:11b:9b9f:426b with SMTP id a92af1059eb24-124a006aa70mr2513397c88.20.1769589498738; Wed, 28 Jan 2026 00:38:18 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a9d7f597sm1504438c88.5.2026.01.28.00.38.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jan 2026 00:38:17 -0800 (PST) From: Chao Li Content-Type: multipart/mixed; boundary="Apple-Mail=_3AA65C7E-006B-42AA-AB33-C90E1AF6811D" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.300.41.1.7\)) Subject: psql: make %P prompt option consistent when not connected Message-Id: <86EF76B5-6E62-404D-B9EC-66F4714D7D5F@gmail.com> Date: Wed, 28 Jan 2026 16:38:08 +0800 To: PostgreSQL Hackers X-Mailer: Apple Mail (2.3864.300.41.1.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_3AA65C7E-006B-42AA-AB33-C90E1AF6811D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi Hackers, While reviewing and testing patch [1], I noticed that psql=E2=80=99s %P = prompt option does not check pset.db, which makes it inconsistent with = other prompt options. As a result, when there is no database connection, = other prompt elements are suppressed, but the pipeline status is still = shown. For example: ``` evantest=3D# \set PROMPT1 '[%P] %R ' [off] =3D \c connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file = or directory Is the server running locally and accepting connections on that = socket? Previous connection kept [off] =3D ; FATAL: terminating connection due to administrator command server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Failed. The connection to the server was lost. Attempting reset: Failed. [off] ! [off] ! ``` To confirm whether this behavior is intentional, I went through the = original discussion for adding %P [2], but didn=E2=80=99t find this case = mentioned, so it seems this detail was simply not considered at the = time. This patch adds a pset.db check to align %P with the other prompt = options, keeping the prompt display consistent when not connected. With = the patch applied, all psql TAP tests pass: ``` # +++ tap check in src/bin/psql +++ t/001_basic.pl ........... ok t/010_tab_completion.pl .. ok t/020_cancel.pl .......... ok t/030_pager.pl ........... ok All tests successful. Files=3D4, Tests=3D221, 5 wallclock secs ( 0.01 usr 0.01 sys + 1.05 = cusr 1.38 csys =3D 2.45 CPU) Result: PASS ``` [1] = https://www.postgresql.org/message-id/flat/016f6738-f9a9-4e98-bb5a-e1e4b95= 91d46@uni-muenster.de [2] = https://www.postgresql.org/message-id/CAO6_XqroE7JuMEm1sWz55rp9fAYX2JwmcP_= 3m_v51vnOFdsLiQ@mail.gmail.com Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_3AA65C7E-006B-42AA-AB33-C90E1AF6811D Content-Disposition: attachment; filename=v1-0001-psql-make-P-prompt-escape-consistent-when-not-con.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-psql-make-P-prompt-escape-consistent-when-not-con.patch" Content-Transfer-Encoding: quoted-printable =46rom=200fa5336d5da7ec7ff2b0dd087a3aac6644979ab9=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Wed,=2028=20Jan=202026=2016:19:47=20+0800=0ASubject:=20[PATCH=20= v1]=20psql:=20make=20%P=20prompt=20escape=20consistent=20when=20not=20= connected=0A=0AThe=20%P=20prompt=20escape=20shows=20the=20current=20= pipeline=20status.=20=20Unlike=20most=0Aother=20prompt=20escapes,=20it=20= was=20evaluated=20even=20when=20psql=20was=20not=20connected=0Ato=20a=20= database.=0A=0AMake=20%P=20behave=20consistently=20with=20the=20other=20= prompt=20options=20by=20only=0Aexpanding=20it=20when=20a=20database=20= connection=20exists.=20=20This=20keeps=20the=20prompt=0Adisplay=20= consistent=20in=20the=20not-connected=20state.=0A=0AAuthor:=20Chao=20Li=20= =0AReviewed-by:=0ADiscussion:=0A---=0A=20= src/bin/psql/prompt.c=20|=204=20++--=0A=201=20file=20changed,=202=20= insertions(+),=202=20deletions(-)=0A=0Adiff=20--git=20= a/src/bin/psql/prompt.c=20b/src/bin/psql/prompt.c=0Aindex=20= 44eae59641e..891cd6374f0=20100644=0A---=20a/src/bin/psql/prompt.c=0A+++=20= b/src/bin/psql/prompt.c=0A@@=20-199,6=20+199,7=20@@=20= get_prompt(promptStatus_t=20status,=20ConditionalStack=20cstack)=0A=20=09= =09=09=09=09break;=0A=20=09=09=09=09=09/*=20pipeline=20status=20*/=0A=20=09= =09=09=09case=20'P':=0A+=09=09=09=09=09if=20(pset.db)=0A=20=09=09=09=09=09= {=0A=20=09=09=09=09=09=09PGpipelineStatus=20status=20=3D=20= PQpipelineStatus(pset.db);=0A=20=0A@@=20-208,9=20+209,8=20@@=20= get_prompt(promptStatus_t=20status,=20ConditionalStack=20cstack)=0A=20=09= =09=09=09=09=09=09strlcpy(buf,=20"abort",=20sizeof(buf));=0A=20=09=09=09=09= =09=09else=0A=20=09=09=09=09=09=09=09strlcpy(buf,=20"off",=20= sizeof(buf));=0A-=09=09=09=09=09=09break;=0A=20=09=09=09=09=09}=0A-=0A+=09= =09=09=09=09break;=0A=20=09=09=09=09case=20'0':=0A=20=09=09=09=09case=20= '1':=0A=20=09=09=09=09case=20'2':=0A--=20=0A2.50.1=20(Apple=20Git-155)=0A= =0A= --Apple-Mail=_3AA65C7E-006B-42AA-AB33-C90E1AF6811D--