DataBase
-
[Redis] 백업을 통한 데이터 영속화DataBase/NoSQL 2023. 3. 12. 22:55
Redis는 인메모리 저장 방식으로 리부팅시 데이터가 휘발된다. 따라서 기존 데이터를 영속화하여 복구, 유지시키기 위해서는 디스크에 데이터 백업해주는 과정이 필요하다. 백업 방식에는 1) RDB snapshot, 2) AOF 2가지가 있다. RDB snapshot은 특정 시점을 스냅샷으로 남겨 데이터를 저장하는 방식을 말한다. 여기서 "RDB"는 관계형 데이터베이스가 아니라 Redis DataBase를 의미한다. redis.conf 파일에서 스냅샷 저장에 대한 주기 설정을 할 수 있는데, save 60 10으로 설정하면 60초마다 10개 이상의 데이터 변경이 있을 때 데이터를 저장하겠다는 의미이다. 아래는 redis.conf에 기본으로 설정되어있는 # save 3600 1 300 100 60 1000..
-
[Redis] Sentinel을 이용한 자동 장애조치DataBase/NoSQL 2023. 2. 19. 16:30
1. master-replica-sentinel 구성을 위해 아래와 같이 docker-compose.yml 파일을 작성한다. 2. docker-compose yml파일을 build한다. 3. master, replica, sentinel 3대가 떠 있는 것을 확인한다. 4. sentinel1의 컨테이너에서 redis에 진입해서 바라보고 있는 master의 정보를 확인한다. $ info sentinel 다른 prompt에서 master의 ip주소를 확인한다. $ docker inspect redis-master sentinel1에서 조회한 master의 ip가 실제 master ip와 일치하는 것을 확인할 수 있다. 5. master를 stop한다. sentinel1, sentinel2, senti..
-
[Redis] 서비스 고가용성을 위한 ReplicaDataBase/NoSQL 2023. 2. 19. 15:24
RDB를 사용하거나 AOF를 사용하는 백업방식은 disk에 있는 파일로부터 Redis를 복구하는 방법인데, 백업만으로는 백업 실패 가능성도 있고 복구에 시간도 꽤 소요되는 등 장애 대비에 부족한 측면이 있다. 하지만 Redis 복제를 하면 가용성을 확보할 수 있을 뿐만 아니라 빠른 장애조치가 가능하다. master가 죽었을 경우 복제본(replica)중 하나를 master로 승격시켜 즉시 서비스 정상화가 가능하기 때문이다. replica는 read-only 모드로 사용하는 것이 권장된다. 입력/수정/삭제가 가능하다면 데이터 무결성이 보장되지 않기 때문이다. 또, 하드웨어적인 문제 발생을 대처하기 위해 master와 replica는 물리적으로 다른 머신에 두어야 한다. 아래는 docker를 이용해서 ..
-
[MySQL] 스파르타 코딩클럽 "엑셀보다 쉬운 SQL" 3주차DataBase/RDBMS 2022. 9. 18. 04:32
이번주는 join을 배웠다-!join이란, 공통된 정보 (key값)를 기준으로 두 테이블을 연결해서 한 테이블처럼 보는 것이다.key는 두 테이블의 연결고리가 되므로 당연히 테이블 양쪽 모두에 존재해야 한다. 자주 사용하는 join 개념에는 inner join과 left join이 있다. 쉽게 생각하면 inner join은 교집합, left join은 합집합이다. left join은 join 순서에 따라 결과가 달라지므로 inner join보다 까다롭다. A테이블과 B테이블을 join(left join)할 때, A를 왼쪽에 두고 기준으로 삼으면 B에는 없는 정보가 발생할 수 있다.다시말해 A에 B가 붙을 때 A가 기준이기 때문에 A테이블은 온전히 보이지만 B테이블에는 NULL값이 발생할 수 있는 것이다...
-
[MySQL] 스파르타 코딩클럽 "엑셀보다 쉬운 SQL" 2주차DataBase/RDBMS 2022. 9. 4. 19:32
이번주는 SQL 쿼리를 이용해 보고싶은 raw data를 의미를 갖는 '정보'로 변환시키는 법을 익혔다. 그 방법은 바로 '통계'를 내고 '정렬'을 하는 것이다. 통계를 내기 위해서는 GROUP BY, 정렬을 하기 위해서는 ORDER BY를 사용한다. 1. GROUP BY: GROUP BY를 기반으로 '개수', '최대값', '최소값', '합계', '평균값'등을 구해 통계를 낼 수 있다. SELECT 필드명, method(*) FROM 테이블명 GROUP BY 필드명; : 특정 필드별로 통계치를 보겠다! 💡 쿼리가 실행되는 순서는 FROM → GROUP BY → SELECT라는 것을 기억! 💡 어떤 기준으로 통계를 냈는지 확인할 수 있도록 SELECT로 출력할 내용에 통계치를 낼 method를..
-
[MySQL] 스파르타 코딩클럽 "엑셀보다 쉬운 SQL" 1주차DataBase/RDBMS 2022. 8. 28. 20:14
업무할 때 SQL 쿼리를 자유롭게 구사하기 위해서 어떻게 공부할지 고민하다가 스파르타 코딩클럽의 SQL 수업을 신청하게 됐다.흥미가 붙은 파이썬은 책 한권 잡아서 혼자 공부하는데에 무리가 없지만 SQL은 약간의 강제성이 필요하다고 느꼈다. 그나저나 파이썬, 네트워크 관리사 2급 공부한 내용들도 정리해야하는데 역시 과제인 SQL을 먼저 하고있는 나...아 맞다.. 채팅프로그램 코드리뷰도 해야지!!!🙄 미루고 미루다 후회하지 말자 유진....😇 1주차는 아래와 같은 기본적인 내용이었다. 1) SHOW TABLES로 database에 어떤 테이블들이 있는지 파악2) 원하는 정보가 있을 것 같은 테이블에 대해서 "SELECT * FROM 테이블명" 쿼리 실행3) 원하는 정보를 찾을 때까지 2)를 반복4) 테..