运行命令时:
psql -h localhost -p 5432 -U meee -d my_db -f sqltest.sql
它显示:
CREATE VIEW ALTER TABLE
但是,我希望它像pgadmin显示它一样显示给我(例如:查询在45毫秒内成功执行,但未返回任何结果)
dxxyhpgq1#
在sqltest.sql的开头添加命令\timing,您将看到每个命令的时间例如script.sql:\timing select 2 ; select 1; create table tablax(i int);或者,如果您需要从脚本开始到结束的所有时间,请在脚本开始处添加一些命令:create temp table tab (time1 time,time2 time); insert into tab (time1) select now()::time;结束时:update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;例如:
\timing select 2 ; select 1; create table tablax(i int);
create temp table tab (time1 time,time2 time); insert into tab (time1) select now()::time;
update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;
create temp table tab (time1 time,time2 time);
insert into tab (time1) select now()::time;...您的脚本代码... update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;
insert into tab (time1) select now()::time;
zaqlnxep2#
使用a psql命令参数:
a
psql -h localhost -p 5432 -U meee -d my_db -af sqltest.sql
https://www.postgresql.org/docs/current/static/app-psql.html并将\timing on放在脚本的顶部
\timing on
2条答案
按热度按时间dxxyhpgq1#
在sqltest.sql的开头添加命令\timing,您将看到每个命令的时间
例如script.sql:
\timing select 2 ; select 1; create table tablax(i int);
或者,如果您需要从脚本开始到结束的所有时间,请在脚本开始处添加一些命令:
create temp table tab (time1 time,time2 time); insert into tab (time1) select now()::time;
结束时:
update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;
例如:
insert into tab (time1) select now()::time;
...您的脚本代码
...
update tab set time2=now()::time; select time2-time1 as time_Elapsed from tab;
zaqlnxep2#
使用
a
psql命令参数:https://www.postgresql.org/docs/current/static/app-psql.html
并将
\timing on
放在脚本的顶部