DB2 를 사용하다가 SQL0913 오류를 보신 적이 있나요?
SQL State: 57033 Vendor Code: -913 Message: [SQL0913] Row or object EMPLOYEE in CORPDATA type *FILE in use. Cause . . . . . : The requested object EMPLOYEE in CORPDATA type *FILE is either in use by another application process or a row in the object is in use by either another application process or another cursor in this application process. Recovery . . . : Look at the previously listed messages in the job log (DSPJOBLOG command) or from interactive SQL press F10 (Display messages in job log) on this display to determine if this is an object or record lock wait time out. Do one of the following: -- If the object is locked by another application process, try the SQL statement again when the object is not in use. Use the Work with Object Locks (WRKOBJLCK) command to determine who is currently using the object. -- If the object is a schema and an attempt was made to create a table, view, or index into this schema under commitment control, a save-while-active operation may be in progress on the same schema by another job in the system. Try the request again when the save-while-active processing is complete. -- If a record is locked by another application process, try the SQL statement again when the record is not in use. The Display Record Locks (DSPRCDLCK) command will determine who is currently using the record. -- If this is a record lock held by another cursor in the same application process, you must issue a COMMIT, ROLLBACK, or another FETCH statement on the cursor that is holding the lock before issuing this SQL statement. If this error occurs frequently, use the Change Physical File (CHGPF), Change Logical File (CHGLF), or Override Data Base File (OVRDBF) command to change the object or record wait time out. |
DB2 는 기본적으로 Concurrency 를 위해 Locking 메카니즘을 사용합니다.
이 SQL 메세지는 현재 쿼리에서 액세스하려고 하는 레코드(Row)를 다른 사용자가 Lock을 걸고 사용하고 있기 때문에 사용할 수 없다는 뜻입니다.
에러 메세지의 상세를 읽어보면, Record lock을 잡고 있는 Job 과 사용자를 확인하는 방법이 나옵니다. 하지만 이 명령어들은 시스템 명령어이기 때문에 별도의 5250 세션 접속이 필요합니다.
번거롭게 다른 툴을 사용하지 않고, 현재 사용중인 SQL 툴에서 확인하는 방법을 소개합니다.
아래의 SQL 을 실행하면, Db2 테이블에서 Lock 이 잡혀 있는 레코드별로 누가 어떤 Job을 통해 어떤 SQL로 사용중인지 확인할 수 있습니다.
DB 접속시 사용한 계정 정보와 클라이언트 IP 주소, 클라이언트 시스템명까지 확인할 수 있어 유용합니다.
WITH LOCK_CONFLICT_TABLE (
table_name, lock_state, rrn, q_job_name) AS (
SELECT table_name, lock_state, rrn, job_name
FROM QSYS2.RECORD_LOCK_INFO where
table_schema = 'CORPDATA' and
table_name = 'EMPLOYEE'
) SELECT table_name, lock_state, rrn,
q_job_name, V_SQL_STATEMENT_TEXT,
V_CLIENT_IP_ADDRESS,
B.* FROM LOCK_CONFLICT_TABLE,
TABLE(QSYS2.GET_JOB_INFO(q_job_name)) B;
(이 SQL 문은 IBM i Access Client Solutions 를 설치하면 쉽게 사용할 수 있는 다양한 SQL 예제 중 하나입니다.)
DB 서버에서 파이썬으로 DB2 데이터 활용하기 (0) | 2022.11.28 |
---|---|
동일한 쿼리인데 왜 실행시간이 달라질까? (0) | 2022.11.21 |
Db2 사용자 정의 함수(UDF) 성능 관련 옵션 (0) | 2022.11.07 |
데이터 마스킹(Masking) (0) | 2022.11.03 |
Db2 for i Isolation level (0) | 2022.10.27 |
댓글 영역