본문 바로가기
MySQL

innodb_open_files과 open_files_limit

by 타마마임팩트_쫀 2021. 8. 4.

MySQL 구성 변수의 설정은 데이터베이스 시스템의 성능에 근본적인 영향을 미칩니다. 때로는 한 변수를 변경하는 것이 다른 변수에 어떤 영향을 미칠 수 있는지 예측하는 것이 약간 까다로울 수 있습니다. 특히 결과가 매우 직관적이지 않은 경우를 처리할 때 그렇습니다. 따라서 여기에서는 open_files_limit이 innodb_open_files보다 높게 설정하면 어떻게 되는지 살펴보겠습니다.

다음을 사용하여 MySQL 구성 파일에서 열린 파일의 최대 수를 설정할 수 있습니다.

open_files_limit=10000

 

이 값이 설정되지 않은 경우 기본값(MySQL 5.7에서는 5,000)을 사용해야 합니다.

open_files_limit 값이 설정되면 infinity로 설정되지 않는 한 SystemD의 LIMIT_NOFILES를 사용합니다(CentOS 7에서는 65536을 사용하지만 수동으로 지정하면 훨씬 더 높은 값이 가능함).

 

[root@centos7-pxc57-3 ~]# grep open_files_limit /etc/my.cnf
open_files_limit=10000
[root@centos7-pxc57-3 ~]# grep LimitNOFILE /lib/systemd/system/mysqld.service.d/limit_nofile.conf
LimitNOFILE=infinity
[root@centos7-pxc57-3 ~]# mysql -e “SELECT @@open_files_limit”
+--------------------+
| @@open_files_limit |
+--------------------+
| 65536              |
+--------------------+
[root@centos7-pxc57-3 ~]# perl -pi -e ’s/LimitNOFILE=infinity/LimitNOFILE=20000/‘ /lib/systemd/system/mysqld.service.d/limit_nofile.conf && systemctl daemon-reload && systemctl restart mysqld
[root@centos7-pxc57-3 ~]# mysql -e “SELECT @@open_files_limit”
+--------------------+
| @@open_files_limit |
+--------------------+
| 20000              |
+--------------------+
[root@centos7-pxc57-3 ~]# perl -pi -e ’s/LimitNOFILE=20000/LimitNOFILE=5000/‘ /lib/systemd/system/mysqld.service.d/limit_nofile.conf && systemctl daemon-reload && systemctl restart mysqld
[root@centos7-pxc57-3 ~]# mysql -e “SELECT @@open_files_limit”
+--------------------+
| @@open_files_limit |
+--------------------+
| 5000               |
+--------------------+

 

위에서 볼 수 있듯이 MySQL은 open_files_limit을 시스템이 허용하도록 구성된  보다 높은 값을 설정할 수 없으며 open_files_limit너무 높게 설정되면 기본값으로 최대값으로 다시 설정됩니다.

그것은 매우 간단해 보이지만, MySQL이 동시에 얼마나 많은 .ibd 파일을 열수 있는지 innodb_open_files에 따라 결정됩니다.

파일을 열기 위해서는 open_files_limit 보다 낮아야 합니다. 만약 더 높게 설정하려고 하면 MySQL은 로그 파일에 warning을 출력합니다.

[root@centos7-pxc57-3 ~]# grep innodb_open_files /var/log/mysqld.log 
2018-09-21T08:31:06.002120Z 0 [Warning] InnoDB: innodb_open_files should not be greater than the open_files_limit.

 

warning을 출력되지 않도록 값을 낮추어야 합니다.

 

[root@centos7-pxc57-3 ~]# mysql -e “SELECT @@innodb_open_files”
+---------------------+
| @@innodb_open_files |
+---------------------+
| 2000                |
+---------------------+

 

왜 2000 으로 설정 되었을까요?

innodb_open_files 너무 높게 설정 하면 문서에 따라 다음과 같이 기본값으로 설정이 되기 때문입니다.

innodb_file_per_table이 활성화되어 있지 않으면 300이고, 300과 table_open_cache 중 더 높은 값으로 설정 됩니다. 
5.6.6 이전에는 기본값이 300입니다.

그리고 table_open_cache는 MySQL 5.6.7 이하 버전의 경우 기본값은 400이고 5.6.8 이후 버전은 2000입니다.

참고로 table_open_cache 완전히 다른 설정입니다. innodb_open_files은 서버가 한 번에 열어둘 수 있는 InnoDB 파일( .ibd)의 수를 제어합니다 . table_open_cache은 서버가 한 번에 열 수 있는 테이블 정의 파일( .frm)의 수  제어합니다 .

'MySQL' 카테고리의 다른 글

ONLY_FULL_GROUP_BY SQL 쿼리 실패  (0) 2021.08.12
MySQL sorted index 생성  (0) 2021.08.06
pt-query-digest  (0) 2021.08.03
MySQL 정적 및 동적 권한 2  (0) 2021.07.30
MySQL 정적 및 동적 권한  (0) 2021.07.29