2

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 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.