11

I am creating a PostgreSQL database from the command line (i.e. using psql).

There are some errors in my SQL statements and I want to find out where the errors are occuring (too many objects to fill the screen buffer - so I need to save thios to file)

I have tried just about everything, from using the -o option, the -L option and using tee - I still cant capture the information that scrolls past on the screen.

How do I log this?

This is what I have tried so far:

  • psql -U -o dbcreate.log -f file.sql
  • psql -U -L dbcreate.log -f file.sql
  • psql -U -a -f file.sql | tee dbcreate.log

NONE of which results in the data flashing accross the screen being logged to file - how do I do this?

2
  • Have you tried pg_dump? cyberciti.biz/tips/tag/pg-dump-command Commented Dec 16, 2010 at 10:34
  • -U is for specifying a username, what purpose does it serve on your command line? Commented Dec 16, 2010 at 11:52

1 Answer 1

16

You need to redirect stderr. On Un*x and Linux:

psql ... 2>error.log

or both stdout and stderr:

psql ... &>error.log

On the other hand if you like to investigate the errors one by one:

psql -v ON_ERROR_STOP=1 ...

A helpful article about executing SQL scripts with psql - here.

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

Looks like just what I need. Regarding your other question (-U option on the command line) - Is there a way where I can run these command (say from a bash script), totally automated - i.e. without it prompting me for a password?
Actually, I saw that in the postgre docs (before I asked you). problem is I can't find any example of how to use it. Unless 'using it' simply involves entering details of the user in the .pgpass file?

Your Answer

Draft saved
Draft discarded

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.