PostgreSQL事务隔离级别4不支持 [英] postgresql Transaction isolation level 4 not supported

查看:638
本文介绍了PostgreSQL事务隔离级别4不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建表(postgres +公开的+ ktor + JDBC),但出现了此错误。

I am Trying to create table (postgres + exposed + ktor + JDBC), I got that error.

在下面找到我拥有的配置:

Find bellow the configuration I have:

build.gradle

compile group: 'postgresql', name: 'postgresql', version: '9.0-801.jdbc4'

您好.kt

object Pays : Table() {
val id = integer("id").autoIncrement().primaryKey() // Column
val name = varchar("name", 50) // Column
}

fun main(args: Array) {
Database.connect("jdbc:postgresql://localhost/my_db", driver = "org.postgresql.Driver", user = "user", password = "password")

这里是我所犯的错误

Caused by: org.postgresql.util.PSQLException: Transaction isolation level 4 not supported.
at org.postgresql.jdbc2.AbstractJdbc2Connection.setTransactionIsolation(AbstractJdbc2Connection.java:826)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction$connectionLazy$1.invoke(ThreadLocalTransactionManager.kt:25)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction$connectionLazy$1.invoke(ThreadLocalTransactionManager.kt:20)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:154)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManager$ThreadLocalTransaction.getConnection(ThreadLocalTransactionManager.kt:29)
at org.jetbrains.exposed.sql.Transaction.getConnection(Transaction.kt)
at org.jetbrains.exposed.sql.Database.getMetadata$exposed(Database.kt:17)
at org.jetbrains.exposed.sql.Database$url$2.invoke(Database.kt:26)
at org.jetbrains.exposed.sql.Database$url$2.invoke(Database.kt:15)
at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:131)
at org.jetbrains.exposed.sql.Database.getUrl(Database.kt)
at org.jetbrains.exposed.sql.Database$dialect$2.invoke(Database.kt:29)
at org.jetbrains.exposed.sql.Database$dialect$2.invoke(Database.kt:15)
at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:131)
at org.jetbrains.exposed.sql.Database.getDialect$exposed(Database.kt)
at org.jetbrains.exposed.sql.vendors.DefaultKt.getCurrentDialect(Default.kt:319)
at org.jetbrains.exposed.sql.vendors.DefaultKt.getCurrentDialectIfAvailable(Default.kt:323)
at org.jetbrains.exposed.sql.Column.getOnDelete$exposed(Column.kt:14)


推荐答案

阅读JDBC驱动程序9.0版的源代码,我会看到:

Reading the source of the JDBC driver version 9.0, I see:

/*
 * You can call this method to try to change the transaction
 * isolation level using one of the TRANSACTION_* values.
 *
 * <B>Note:</B> setTransactionIsolation cannot be called while
 * in the middle of a transaction
 *
 * @param level one of the TRANSACTION_* isolation values with
 * the exception of TRANSACTION_NONE; some databases may
 * not support other values
 * @exception SQLException if a database access error occurs
 * @see java.sql.DatabaseMetaData#supportsTransactionIsolationLevel
 */
public void setTransactionIsolation(int level) throws SQLException
{
    checkClosed();

    if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
        throw new PSQLException(GT.tr("Cannot change transaction isolation level in the middle of a transaction."),
                                PSQLState.ACTIVE_SQL_TRANSACTION);

    String isolationLevelName = getIsolationLevelName(level);
    if (isolationLevelName == null)
        throw new PSQLException(GT.tr("Transaction isolation level {0} not supported.", new Integer(level)), PSQLState.NOT_IMPLEMENTED);

    String isolationLevelSQL = "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL " + isolationLevelName;
    execSQLUpdate(isolationLevelSQL); // nb: no BEGIN triggered
}

getIsolationLevelName 的定义如下:

protected String getIsolationLevelName(int level)
{
    boolean pg80 = haveMinimumServerVersion("8.0");

    if (level == Connection.TRANSACTION_READ_COMMITTED)
    {
        return "READ COMMITTED";
    }
    else if (level == Connection.TRANSACTION_SERIALIZABLE)
    {
        return "SERIALIZABLE";
    }
    else if (pg80 && level == Connection.TRANSACTION_READ_UNCOMMITTED)
    {
        return "READ UNCOMMITTED";
    }
    else if (pg80 && level == Connection.TRANSACTION_REPEATABLE_READ)
    {
        return "REPEATABLE READ";
    }

    return null;
}

java.sql.Connection.TRANSACTION_REPEATABLE_READ 是4 ,您的错误消息只能表示 pg80 false

因此,唯一的解释是您实际上正在使用早于8.0的PostgreSQL服务器版本,或者更有可能是您正在使用PostgreSQL v10,并且JDBC驱动程序太旧而无法理解新的二位数版本编号系统。

So the only explanations are that you are actually using a PostgreSQL server version older than 8.0 or, more likely, that you are using PostgreSQL v10 and the JDBC driver is too old to understand the new two-number version numbering system.

在第一种情况下,应升级PostgreSQL,但无论如何,都应使用最新版本的JDBC驱动程序。那应该解决您的问题。

In the first case, you should upgrade PostgreSQL, but in any event, you should use a current version of the JDBC driver. That should take care of your problem.

这篇关于PostgreSQL事务隔离级别4不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆