1. 문제점
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
parent: TimeoutError: Operation timeout
at Timeout.<anonymous> (/app/node_modules/sequelize-pool/lib/Deferred.js:17:25)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7),
original: TimeoutError: Operation timeout
at Timeout.<anonymous> (/app/node_modules/sequelize-pool/lib/Deferred.js:17:25)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
서버에서 timeout 문제가 발생하고 있었다.

또한 cpu 사용량이 100%를 찍으면서 ec2 인스턴스 서버가 다운되는 문제가 발생했다.
DB CPU가 올라간다는 문제는 어떤 쿼리로 인해서 DB LOCK이 잡히고 있을 가능성이 높았고,
실제로 어떤 쿼리가 DB에서 계속 돌고 있음을 발견했다.
2. 일시적 해결 방법
aws RDB postgresql에서 파라미터 설정을 하는 것

statement_timeout
1. 목적:
• 데이터베이스 서버가 오래 실행되는 쿼리로 인해 잠기지 않도록 하기 위해 사용됩니다.
• 특정 쿼리가 너무 오래 걸릴 경우 자동으로 중단시켜 다른 쿼리의 실행을 보장합니다.
2. 비즈니스 사례:
• 쿼리가 일정 시간 이상 실행되면 서버 리소스를 과도하게 사용하게 되어 다른 쿼리의 실행에 영향을 미칠 수 있습니다.
• 무한 루프 쿼리나 최적화되지 않은 쿼리로 인해 발생할 수 있는 성능 문제를 예방합니다.
SET statement_timeout = '2s';
idle_in_transaction_session_timeout
1. 목적:
• 열린 트랜잭션이 있는 상태에서 세션이 오랫동안 유휴 상태로 남아 있는 것을 방지합니다.
• 유휴 트랜잭션이 잠금이나 오래된 데이터 문제를 야기할 수 있습니다.
2. 비즈니스 사례:
• 트랜잭션이 열린 상태로 오랫동안 유휴 상태가 되면, 테이블의 청소(vacuuming)가 지연되고, 이는 테이블 크기 증가 및 성능 저하를 초래할 수 있습니다.
• 다른 트랜잭션이 리소스를 기다리게 되는 문제를 방지합니다.
SET idle_in_transaction_session_timeout = '2s';
그래서 statement_timeout과idle_in_transaction_session_timeout 파라미터 설정을 해서 계속 도는 쿼리를 끊어주었다.
해당 옵션은 데이터베이스 수준의 설정으로 모든 유저가 동일하게 설정되게 했다.
2-1. 궁금증
왜 lock_timeout과 idle_session_timeout을 사용하지 않았을까?
idle_session_timeout:
• 연결 풀링 소프트웨어나 미들웨어를 사용하는 환경에서는 세션이 갑자기 끊기는 것을 잘 처리하지 못할 수 있습니다. 이는 예기치 않은 연결 종료로 인해 시스템의 안정성을 저해할 수 있습니다. 따라서, 이러한 환경에서는 idle_session_timeout을 설정하지 않는 것이 좋습니다.
lock_timeout:
• statement_timeout이 설정되어 있으면, 쿼리가 일정 시간 동안 실행되지 못하게 제한됩니다. 이 경우, 잠금 대기 시간도 포함되므로 statement_timeout이 lock_timeout보다 먼저 적용됩니다. 따라서, statement_timeout이 설정되어 있다면 lock_timeout의 효과는 제한적일 수 있습니다.
숙제.
해당 해결방법은 문제가 있는 쿼리를 해결한게 아니므로 쿼리 옵티마이저나 부하테스트 등을 통해 테스트를 많이 돌려보는 것이 해결방법이 아닐까 싶다.
또한 빠른 문제 인식을 위해서 RDB 인스턴스의 메트릭 정보를 CloudWatch 경보를 이용해 받고 이를 Slack으로 전송해주는 알림 파이프라인을 구축하는 것도 필요하겠다.
참고
https://www.postgresql.org/docs/current/runtime-config-client.html
20.11. Client Connection Defaults
20.11. Client Connection Defaults # 20.11.1. Statement Behavior 20.11.2. Locale and Formatting 20.11.3. Shared Library Preloading 20.11.4. Other Defaults 20.11.1. Statement Behavior …
www.postgresql.org
idle_in_transaction_session_timeout - AWS Prescriptive Guidance
idle_in_transaction_session_timeout The idle_in_transaction_session_timeout parameter controls the amount of time an idle transaction waits before it's stopped. The default value for this parameter in Amazon RDS for PostgreSQL and Aurora PostgreSQL-Compati
docs.aws.amazon.com
statement_timeout - AWS Prescriptive Guidance
statement_timeout The statement_timeout parameter sets the maximum amount of time a query can run before it's stopped. AWS CLI syntax The following command changes statement_timeout for a specific DB parameter group. This change applies to all instances or
docs.aws.amazon.com
https://www.youtube.com/watch?v=VKPFmKPf3uY
'Database > postgresql' 카테고리의 다른 글
postgresql local 환경 설정 (0) | 2024.05.15 |
---|
1. 문제점
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
parent: TimeoutError: Operation timeout
at Timeout.<anonymous> (/app/node_modules/sequelize-pool/lib/Deferred.js:17:25)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7),
original: TimeoutError: Operation timeout
at Timeout.<anonymous> (/app/node_modules/sequelize-pool/lib/Deferred.js:17:25)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
서버에서 timeout 문제가 발생하고 있었다.

또한 cpu 사용량이 100%를 찍으면서 ec2 인스턴스 서버가 다운되는 문제가 발생했다.
DB CPU가 올라간다는 문제는 어떤 쿼리로 인해서 DB LOCK이 잡히고 있을 가능성이 높았고,
실제로 어떤 쿼리가 DB에서 계속 돌고 있음을 발견했다.
2. 일시적 해결 방법
aws RDB postgresql에서 파라미터 설정을 하는 것

statement_timeout
1. 목적:
• 데이터베이스 서버가 오래 실행되는 쿼리로 인해 잠기지 않도록 하기 위해 사용됩니다.
• 특정 쿼리가 너무 오래 걸릴 경우 자동으로 중단시켜 다른 쿼리의 실행을 보장합니다.
2. 비즈니스 사례:
• 쿼리가 일정 시간 이상 실행되면 서버 리소스를 과도하게 사용하게 되어 다른 쿼리의 실행에 영향을 미칠 수 있습니다.
• 무한 루프 쿼리나 최적화되지 않은 쿼리로 인해 발생할 수 있는 성능 문제를 예방합니다.
SET statement_timeout = '2s';
idle_in_transaction_session_timeout
1. 목적:
• 열린 트랜잭션이 있는 상태에서 세션이 오랫동안 유휴 상태로 남아 있는 것을 방지합니다.
• 유휴 트랜잭션이 잠금이나 오래된 데이터 문제를 야기할 수 있습니다.
2. 비즈니스 사례:
• 트랜잭션이 열린 상태로 오랫동안 유휴 상태가 되면, 테이블의 청소(vacuuming)가 지연되고, 이는 테이블 크기 증가 및 성능 저하를 초래할 수 있습니다.
• 다른 트랜잭션이 리소스를 기다리게 되는 문제를 방지합니다.
SET idle_in_transaction_session_timeout = '2s';
그래서 statement_timeout과idle_in_transaction_session_timeout 파라미터 설정을 해서 계속 도는 쿼리를 끊어주었다.
해당 옵션은 데이터베이스 수준의 설정으로 모든 유저가 동일하게 설정되게 했다.
2-1. 궁금증
왜 lock_timeout과 idle_session_timeout을 사용하지 않았을까?
idle_session_timeout:
• 연결 풀링 소프트웨어나 미들웨어를 사용하는 환경에서는 세션이 갑자기 끊기는 것을 잘 처리하지 못할 수 있습니다. 이는 예기치 않은 연결 종료로 인해 시스템의 안정성을 저해할 수 있습니다. 따라서, 이러한 환경에서는 idle_session_timeout을 설정하지 않는 것이 좋습니다.
lock_timeout:
• statement_timeout이 설정되어 있으면, 쿼리가 일정 시간 동안 실행되지 못하게 제한됩니다. 이 경우, 잠금 대기 시간도 포함되므로 statement_timeout이 lock_timeout보다 먼저 적용됩니다. 따라서, statement_timeout이 설정되어 있다면 lock_timeout의 효과는 제한적일 수 있습니다.
숙제.
해당 해결방법은 문제가 있는 쿼리를 해결한게 아니므로 쿼리 옵티마이저나 부하테스트 등을 통해 테스트를 많이 돌려보는 것이 해결방법이 아닐까 싶다.
또한 빠른 문제 인식을 위해서 RDB 인스턴스의 메트릭 정보를 CloudWatch 경보를 이용해 받고 이를 Slack으로 전송해주는 알림 파이프라인을 구축하는 것도 필요하겠다.
참고
https://www.postgresql.org/docs/current/runtime-config-client.html
20.11. Client Connection Defaults
20.11. Client Connection Defaults # 20.11.1. Statement Behavior 20.11.2. Locale and Formatting 20.11.3. Shared Library Preloading 20.11.4. Other Defaults 20.11.1. Statement Behavior …
www.postgresql.org
idle_in_transaction_session_timeout - AWS Prescriptive Guidance
idle_in_transaction_session_timeout The idle_in_transaction_session_timeout parameter controls the amount of time an idle transaction waits before it's stopped. The default value for this parameter in Amazon RDS for PostgreSQL and Aurora PostgreSQL-Compati
docs.aws.amazon.com
statement_timeout - AWS Prescriptive Guidance
statement_timeout The statement_timeout parameter sets the maximum amount of time a query can run before it's stopped. AWS CLI syntax The following command changes statement_timeout for a specific DB parameter group. This change applies to all instances or
docs.aws.amazon.com
https://www.youtube.com/watch?v=VKPFmKPf3uY
'Database > postgresql' 카테고리의 다른 글
postgresql local 환경 설정 (0) | 2024.05.15 |
---|