Gpdb Current transaction is aborted

Source: Internet
Author: User

The following error is encountered when working with Python in gpdb

gpmg.manager_tabl1eerror ‘ERROR:  relation "gpmg.manager_tabl1e" does not exist‘ in ‘select pg_total_relation_size(‘gpmg.manager_tabl1e‘);‘gpmg.manager_tableerror ‘ERROR:  current transaction is aborted, commands ignored until end of transaction block‘ in ‘select pg_total_relation_size(‘gpmg.manager_table‘);‘

This is a loop in which the size of the object is collected and the result table is inserted, the reason for this error is that if there are any errors in the gpdb, then the subsequent session error will be caused.

The Python code block is as follows

sql = "select v1,v2,v3 from test order by 2"cur.execute(sql)for ret in cur.fetchall():    v_schemaname = ret[0]    v_tablename = ret[1]    v_tableowner = ret[2]    v_object = v_schemaname + "." + v_tablename    try:        cur.execute("select pg_total_relation_size(‘" + v_object + "‘);")        v_totalsize = cur.fetchone()[0]        cur.execute("insert into gpmg.table_size_info (ctime,schemaname,tablename,tableowner,totalsize) values(%s,%s,%s,%s,%s)", (ctime,v_schemaname,v_tablename,v_tableowner,v_totalsize))    except Exception, e:        print v_object        print e

After the improvements are as follows

try:    for ret in cur.fetchall():        v_schemaname = ret[0]        v_tablename = ret[1]        v_tableowner = ret[2]        v_object = v_schemaname + "." + v_tablename        try:            cur.execute("select pg_total_relation_size(‘" + v_object + "‘);")            v_totalsize = cur.fetchone()[0]            cur.execute("insert into gpmg.table_size_info (ctime,schemaname,tablename,tableowner,totalsize) values(%s,%s,%s,%s,%s)", (ctime,v_schemaname,v_tablename,v_tableowner,v_totalsize))            db.commit()        except Exception, e:            db.commit()            print v_object, ‘--‘, e            continueexcept Exception, e:    pass    finally:    db.commit()    db.close()    os.system(‘rm -rf ‘ + pf)

This is even more perfect.

-eof-

Gpdb Current transaction is aborted

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.