GPDB current transaction is aborted

在用Python操作GPDB的时候遇到报错如下

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

这个在一个循环当中,收集对象大小并插入结果表,出现这个错误的原因是因为在GPDB中如果有出现任何错误,将导致后续的会话报错。

Python代码块如下

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_ta
bleowner,v_totalsize))
    except Exception, e:
        print v_object
        print e

改进之后如下

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
            continue
except Exception, e:
    pass
finally:
    db.commit()
    db.close()
    os.system(‘rm -rf ‘ + pf)

这样就算比较完美咯。

-EOF-

时间: 2024-11-06 09:42:30

GPDB current transaction is aborted的相关文章

Rails 中的事物处理

1. 使用事物的原因 保证数据一致性, 当其中出现一个失败的时候,操作可以回滚 比如: ActiveRecord::Base.transaction do david.withdrawal(100) # withdrawal失败必须触发 exception mary.deposit(100) # deposit失败必须触发 exception end return false 不会出发操作回滚, 所以事物中要使用!的方法, 比如 save! update! before_save 等callba

PostgreSQL数据库中的常见错误

转载以作参考. 错误1 FATAL: connection limit exceeded for non-superusers 原因:非超级用户的连接数(max_connections - superuser_reserved_connections)超过了设定值 解决办法:增加max_connections设定值,但如果增加了过多的话,数据库负担太大还容易产生内存错误.可以记住pg-pool等工具来辅助解决. 错误2 FATAL: sorry, too many clients already

postgresql 关闭自动提交

1. 简介说明 我们知道oracle中sqlplus里面执行dml语句:是需要提交commit:若错了:也可以回滚rollback: 然而在postgresql里面默认是自动提交:执行完就马上提交了,不能回滚,这样容易导致误操作的发生,有没有什么办法避免这个风险呢?当然有,在psql中默认是打开自动提交的,我们可以关闭自动提交. 2. 操作验证 [[email protected] ~]$ psql -U lottu -d xzfb psql (9.5.0) Type "help" f

druid连接池使用过程遇到的一个奇怪异常

某天日志中连续都是如下的异常: 2017-09-06 21:39:52.936 ERROR [DruidDataSource.java:1974] create connection holder error org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block at org.postgresql.core.

Flink kafka producer with transaction support

Background In flink 1.5 above, it provides a new kafka producer implementation: FlinkKafkaProducer011, aligning with kafka 0.11 above that supports transaction. Kafka transaction allows multiple kafka messages sent by producer to deliver in an atomic

sqlserver 存储过程 try catch TRANSACTION (转)

CREATE PROCEDURE YourProcedure    ASBEGIN    SET NOCOUNT ON; BEGIN TRY---------------------开始捕捉异常       BEIN TRAN------------------开始事务        UPDATE A SET A.names = B.names FROM 表1 AS A INNER JOIN 表2 AS B ON A.id = B.id UPDATE A SET A.names = B.name

spring Transaction Management --官方

原文链接:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html 12. Transaction Management 12.1 Introduction to Spring Framework transaction management Comprehensive transaction support is among the most compelling rea

Spring Transaction + MyBatis SqlSession事务管理机制研究学习

线上的系统中,使用的是Spring+Mybatis+Mysql搭建的框架,由于客户需要,最近一直在对性能提升部分进行考虑,主要是涉及Mysql的一些重要参数的配置学习,以及Spring事务管理机制的学习,因为通过观察服务器日志,发现在这两部分的时候耗时比较严重,特别是进行mysql事务提交的时候,项目源码中使用了Spring的声明式事务,即通过@Transactional注解来控制事务的开启与提交,这两天看了一些关于Spring Transaction事务的一些文章,也debug了源码,总算有点

START TRANSACTION, COMMIT, and ROLLBACK Syntax-from cyber

START TRANSACTION [WITH CONSISTENT SNAPSHOT] BEGIN [WORK] COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE] ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE] SET autocommit = {0 | 1} These statements provide control over use of transactions: START TRANSACT