Issue
When I attempt to execute a PostgreSQL command through a script, the \timing setting is automatically turned on during query execution. This timing information is interfering with my ability to respond appropriately to the query's output, as it affects the timing of my interruptions or actions.
Below is the output I got from the script: result: Timing is on. t Time: 0.381 ms
In my output, I am checking whether a node is in recovery mode, and I'm storing the result in a variable. While the result is correct (true), the variable contains additional timing information that I didn't expect. I'm unsure why this is happening, and I'm curious if there are default settings that are affecting the output by including timing information each time I query the database.
Solution
The timing details for each query that is run when the \timing command is enabled are by default displayed by psql. So the issue which you are facing is due to this default behavior of psql. So if you want to control or suppress the timing information you can try these three cases depending upon your need.
Turn Off Timing for a Single Query in psql
\timing off
SELECT * FROM your_table;
Turn Off Timing for the whole psql Session
psql -q -U your_username -d your_database
The psql runtime configuration (psqlrc) file can be set up to disable timing information by default. In your user's home directory, create or update the ~/.psqlrc file, and add the following line:
\timing off
Hope it works :)
Answered By - Maimoona Abid Answer Checked By - Katrina (WPSolving Volunteer)