pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
psql --echo-queries does not echo all queries
3+ messages / 2 participants
[nested] [flat]

* psql --echo-queries does not echo all queries
@ 2025-10-24 18:16 Gavin Wahl <gavinwahl@gmail.com>
  2025-10-25 14:32 ` Re: psql --echo-queries does not echo all queries Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Gavin Wahl @ 2025-10-24 18:16 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

The -e/--echo-queries psql option is documented to "Copy all SQL
commands sent to the server to standard output as well." However, it
does not show queries sent to the server by -1/--single-transaction or
by ON_ERROR_ROLLBACK.

For example:

$ psql -e  -1 -c 'SELECT 1'
SELECT 1
 ?column?
----------
        1
(1 row)

While the server log reports:
2025-10-24 12:01:57.937 MDT [1970796] LOG:  duration: 0.035 ms  statement: BEGIN
2025-10-24 12:01:57.937 MDT [1970796] LOG:  duration: 0.085 ms
statement: SELECT 1
2025-10-24 12:01:57.937 MDT [1970796] LOG:  duration: 0.004 ms
statement: COMMIT

The BEGIN/END are not reported by psql.


$ psql -e -v ON_ERROR_ROLLBACK=on
psql (16.9)
Type "help" for help.

# BEGIN;
BEGIN;
BEGIN
# SELECT 1;
SELECT 1;
 ?column?
----------
        1
(1 row)

While the server log reports:
2025-10-24 12:12:21.517 MDT [1974726] LOG:  duration: 0.077 ms
statement: BEGIN;
2025-10-24 12:12:25.757 MDT [1974726] LOG:  duration: 0.048 ms
statement: SAVEPOINT pg_psql_temporary_savepoint
2025-10-24 12:12:25.757 MDT [1974726] LOG:  duration: 0.156 ms
statement: SELECT 1;
2025-10-24 12:12:25.757 MDT [1974726] LOG:  duration: 0.012 ms
statement: RELEASE pg_psql_temporary_savepoint

The savepoints are not reported by psql.





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: psql --echo-queries does not echo all queries
  2025-10-24 18:16 psql --echo-queries does not echo all queries Gavin Wahl <gavinwahl@gmail.com>
@ 2025-10-25 14:32 ` Tom Lane <tgl@sss.pgh.pa.us>
  2025-10-27 22:24   ` Re: psql --echo-queries does not echo all queries Gavin Wahl <gavinwahl@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2025-10-25 14:32 UTC (permalink / raw)
  To: Gavin Wahl <gavinwahl@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org

Gavin Wahl <gavinwahl@gmail.com> writes:
> The -e/--echo-queries psql option is documented to "Copy all SQL
> commands sent to the server to standard output as well." However, it
> does not show queries sent to the server by -1/--single-transaction or
> by ON_ERROR_ROLLBACK.

Did you try

  -E, --echo-hidden        display queries that internal commands generate

?

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: psql --echo-queries does not echo all queries
  2025-10-24 18:16 psql --echo-queries does not echo all queries Gavin Wahl <gavinwahl@gmail.com>
  2025-10-25 14:32 ` Re: psql --echo-queries does not echo all queries Tom Lane <tgl@sss.pgh.pa.us>
@ 2025-10-27 22:24   ` Gavin Wahl <gavinwahl@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Gavin Wahl @ 2025-10-27 22:24 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs@lists.postgresql.org

I tried with -E and it does echo the BEGIN/END used to implement
-1/--single-transaction, but not the SAVEPOINT queries for
ON_ERROR_ROLLBACK.  It looks like SendQuery is calling PQexec directly
instead of calling the PSQLexec wrapper function that does the
logging. I happened to notice that the queries emitted by \watch, nor
the BEGIN for autocommit, aren't logged by either option as well.

I think this may be a documentation bug as well? I would expect -e to
be a superset of -E:

 -E
 --echo-hidden
     Echo the actual queries generated by \d and other backslash commands.

 -e
 --echo-queries
     Copy *ALL* [emphasis mine] SQL commands sent to the server to
standard output as well





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2025-10-27 22:24 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-10-24 18:16 psql --echo-queries does not echo all queries Gavin Wahl <gavinwahl@gmail.com>
2025-10-25 14:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-10-27 22:24   ` Gavin Wahl <gavinwahl@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox