1

I have a large batch of of comprising over 300000 insert commands in PostgreSQL. I can not even load it into pgAdmin (it crashes). so I am using the command line and \i to execute the file. I'd like to see the error messages (if any). How may I save the messages into a log file through command line? appreciate your help thank you

Edit I have already seen some other posts but couldn't help.

6
  • 300000 insert commands? Wouldn't it be easier to read the data from a file? Commented Apr 9, 2012 at 9:39
  • @wildplasser :) I have just converted an XML file into insert commands to populate a DB. that is what the employer requires: a database! "read the data from a file"? are you suggesting another solution to get it done? please help. thank you Commented Apr 9, 2012 at 9:43
  • 1
    If the XML consists if only one (or a few) rectangular data-tables, it could be transformed to .csv (or .tsv) files relatively easy. (easier than converting it into insert statements, IMHO) Commented Apr 9, 2012 at 9:46
  • I had already considered CSV, but ,actually I couldn't do that. However, it is still important for me if it is possible. So, what to you mean by rectangular data-tables? if you mean not hierarchichal, No, the data is hierarchical(nested). Still possible? what are the tools? thanks Commented Apr 9, 2012 at 9:50
  • I meant rectangular in the sense of (a collection of) rows*columns data. Just plain table data. If you mean hierarchical in the sense of "denormalised" you would be in trouble. If you only mean (FK) relations between tables, it's Ok. Commented Apr 9, 2012 at 9:58

2 Answers 2

2

From the unix-prompt: (windows may have a similar mechanism).

psql -U my_username my_databasename < the_script.sql >the_output.log

UPDATE: The above command assumes that the user that executes it is able to read "the_script.sql" and that the user can write to "the_output.log" (in this case in the current directory) If you can't write there for some reason, you could always write to /tmp, as in psql -U my_username my_databasename < the_script.sql >/tmp/other_output.log

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

8 Comments

I am logged in with my own account(vahid) and database owner is postgres. so the command looks like this: vahid@vahid-ThinkPad-T420:~/workspace/MATSIM$ psql -U postgres MATEST < testing.sql > ./res.txt psql: FATAL: Peer authentication failed for user "postgres"
doing a sudo didn't change anything
changing the output file owner(and middle directories) to postgres also yields another problem:$ psql -U postgres MATEST < testing.sql > /sqlresult/res.txt bash: /sqlresult/res.txt: Permission denied Any Idea? thanks
changing chmod the permission of output file sudo chmod 777 /sqlresult/res.txt gets me back to the original problem: FATAL: Peer authentication failed for user "postgres"
Pleas update your question, and show us exactly which command(s) you used. "doing a sudo didn't change anything" is not very informative.
|
0
psql -e -f file_name db_name 2>&1 > log.txt

most of the interesting logs you will find are sent to stderr from psql, so redirecting stderr to stdout and then put them in a log.txt file should work.

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.