728x90
반응형
ETL 이나 배치프로그램에서 쿼리를 실행할때 시간제한을 두고 싶은 쿼리가 있을 것이다.
무거운 쿼리를 시간제한없이 실행하면 서버에 부하를 많이 줄 수도 있고 Lock이 발생해서 장애의 원인이 될 수 있을 것이다.
이때 사용하는 옵션이 이때 사용하는 옵션이 statement_timeout 이다.
실제 운영환경에서는 2시간(2h) 설정을 많이 사용하고 있으며 Role 별로 설정할 수 있어 유연하게 사용할 수 있다.
다만 0 으로 설정하면 무제한으로 쿼리가 실행될 수 있다. (!!!주의가 필요!!!)
statement_timeout 설정값 확인방법
[root@mdw ~]# su - gpadmin
[gpadmin@mdw ~]$ gpconfig -s statement_timeout
Values on all segments are consistent
GUC : statement_timeout
Master value: 4h
Segment value: 4h
[gpadmin@mdw ~]$
statement_timeout 설정값 변경방법
[gpadmin@mdw ~]$ gpconfig -c statement_timeout -v 2h
20201208:12:11:52:004511 gpconfig:mdw:gpadmin-[INFO]:-completed successfully with parameters '-c statement_timeout -v 2h'
[gpadmin@mdw ~]$
[gpadmin@mdw ~]$ gpstop -u
20201208:12:11:56:004608 gpstop:mdw:gpadmin-[INFO]:-Starting gpstop with args: -u
20201208:12:11:56:004608 gpstop:mdw:gpadmin-[INFO]:-Gathering information and validating the environment...
20201208:12:11:56:004608 gpstop:mdw:gpadmin-[INFO]:-Obtaining Greenplum Master catalog information
20201208:12:11:56:004608 gpstop:mdw:gpadmin-[INFO]:-Obtaining Segment details from master...
20201208:12:11:56:004608 gpstop:mdw:gpadmin-[INFO]:-Greenplum Version: 'postgres (Greenplum Database) 5.22.0 build commit:a32663083d637f01f6ec54504cacc704bc74903b'
20201208:12:11:56:004608 gpstop:mdw:gpadmin-[INFO]:-Signalling all postmaster processes to reload
[gpadmin@mdw ~]$
[gpadmin@mdw ~]$ gpconfig -s statement_timeout
Values on all segments are consistent
GUC : statement_timeout
Master value: 2h
Segment value: 2h
[gpadmin@mdw ~]$
!!! 설정값을 변경한 후 꼭 gpstop -u 를 해주어야 설정값이 적용된다. !!!
실제로 timeout 이 정상적으로 작동되는지 테스틀 해보자.
(해당 세션에 statement_timeout 설정을 1분으로 설정했으며 set statement_timeout='1min'; 이 구문을 사용하지않으면 전역옵션값인 2시간(2h)으로 적용된다.)
db(work_db) 와 role(test_user) 은 먼저 세팅이 되어 있다고 가정하고 test.sql 파일을 생성한다.
[gpadmin@mdw ~]$ cd ~
[gpadmin@mdw ~]$ vi test.sql
set statement_timeout='1min';
show statement_timeout;
select current_timestamp, pg_backend_pid(), pg_sleep(80);
:wq
그리고 psql 명령어로 해당쿼리를 실행하면 쿼리가 중간에 중단되면서 에러메세지가 표시된다.
[gpadmin@mdw ~]$ psql -d work_db -U test_user -f test.sql > ~/result_sql_`date '+%Y%m%d%H%M%S'`.out
psql:test.sql:3: ERROR: canceling statement due to statement timeout
[gpadmin@mdw ~]$
[gpadmin@mdw ~]$ cat ~/result_sql_20201208130319.out
SET
statement_timeout
-------------------
1min
(1 row)
728x90
반응형
'Database > Greenplum' 카테고리의 다른 글
Greenplum 6.14에서 ORCA(query optimizer) 성능향상 (0) | 2021.02.17 |
---|---|
Greenplum biopython-1.76 모듈 설치 (0) | 2021.01.01 |
Greenplum - Procedural Languages 란? (0) | 2020.12.23 |
Greenplum PXF 란? (0) | 2020.12.16 |
Greenplum minor 업그레이드하기(6.3.0->6.11.1) (0) | 2020.12.16 |