Monitoring



모니터링용 Software 설치

#--- CentOS7
yum  -y  install  sysstat 

#--- NodeJS
npm  install  node-os-utils

#--- OS 버전 확인
cat  /etc/*-release  |  uniq

CPU 모니터링

#--- CPU 갯수
cat  /proc/cpuinfo  |  grep  processor

#--- CPU 평균 사용시간
sar  1  100                   #--- 1초 단위로 100번 검사후 평균 표시

#--- 기타 확인 방법
top
pidstat  1

sar  1  3
sar  -r

#--- CPU별 CPU 사용시간 표시
mpstat  -P  ALL  1

Momory 모니터링

#--- 전체 메모리 용량
cat  /proc/meminfo  |  grep MemTotal

#--- 메모리 상태 확인
vmstat  1  100                          #--- 1초마다 정보 표시
#--- r : 동작중인 프로세스의 수             #--- 값이 크면 cpu 부족
#--- free : Free memory (KB)
#--- si : swap-In                       #--- 0이 아니면 메모리 부족 (swap 영역에서 주메모리로 이동)
#--- so : Swap-Out                      #--- 0이 아니면 메모리 부족 (주메모리에서 swap 영역으로 이동)
#--- us, sy, id, wa, st : CPU 사용율
#---     us. User time, sy. System time, id. Idle, wa. Wait I/O, st. Stolen time

#--- 메모리 사용 평균 확인
free  -m
#--- Free 메모리 확인
#--- buff/cache : I/O Buffer 캐시 사용량, 0에 가까우면 높은 Disk I/O 발생
#--- available

Storage 모니터링

yum  install  dstat

#--- 로그 정리
pm2  flush
cd  /root/.pm2/logs
#---     수작업으로 로그 정리

#--- 디스크 사용량 조회
df  -h  |  egrep  'Avail|mapper'

iostat  -xz  1
#--- r/s : Read 요청
#--- w/s : Write 요청
#--- rkB/s : Read KB/s 
#--- wkB/s : Write KB/s
#--- await : I/O 처리 평균 시간 (밀리세컨드)

dstat
lsblk

Network 모니터링

sar  -n  DEV  1
#--- rxpck/s
#--- txpck/s
#--- rxkB/s : 초당 네트워크 수신량
#--- txkB/s : 초당 네트워크 송신량

#--- TCP 통신량 요약
sar  -n  TCP,ETCP  1
#--- active/s : 로컬에서 요청한 초당 tcp connection 수 (connect())
#--- passive/s : 요청된 초당 tcp 커넥션 수 (accept())
#--- retrans/s : 초당 tcp 재연결 수

Process 모니터링

#--- CPU 사용량 top 10
#---     USER : 사용자 ID
#---     PID : Process ID
#---     PPID : Parent Process ID
#---     RSS : Non swapped Physical memory (KB)
#---     SIZE : SWAP 공간
#---     VSZ : 프로세스의 가상 메모리 (KB)
ps  -eo  user,pid,ppid,rss,size,vsize,pmem,pcpu,time,comm  --sort  -pcpu  |  head  -21


#--- Memory 사용량 top 10
#---     USER : 사용자 ID
#---     PID : Process ID
#---     PPID : Parent Process ID
#---     RSS : Non swapped Physical memory (KB)
#---     SIZE : SWAP 공간
#---     VSZ : 프로세스의 가상 메모리 (KB)
ps  -eo  user,pid,ppid,rss,size,vsize,pmem,pcpu,time,comm  --sort  -pcpu  |  head  -11

#--- 프로세스 정보
#---     /proc/${PID}/
cat  /proc/${PID}/status

MariaDB 모니터링

-- scadadb 데이터베이스의 크기(MB)
SELECT table_schema, sum(round(((data_length + index_length) / 1024 / 1024), 2)) "MB"
  FROM information_schema.TABLES
 WHERE table_schema = "scadadb"
 GROUP BY table_schema;
 
-- scadadb 데이터베이스에 포함된 테이블별 크기
SELECT TABLE_NAME, round(((data_length + index_length) / 1024 / 1024), 2) "MB"
  FROM information_schema.TABLES
 WHERE table_schema = "scadadb"
 ORDER BY (data_length + index_length) DESC;

-- Table별 레코드 수
SELECT TABLE_NAME, TABLE_ROWS
  FROM information_schema.TABLES
 WHERE table_schema = "scadadb"
 ORDER BY TABLE_ROWS DESC;



-- obcondb 데이터베이스의 크기(MB)
SELECT table_schema, sum(round(((data_length + index_length) / 1024 / 1024), 2)) "MB"
  FROM information_schema.TABLES
 WHERE table_schema = "obcondb"
 GROUP BY table_schema;
 
-- obcondb 데이터베이스에 포함된 테이블별 크기
SELECT TABLE_NAME, round(((data_length + index_length) / 1024 / 1024), 2) "MB"
  FROM information_schema.TABLES
 WHERE table_schema = "obcondb"
 ORDER BY (data_length + index_length) DESC;

-- Table별 레코드 수
SELECT TABLE_NAME, TABLE_ROWS
  FROM information_schema.TABLES
 WHERE table_schema = "obcondb"
 ORDER BY TABLE_ROWS DESC;



-- 테이블에 포함된 partition 정보 표시
SELECT TABLE_SCHEMA, TABLE_NAME, PARTITION_NAME, PARTITION_ORDINAL_POSITION, TABLE_ROWS
  FROM INFORMATION_SCHEMA.PARTITIONS
  WHERE TABLE_NAME = 'devicedata1s';

MariaDB 튜닝

top
ps  -ef  |  grep  mysql
pidstat  -t  -p  31922  2 
# TID: Thread ID

#--- CentOS 설정
ulimit  -n  65536
ulimit  -n
ulimit  -a

mysql  -uroot  -p  mysql
    show  variables  like  '%connect%';
    show  global  status  like  '%connect%';
    show  global  status  like  '%Threads%';
    
    show  variables  like  'wait_timeout';
    show  variables  like  'thread_cache_size';
    show  variables  like  'ppp';
    show  variables  like  'ppp';
    show  variables  like  'ppp';
    show  variables  like  'ppp';
    set  global  max_connections=1024;

vi  /etc/my.cnf
    key_buffer_size = 256M
    query_cache_size = 512M
    tmp_table_size = 64M
    innodb_buffer_pool_size = 256M
    innodb_additional_mem_pool_size = 2M
    innodb_log_buffer_size = 2M
    max_connections = 1024
    max_connect_errors = 2048
    sort_buffer_size = 2M
    read_buffer_size = 2M
    read_rnd_buffer_size = 8M
    join_buffer_size = 1M
    thread_stack = 196K
    binlog_cache_size = 32K

    # net_read_timeout    = 3600
    # net_write_timeout   = 3600
    # wait_timeout = 3600
    # interactive_timeout = 3600

    wait_timeout = 60
    interactive_timeout = 60
    max_heap_table_size = 64M
    table_cache = 1024
    max_allowed_packet = 4M
    myisam_sort_buffer_size = 64M
    thread_cache = 8
    thread_stack = 262144
    query_cache_type = 1
    query_cache_limit = 16M

Disk 증설

LVM (Logical Volume Manager)

yum  -y  install  lvm2  lvm2-*
yum  -y  install  xfsprogs              #--- For mkfs.xfs

#--- KT Cloud에서 SSD Disk를 추가 한다.
#---     "Server > Disk" 메뉴에서 "Disk 생성"을 한다.
#---     Server Disk는 최대 13개까지 mount 가능하다고 합니다.
#---     "Server > Disk" 메뉴에서 "연결"을 사용하여 추가한 Disk를 Server에 연결 한다.

#--- 추가된 disk 확인
lsblk  -l
fdisk  -l

#--- Disk를 LVM용으로 설정
fdisk  /dev/xvdk
# n p 1 엔터 엔터
# t 8e
# w
lsblk  -l                               #--- part가 생김
fdisk  -l

#--- LVM에 disk(part) 추가
#---     PG(Physical Volumn) 생성
# pvdisplay
pvcreate  /dev/xvdk1
pvscan

#---     VG(Volumn Group) 확장
# vgscan
# 생성: vgcreate  vg_data  /dev/xvdk1
vgextend  vg_data  /dev/xvdk1
vgdisplay

#--- LV (Logical Volume) 확장
# lvscan
lvextend  -l  +100%FREE  -n  /dev/vg_data/lv_data
lvdisplay

#--- 파일 시스템 생성
# resize2fs  /dev/mapper/vg_data-lv_data    #--- for ext4
xfs_growfs  /dev/mapper/vg_data-lv_data
df -Th

#--- Mount: 이미 되어 있어서 할 필요가 없음
# vi  /root/mount.bash
# vi  /etc/fstab
#     /dev/vg_BigData001/lv_BigData001  /nas  ext4  defaults  1  2

Device 모니터링

#--- Site 갯수
SELECT count(*)
  FROM sites
 WHERE deleted = 0
   AND status = 'Active';

#--- 장비 종류별 갯수
SELECT type, count(*)
  FROM devices
 WHERE deleted = 0
 GROUP BY type
 ORDER BY type ASC;

SELECT type, count(*)
  FROM devices
 WHERE deleted = 0
   AND statusUse = "Active"
 GROUP BY type
 ORDER BY type ASC;
 
 

#--- Site별 장비 종류별 갯수
SELECT site, type, count(*)
  FROM devices
 WHERE deleted = 0
   AND statusUse = "Active"
 GROUP BY site, type
 ORDER BY site ASC, type ASC;  

기타 모니터링

#--- 시스템 메시지 확인
dmesg  |  tail

Partition 관리

-- scada.sql 참조
SHOW TABLES;

SHOW CREATE TABLE `devicedata1s`;
SHOW INDEXES FROM `devicedata1s`;

-- Partition 조회
SELECT table_schema, table_name, partition_name, partition_method, partition_expression, table_rows, avg_row_length, data_length, index_length
  FROM information_schema.partitions
 WHERE table_name = 'devicedata1s'
 ORDER BY table_name ASC, partition_name ASC;

-- Partition 추가
-- ALTER TABLE `devicedata1s` ADD PARTITION (
--     PARTITION p202401 VALUES LESS THAN ('2024019') ENGINE = InnoDB
-- );

-- 1493 오류
-- VALUES LESS THAN value must be strictly increasing for each partition

-- 위 오류 발생시 partition 재구성
alter table test_db.tb_part_test
REORGANIZE PARTITION p202101 into (
    partition p202012 values less than ('2021-01-01:00') engine=innodb,
    partition p202101 values less than ('2021-02-01:00') engine=innodb
);



-- Partition 삭제
--     Partition을 삭제하면 해당 파티션에 있던 데이터도 모두 삭제 된다.
-- ALTER TABLE `devicedata1s`
--  DROP PARTITION p201901;
 
-- Partition의 데이터 조회
SELECT *
  FROM `devicedata1s` PARTITION (p201901);



-- Exchange Partition를 사용하여 Partition과 해당 데이터 삭제
--    sourceTable : 원본 테이블
--    targetTable : 삭제를 위한 임시 테이블
CREATE TABLE targetTable like sourceTable;
AlTER TABLE targetTable REMOVE PARTITIONING;

ALTER TABLE sourceTable 
      EXCHANGE PARTITION p201901 WITH TABLE targetTable
      WITHOUT VALIDATION;

ALTER TABLE sourceTable
      DROP PARTITION p201901;

DROP TABLE targetTable;
 

데이터 백업과 삭제

#--- 데이터베이스 장비에서 show 명령을 실행한 후, 가이드대로 작업할 것
cd  /nas2/backup_data

/work/bin/backupDevicedata.bash  INIT
ls -altF

/work/bin/backupDevicedata.bash  DATA  1140
watch -n 5 'ls -alF devicedata101s_* | tail -15'

/work/bin/backupDevicedata.bash  OTHER
watch -n 2 'ls -alF devicedata[2345678AB]s_*2023*'

#-----------------------------------------------------------
#--- 백업 파일 목록 보기
#-----------------------------------------------------------
cd  /nas2/backup_data

watch -n 5 'ls -alF devicedata101s_* | tail -10'

watch -n 5 'ls -alF devicedata[2345678a]s_* | tail -10'

#-----------------------------------------------------------
#--- 정류기 데이터 백업
#---     2019년부터 2022년 5월까지 백업 완료
#---     최종 백업 번호 : 270  <  expr ${id} + 139
#---         *** 백업한 파일을 외장 디스크로 다운로드할 것 ***
#---     다음 백업 번호 : 280
#-----------------------------------------------------------
# /work/bin/backupDevicedata.bash 파일 내용을 수정할 것
###--- 정류기 데이터 백업
###---    ID는 IDS이 갯수만큼 증가1G
IDS=(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29)
for id in ${IDS[@]}; do
    ID=`expr ${id} + 180`
    ID_FR=`expr ${ID} \* 5000000`
    ID_TO=$(expr ${ID} \* 5000000 + 5000000 - 1)
    funcBackupById  devicedata101s  ${ID_FR}  ${ID_TO}
done

# 1 파일 백업시 약 40초 소요 (600MB, 500만 데이터)
#    영향 : 실시간 연동 현황에 약 2초 느려짐
#
# 139번 : 20220603111932
# 140번 : 20220604014446
# 189번 : 20220704083727

#-----------------------------------------------------------
#--- 기타 장비 데이터 백업
#---     2019년부터 2021년 12월까지 백업 완료
#-----------------------------------------------------------
# /work/bin/backupDevicedata.bash 파일 내용을 수정할 것
TABLES=(
    "devicedata2s" "devicedata3s" "devicedata4s" "devicedata5s"
    "devicedata6s" "devicedata7s" "devicedata8s" "devicedataAs" 
)
for table in ${TABLES[@]}; do
    # funcBackupByStatusDatetime  ${table}  2019
    # funcBackupByStatusDatetime  ${table}  2020
    # funcBackupByStatusDatetime  ${table}  2021
    echo " "
done

#-----------------------------------------------------------
#--- 정류기 데이터 삭제
#---     ALTER TABLE devicedata1s TRUNCATE PARTITION p202010;
#---     ALTER TABLE devicedata1s TRUNCATE PARTITION p202010;
#-----------------------------------------------------------
# 아래에서 ppp로 표시한 2군데서 작업할 것
  • 삭제
    • ppp 로 표시한 부분에서 작업할 것
-- ---------------------------------------------------------
-- Table별 레코드 수
SELECT TABLE_NAME, TABLE_ROWS
  FROM information_schema.TABLES
 WHERE table_schema = "scadadb"
   AND table_name like 'devicedata%'
 ORDER BY TABLE_NAME ASC;
 
-- 2022년 8월 11일 기준
--     devicedata1s   : 1,986,886,632 (201901 ~ 202204)
--     "2019년 ~ 2021년" 데이터 사용
--                      2,090,000,000 (~ 2022년 3월)
--     devicedata101s : 1,264,574,472 (202204 ~ )
---    "2022년 ~" 데이터 사용
--     devicedata2s   :     4,532,070 (2019 ~ )
--     devicedata3s   :       153,827 (2019 ~ )
--     devicedata4s   :       397,148 (2019 ~ )
--     devicedata5s   :    38,900,043 (2019 ~ )
--     devicedata6s   :     5,119,056 (2019 ~ )
--     devicedata7s   :        43,877 (2020 ~ 2020)
--     devicedata8s   :    18,926,554 (202101 ~)
--     devicedataAs   :            11 (없음)

-- 2019년 백업 대상 : devicedata[123456]s  >  삭제 예정
-- 2020년 백업 대상 : devicedata[123456]s  >  일부 삭제 예정
-- 2021년 백업 대상 : devicedata[12345678]s
-- 2022년 백업 대상 : devicedata[1234568]s, devicedata101s


-- ---------------------------------------------------------
-- 장비 정보 백업
SHOW CREATE TABLE `devices`;
SHOW CREATE TABLE `devicedata1s`;
SHOW CREATE TABLE `devicedata101s`;
SHOW CREATE TABLE `devicedata2s`;
SHOW CREATE TABLE `devicedata3s`;
SHOW CREATE TABLE `devicedata4s`;
SHOW CREATE TABLE `devicedata5s`;
SHOW CREATE TABLE `devicedata6s`;
SHOW CREATE TABLE `devicedata7s`;
SHOW CREATE TABLE `devicedata8s`;
SHOW CREATE TABLE `devicedataAs`;


-- ---------------------------------------------------------
-- 장비 데이터 백업
select id from devicedata1s   order by id asc;
select id from devicedata101s order by id asc;
select id from devicedata2s   order by id asc;
select id from devicedata3s   order by id asc;
select id from devicedata4s   order by id asc;
select id from devicedata5s   order by id asc;
select id from devicedata6s   order by id asc;
select id from devicedata7s   order by id asc;
select id from devicedata8s   order by id asc;
select id from devicedataAs   order by id asc;
-- devicedata1s   : 86,907,761
-- devicedata101s : 1
-- devicedata2s   : 1
-- devicedata3s   : 1
-- devicedata4s   : 1
-- devicedata5s   : 1
-- devicedata6s   : 1
-- devicedata7s   : 1
-- devicedata8s   : 1
-- devicedataAs   : 1

-- /work/bin/backupDevicedata.bash 프로그램 실행


-- ---------------------------------------------------------
-- 장비 데이터 삭제

--  파트션의 데이터를 삭제 한다.
ALTER TABLE devicedata1s TRUNCATE PARTITION p201901;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201902;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201903;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201904;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201905;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201906;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201907;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201908;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201909;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201910;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201911;
ALTER TABLE devicedata1s TRUNCATE PARTITION p201912;

ALTER TABLE devicedata1s TRUNCATE PARTITION p202001;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202002;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202003;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202004;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202005;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202006;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202007;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202008;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202009;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202010;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202011;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202012;

ALTER TABLE devicedata1s TRUNCATE PARTITION p202101;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202102;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202103;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202104;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202105;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202106;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202107;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202108;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202109;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202110;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202111;
ALTER TABLE devicedata1s TRUNCATE PARTITION p202112;
ALTER TABLE devicedata1s TRUNCATE PARTITION p999999;
-- ppp 여기에 추가할 것

-- devicedata1s 파티션을 삭제 한다.
ALTER TABLE devicedata1s DROP PARTITION p201901;
ALTER TABLE devicedata1s DROP PARTITION p201902;
ALTER TABLE devicedata1s DROP PARTITION p201903;
ALTER TABLE devicedata1s DROP PARTITION p201904;
ALTER TABLE devicedata1s DROP PARTITION p201905;
ALTER TABLE devicedata1s DROP PARTITION p201906;
ALTER TABLE devicedata1s DROP PARTITION p201907;
ALTER TABLE devicedata1s DROP PARTITION p201908;
ALTER TABLE devicedata1s DROP PARTITION p201909;
ALTER TABLE devicedata1s DROP PARTITION p201910;
ALTER TABLE devicedata1s DROP PARTITION p201911;
ALTER TABLE devicedata1s DROP PARTITION p201912;

ALTER TABLE devicedata1s DROP PARTITION p202001;
ALTER TABLE devicedata1s DROP PARTITION p202002;
ALTER TABLE devicedata1s DROP PARTITION p202003;
ALTER TABLE devicedata1s DROP PARTITION p202004;
ALTER TABLE devicedata1s DROP PARTITION p202005;
ALTER TABLE devicedata1s DROP PARTITION p202006;

ALTER TABLE devicedata1s DROP PARTITION p202007;
ALTER TABLE devicedata1s DROP PARTITION p202008;
ALTER TABLE devicedata1s DROP PARTITION p202009;
ALTER TABLE devicedata1s DROP PARTITION p202010;
-- ppp 여기에 추가할 것

-- devicedata101s 파티션을 삭제 한다.
ALTER TABLE devicedata101s DROP PARTITION p201901;
ALTER TABLE devicedata101s DROP PARTITION p201902;
ALTER TABLE devicedata101s DROP PARTITION p201903;
ALTER TABLE devicedata101s DROP PARTITION p201904;
ALTER TABLE devicedata101s DROP PARTITION p201905;
ALTER TABLE devicedata101s DROP PARTITION p201906;
ALTER TABLE devicedata101s DROP PARTITION p201907;
ALTER TABLE devicedata101s DROP PARTITION p201908;
ALTER TABLE devicedata101s DROP PARTITION p201909;
ALTER TABLE devicedata101s DROP PARTITION p201910;
ALTER TABLE devicedata101s DROP PARTITION p201911;
ALTER TABLE devicedata101s DROP PARTITION p201912;

ALTER TABLE devicedata101s DROP PARTITION p202001;
ALTER TABLE devicedata101s DROP PARTITION p202002;
ALTER TABLE devicedata101s DROP PARTITION p202003;
ALTER TABLE devicedata101s DROP PARTITION p202004;
ALTER TABLE devicedata101s DROP PARTITION p202005;
ALTER TABLE devicedata101s DROP PARTITION p202006;
ALTER TABLE devicedata101s DROP PARTITION p202007;
ALTER TABLE devicedata101s DROP PARTITION p202008;
ALTER TABLE devicedata101s DROP PARTITION p202009;
ALTER TABLE devicedata101s DROP PARTITION p202010;
ALTER TABLE devicedata101s DROP PARTITION p202011;
ALTER TABLE devicedata101s DROP PARTITION p202012;

ALTER TABLE devicedata101s TRUNCATE PARTITION p202112;

ALTER TABLE devicedata101s DROP PARTITION p202101;
ALTER TABLE devicedata101s DROP PARTITION p202102;
ALTER TABLE devicedata101s DROP PARTITION p202103;
ALTER TABLE devicedata101s DROP PARTITION p202104;
ALTER TABLE devicedata101s DROP PARTITION p202105;
ALTER TABLE devicedata101s DROP PARTITION p202106;
ALTER TABLE devicedata101s DROP PARTITION p202107;
ALTER TABLE devicedata101s DROP PARTITION p202108;
ALTER TABLE devicedata101s DROP PARTITION p202109;
ALTER TABLE devicedata101s DROP PARTITION p202110;
ALTER TABLE devicedata101s DROP PARTITION p202111;
ALTER TABLE devicedata101s DROP PARTITION p202112;

-- ---------------------------------------------------------
-- To-Do : 장비 데이터 분류 프로그램
--         정류기 : 2019년 ~ 2021년 (devicedata1s)
--                 2022년 01월 ~   (devicedata101s)

-- ---------------------------------------------------------
-- To-Do : 예스코의 장비 데이터 백업과 삭제 프로그램
--         예스코의 정류기 데이터는 5일간만 보관

예스코 데이터 삭제

  • YESCO (예스코)
  • siteKey : '09'
  • type : '1'. 정류기
--- Query시 약 3분 소요
--- 500000000 : 2022-05-10
--- 600000000 : 2022-05-22
SELECT id, siteKey, type, deviceKey, statusDatetime
  FROM devicedata101s 
 WHERE 500000000 <= id AND id < 600000000
   AND siteKey = '09'
   AND type = '1'
 ORDER BY id DESC
 LIMIT 20;
 
--- 삭제시 약  4분 소요 (         0건 데이터 삭제)
--- 삭제시 약  4분 소요 ( 5,162,967건 데이터 삭제)
--- 삭제시 약 27분 소요 (54,699,458건 데이터 삭제)
DELETE FROM devicedata101s
 WHERE 500000000 <= id AND id < 600000000
   AND siteKey = '09'
   AND type = '1';
 
--- Storage 사이즈를 줄이는 방법
---     DELETE 명령은 데이터만 삭제하고 용량은 줄어들지 않는다.

-- 사용 불가 : DB가 너무 느려져서 다른 처리가 되지 않음
-- ALTER TABLE devicedata101s 
--      OPTIMIZE PARTITION p202201;

참고 문헌

최종 수정일: 2024-01-21 23:47:05

이전글 :
다음글 :
상단 menu
arrow_back_ios
arrow_forward_ios