3 ms·
Aye. This is getting over my head, so I inquired on the pgsql-general list (which is amazingly helpful). Ian Barwick writes how to put all the prep stuff into
by atsaloli 14y ago
Aye. This is getting over my head, so I inquired on the pgsql-general list (which is amazingly helpful).
Ian Barwick writes how to put all the prep stuff into a psql script, then all you have to do is define your query and invoke the script:
-- start quote --
What you could do is create a small psql script along these lines:
barwick@localhost:~$ cat tmp/plot.psql
\set QUIET yes
\t\a\f ' '
\unset QUIET
\o | /usr/bin/gnuplot
select 'set title "My Graph"; set terminal dumb 78 24; set key off; set ylabel "Time"; set xlabel "Servers";' || 'plot ''-'' with lines;' ;
:plot_query;
\set QUIET yes
\t\a\f
\unset QUIET
\o
barwick@localhost:~$ psql -U postgres testdb
psql (9.2.3)
Type "help" for help.
testdb=# \set plot_query 'SELECT * FROM plot'
testdb=# \i tmp/plot.psql
My Graph
4 ++---------+-----------+----------+----------+-----------+---------**
+ + + + + + **** +
| **** |
3.5 ++ **** ++
| **** |
| **** |
3 ++ **** ++
| **** |
2.5 ++ ***** ++
| **** |
| **** |
2 ++ **** ++
| **** |
| **** |
1.5 ++ **** ++
| **** |
+ **** + + + + + +
1 **---------+-----------+----------+----------+-----------+---------++
1 1.5 2 2.5 3 3.5 4
Servers
testdb=#
-- end quote --
And
Sergey Konoplev explains how to do it with a server-side function - you
need gnuplot installed on the db server -
-- start quote --
plpython/plperl/etc plus this way of calling
select just_for_fun_graph('select ... from ...', 'My Graph', 78, 24, ...)
will do the trick.
-- end quote --