Vertica's vsql.exe returns errorlevel 0 when facing ERROR 3326: Execution time exceeded run time cap

197 Views Asked by At

I am using vsql.exe on an external Vertica database for which I don't have any administrative access. I use some views with simple SELECT+FROM+WHERE queries. These queries 90% of the time work just fine, but some times, randomly, I get this error:

ERROR 3326:  Execution time exceeded run time cap of 00:00:45

The strange thing is that this error can happen way after those 45 seconds, even after 3 minutes. I've been told this is related to having different resource pools, but anyway I don't want to dig into that.

The problem is that when this occurs, vsql.exe returns errorlevel 0 and there is (apparently almost) no way to know this failed.

The output of the query is stored in a csv file. When it succeeds, it ends with (#### rows). But when it fails with this error, it just stops at any point of the csv, and its resulting size is around half of what's expected. This is of course not what you would expect when an error occurs, like no output or an empty one. If there is a connection error or if the query has syntax errors, the errorlevel is not 0, so in those cases it behaves as expected.

I've tried many things, like increasing the timeout or adding -v ON_ERROR_STOP=ON to the vsql.exe parameters, but none of that helped.

I've googled a lot and found many people having this error, but the solutions are mostly related to increasing the timeouts, not related to the errorlevel returned.

Any help will be greatly appreciated.

TL;DR: how can I detect an error 3326 in a batch file like this?

@echo off
vsql.exe -h <hostname> -U <user> -w <pwd> -o output.cs -Ac "SELECT ....;"
echo %errorlevel% is always 0
if errorlevel 1 echo Error!! But this is never displayed.
1

There are 1 best solutions below

4
On

Now that's really unexpected to me. I don't have Windows available just now, but trying on my Mac - at first just triggering a deliberate error:

$ vsql -h zbook -d sbx -U dbadmin -w $VSQL_PASSWORD  -v ON_ERROR_STOP=ON -Ac "select * from foobarfoo"
ERROR 4566:  Relation "foobarfoo" does not exist
$ echo $?
1

With ON_ERROR_STOP set to ON, this should be the behaviour everywhere.

Could you try what I did above through Windows, just with echo %ERRORLEVEL% instead of echo $?, just from the Windows command prompt and not in a batch file?

Next test: I run on resource pool general in my little test database, so I temporarily modify it to a runtime cap of 30 sec, run a silly query that will take over 30 seconds with ON_ERROR_STOP set to ON, collect the value returned by vsql and set the runtime cap of general back to NONE. I also have the %VSQL_* % env variables set so I don't have to repeat them all the time:

rem Windows way to set environment variables for vsql:
set VSQL_HOST=zbook
set VSQL_DATABASE=sbx
set VSQL_USER=dbadmin
set VSQL_PASSWORD=***masked***

Now for the test (backslashes, in Linux/MacOs escape a new line, which enables you to "word wrap" a shell command. Use the caret (^) in Windows for that):

marco ~/1/Vertica/supp $ # set a runtime cap
marco ~/1/Vertica/supp $ vsql -i -c \
"alter resource pool general runtimecap '00:00:30'"
ALTER RESOURCE POOL
Time: First fetch (0 rows): 116.326 ms. All rows formatted: 116.730 ms
marco ~/1/Vertica/supp $ vsql -v ON_ERROR_STOP=ON -iAc \
 "select count(*) from one_million_rows a cross join one_million_rows b" 
ERROR 3326:  Execution time exceeded run time cap of 00:00:30
marco ~/1/Vertica/supp $ # test the return code
marco ~/1/Vertica/supp $ echo $?
1
marco ~/1/Vertica/supp $ # clear the runtime cap
marco ~/1/Vertica/supp $ vsql -i -c \
"alter resource pool general runtimecap NONE  "   
ALTER RESOURCE POOL
Time: First fetch (0 rows): 11.148 ms. All rows formatted: 11.383 ms

So it works in my case. Your line:

if errorlevel 1 echo Error!! But this is never displayed.

... never echoes anything because the previous line, with echo will return 0 to the shell, overriding the previous errorlevel.

Try it command by command on your Windows command prompt, and see what happens. Just echo %errorlevel%, without evaluating it.

And I notice that you are trying to export to CSV format. Then, try this:

  • Format the output unaligned (-A)
  • set the field separator to comma (-F ',')
  • remove the footer '(n rows)' (-P footer)
  • limit the output to 5 rows in the query for test

(I show the output before redirecting to file):

marco ~/1/Vertica/supp $ vsql -A -F ',' -P footer -c "select * from one_million_rows limit 5"
id,id_desc,dob,category,busid,revenue
0,0,1950-01-01,1,====== boss ========,0.000
1,-1,1950-01-02,2,kbv-000001kbv-000001,0.010
2,-2,1950-01-03,3,kbv-000002kbv-000002,0.020
3,-3,1950-01-04,4,kbv-000003kbv-000003,0.030
4,-4,1950-01-05,5,kbv-000004kbv-000004,0.040

Not aligning is much faster than aligning. Then, as you spend most time in the fetching of the rows (that's because you get a timeout in the middle of an output file write process), try fetching more rows at a time than the default 1000. You will need to play with the value, depending on the network settings at your site until you get your best value:

  • -v ROWS_AT_A_TIME=10000

Once you're happy with the tested output, try this command (change the SELECT for your needs, of course ....):

marco ~/1/Vertica/supp $ vsql -A -F ',' -P footer \ 
-v ON_ERROR_STOP=ON -v ROWS_AT_A_TIME=10000 -o one_million_rows.csv  \
-c "select * from one_million_rows"         
marco ~/1/Vertica/supp $ wc -l one_million_rows.csv 
 1000001 one_million_rows.csv

The table actually contains one million rows. Note the line count in the file: 1,000,001. That's the title line included, but the footer (1000000 rows) removed.