Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redshift VACUUM cannot run inside a transaction block on SQLWorkbenchJ

I have got a:

VACUUM cannot run inside a transaction block

error on SQLWorkbenchJ in Redshift, but I already commit all transactions before this.

like image 603
Ting Jia Avatar asked Nov 30 '15 08:11

Ting Jia


3 Answers

For me this worked.

END TRANSACTION;
VACCUM <TABLENAME>;
like image 62
user 923227 Avatar answered Oct 13 '22 05:10

user 923227


You don't need to change the connection profile, you can change the autocommit property inside your SQL script "on-the-fly" with set autocommit

set autocommit on;
vacuum;
set autocommit off;

You can also toggle the current autocommit state through the menu "SQL -> Autocommit"

like image 25
a_horse_with_no_name Avatar answered Oct 13 '22 06:10

a_horse_with_no_name


turning autocommit on and off seems like a hacky solution particularly if you have a long script punctuated with commits and vacuums (ie lots of very large temp tables). Instead, try (in one line). Also, many are reporting redshift does not like the syntax. Instead,

COMMIT;VACUUM;COMMIT;

The problem is that vacuum not only wants to be the first command in a transaction block, it wants the block to be explicitly committed after.

like image 10
Chris.Caldwell Avatar answered Oct 13 '22 06:10

Chris.Caldwell