Обсуждение: Fwd: Psql.exe error logging
<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">Hi,<br /></div><div class="gmail_quote"><divdir="ltr"><div style="font-family:tahoma,sans-serif"><br /></div><div style="font-family:tahoma,sans-serif">Iam running a .sql file using psql.exe command. The command inserts data from a fileinto a table as is, no checks.</div><div style="font-family:tahoma,sans-serif"><br /></div><div style="font-family:tahoma,sans-serif">ProblemI am facing is when even if the command gives me an error, still it completessuccessfully. I am running this command via java, so am not able to catch the error.</div><div style="font-family:tahoma,sans-serif"><br/></div><div style="font-family:tahoma,sans-serif">It would be of great help ifyou could rescue me from this situation.</div><div style="font-family:tahoma,sans-serif"><br /></div><div style="font-family:tahoma,sans-serif">Ihave attached a screenshot also.</div><div style="font-family:tahoma,sans-serif"><br/></div><div style="font-family:tahoma,sans-serif"><div style="display:inline-block"></div><imgalt="Inline image 2" height="39" src="cid:ii_153171878d810a00" width="454" /><br /></div><divstyle="font-family:tahoma,sans-serif"><br /></div><div style="font-family:tahoma,sans-serif">Thanks,</div><divstyle="font-family:tahoma,sans-serif">Aman</div></div></div><br /></div>
Hi,I am running a .sql file using psql.exe command. The command inserts data from a file into a table as is, no checks.Problem I am facing is when even if the command gives me an error, still it completes successfully. I am running this command via java, so am not able to catch the error.It would be of great help if you could rescue me from this situation.
psql --set=ON_ERROR_STOP=1
David J.
Hi David,Thanks for the reply, but it still doesn't seem to run.I followed the following steps:1) updated the on_error_stop value to 1
2) Ran a command that should fail and exit
Any particular reason you didn't just add the --set option from #1 to the psql command in #2?
David J.
Вложения
Hi David,Thanks for the reply, but it still doesn't seem to run.I followed the following steps:1) updated the on_error_stop value to 12) Ran a command that should fail and exitAny particular reason you didn't just add the --set option from #1 to the psql command in #2?
As an aside, the portion of the command "psql -c -a -f <file>" is wrong (though apparently not broken...). You specify, via "c", that you are going to provide a single command for psql to execute but then fail to provide any such command and instead change you mind and tell it your are going to provide a script file, via "f", instead.
David J.
Вложения
Hi David,
Thanks for the reply, but it still doesn't seem to run.
I followed the following steps:
1) updated the on_error_stop value to 1
![Inline image 1](/media/maillist_attaches/pgsql-www/2016/02/26/CAOrOm8X4LHm=AibDqWaO0HsgE9V+gsOeOpUVOYQpR8nCWmPtEQ@mail.gmail.com/image.png)
2) Ran a command that should fail and exit
![Inline image 1](/media/maillist_attaches/pgsql-www/2016/02/26/CAOrOm8X4LHm=AibDqWaO0HsgE9V+gsOeOpUVOYQpR8nCWmPtEQ@mail.gmail.com/image-1.png)
3) Checked my java log and it shows it ran without errors and continued with the program.
Right now I have been able to write the error into a log file and then read it to check if there was any error, but that doesn't seem to be a very optimized way of handling psql error.
Request you if you could provide me some more tips on how to handle it.
Thanks,
Aman
On Thu, Feb 25, 2016 at 10:03 PM, David G. Johnston <david.g.johnston@gmail.com> wrote:
Hi,I am running a .sql file using psql.exe command. The command inserts data from a file into a table as is, no checks.Problem I am facing is when even if the command gives me an error, still it completes successfully. I am running this command via java, so am not able to catch the error.It would be of great help if you could rescue me from this situation.psql --set=ON_ERROR_STOP=1David J.
Вложения
On Fri, Feb 26, 2016 at 10:21 AM, David G. Johnston <david.g.johnston@gmail.com> wrote:
Hi David,Thanks for the reply, but it still doesn't seem to run.I followed the following steps:1) updated the on_error_stop value to 12) Ran a command that should fail and exitAny particular reason you didn't just add the --set option from #1 to the psql command in #2?As an aside, the portion of the command "psql -c -a -f <file>" is wrong (though apparently not broken...). You specify, via "c", that you are going to provide a single command for psql to execute but then fail to provide any such command and instead change you mind and tell it your are going to provide a script file, via "f", instead.David J.
>3) Checked my java log and it shows it ran without errors and continued with the program.
Do you realize that all psql errors will go to the postgresql log file, not java log?
Melvin Davidson
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.![](http://us.i1.yimg.com/us.yimg.com/i/mesg/tsmileys2/01.gif)
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.
![](http://us.i1.yimg.com/us.yimg.com/i/mesg/tsmileys2/01.gif)
Вложения
On Monday, February 29, 2016, Aman Rathi <aman.rathi0904@gmail.com> wrote:
Hi David,1) I thought that --set command is meant at DB level for all the commands being run. So ran it first. Not sure how to use it within the command.
everyone else is bottom posting. Please do the same.
On the point above: everytime you execute psql you connect to the database using a clean session. Nothing carries over between sessions. So while --set alters the session you have to make you specify it on the psql invocation you actually want to have stop on errors.
David J.
On 29 February 2016 at 15:24, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Monday, February 29, 2016, Aman Rathi <aman.rathi0904@gmail.com> wrote:Hi David,1) I thought that --set command is meant at DB level for all the commands being run. So ran it first. Not sure how to use it within the command.everyone else is bottom posting. Please do the same.
Also, this is on the pgsql-www mailing list. Shouldn't it really be on -general?
'psql' could really use a flag that was shorthand for -v ON_ERROR_STOP=1 since it's an obvious and desirable thing that's horrid to specify and not quite as easy to discover as it could be.
Hi David,
1) I thought that --set command is meant at DB level for all the commands being run. So ran it first. Not sure how to use it within the command.
2) -c option: I was doing something but forgot to remove it and didn't notice that it is still there. Now, if I run it with -c option, then also I am facing the same issue.
3) I realize that the psql.log is different from java log. Reason for creating this log is to read the error message from the file since command exists successfully and not with some errors. %errorlevel% is 0 even if the command fails, therefore my java does not stop. So i use this log file to read if there is any error record else continue.
Now, I am facing one more issue: The creation of the log file command sometimes creates a log file and sometimes doesn't ( through java). Wanted to check if there is something I should keep in mind for this.? Command I am running is:
"<path_to_exe>psql.exe" -U <value>-w -h <value>-d <value> -a -f "<path to .sql file>copy_s_m_asset_391.sql" 2> ",log_file_path>psql.log"
Thanks a lot for you help on this. Really appreciate it.
Aman
On Fri, Feb 26, 2016 at 9:29 PM, Melvin Davidson <melvin6925@gmail.com> wrote:
On Fri, Feb 26, 2016 at 10:21 AM, David G. Johnston <david.g.johnston@gmail.com> wrote:Hi David,Thanks for the reply, but it still doesn't seem to run.I followed the following steps:1) updated the on_error_stop value to 12) Ran a command that should fail and exitAny particular reason you didn't just add the --set option from #1 to the psql command in #2?As an aside, the portion of the command "psql -c -a -f <file>" is wrong (though apparently not broken...). You specify, via "c", that you are going to provide a single command for psql to execute but then fail to provide any such command and instead change you mind and tell it your are going to provide a script file, via "f", instead.David J.>3) Checked my java log and it shows it ran without errors and continued with the program.Do you realize that all psql errors will go to the postgresql log file, not java log?--Melvin Davidson
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.