문제

Java 내에서 다음 SQL 명령을 실행하여 Postgres 데이터베이스를 청소하려고합니다.

진공 장황 분석

때로는 프로세스를 중단하는 깨끗한 방법이 있습니까? 나는 시도했다

Steption_timeout을 xxxx로 설정하십시오

그러나 "진공은 트랜잭션 블록 내부에서 실행할 수 없습니다"오류 메시지가 표시됩니다.

도움이 되었습니까?

해결책

방금 테스트했고 "진공"은 "Statement_Timeout"을 존중합니다. 예제 프로그램 :

import java.sql.*;

class test
{
        public static void main(String[] args) {
                try {
                        Class.forName("org.postgresql.Driver");
                        Connection connection =
                                DriverManager.getConnection(
                                        "jdbc:postgresql://hostname/dbname",
                                        "username",
                                        "password"
                                );
                        connection.createStatement().executeUpdate(
                                "set statement_timeout to 500"
                        );
                        connection.createStatement().executeUpdate(
                                "vacuum analyze"
                        ); 
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
        }
}

다음 오류가 발생합니다.

org.postgresql.util.PSQLException: ERROR: canceling statement due to statement timeout
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:353)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:299)
    at test.main(test.java:14)

어쩌면 연결에 자동 커밋을 활성화해야 할 수도 있습니다.

다른 팁

Postgres 서버가 데이터를로드하는 데 너무 많은 시간이 걸리면 특정 쿼리의 경우 많은 결과가 너무 많아서로드하는 데 시간이 걸리고이 예외를 던질 경우이 오류가 발생할 수 있습니다.

데이터베이스를 다시 시작하는 것 외에 다른 프로세스를 죽이는 좋은 (안전한) 방법이 없다고 생각합니다. 트랜잭션 시간 초과 옵션도 모릅니다.

가장 좋은 해결책은 교수형의 원인을 파악하고 해당 문제를 해결하는 것입니다. 진공 청소기가 트랜잭션 잠금이 릴리스되기를 기다리고있을 것입니다. 사용 pg_locks 이것이 사실인지 확인하십시오. 어떤 리소스가 잠겨 있는지 알 수 있다면 해당 문제를 해결하기 시작할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top