View operation timestamps for long running operations in PSQL console
There are various options for retrieving timing information while using psql.


The \timing command.
In scripts you can use


\echo `date`


to insert the date in the output.


You can have the date in prompt strings using eg


\set PROMPT1 = '%`date` %n@%m:%/%R%# '


For both 2 and 3 you can supply arguments to date to get the date in the format you want.


If using psql non-interactively, you can pipe the output through ts (from moreutils) or through awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'(GNU's version of awk is needed) to prepend a timestamp to each line of output.