ifexception.message.include?('canceling statement due to statement timeout')
# Check if the table has any lock
lock=user.in_database(as::superuser).fetch(%Q{
SELECTpid,state,usename,query,query_start
# Check if the table has any lock and cancel locking queries
locks=user.in_database(as::superuser).fetch(%Q{
SELECTpid, query
FROMpg_stat_activity
WHEREpidin(
SELECTpidFROMpg_locksl
@ -404,8 +404,14 @@ module CartoDB
ANDt.relkind='r'
WHEREt.relnameIN('#{table_name}')
);
}).first
@logger.append_and_store"Transaction timed out as the table is blocked by query #{lock[:query]}. Retrying in 60 seconds..."if@logger&&lock.present?
}).all
@logger.append_and_store"Transaction timed out as the table is blocked by other queries. Terminating locking queries and retrying in 60 seconds..."if@logger&&locks.present?