I am working with PostgreSQL 9 in windows (pgAdmin3) and I'm trying to execute distinct EXPLAIN ANAlYZE command on each of 5 queries that are really time consumming, and send the results to a single file. can anybody help me to solve this please? thanks
1 Answer
This is probably better done with the psql command-line utility, not with pgadminIII. You can create a file with all the psql commands you need, kind of like this.
$ cat test.psql
\o test.txt
\qecho First query
explain analyze select * from narrow;
\qecho Second query
explain analyze select * from person;
\q
\o tells psql to send all query output to the file test.txt. \qecho is just for documentation; it writes any string you like to the output file.
On my machine, I'd run that file (test.psql) like this.
$ psql -h localhost -p 5433 -U postgres sandbox < test.psql
That just tells psql that the server is on my computer, it's listening on port 5433, I want to connect to the database "sandbox" as the user "postgres", and read all the commands from test.psql. Output for all the queries will be in the file test.txt.