๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
SQL/MariaDB

[MariaDB] Too many connections ์—๋Ÿฌ ๋ฐœ์ƒ ์›์ธ๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

by ํ‘์‹œ๋ฐ” 2024. 1. 19.

๐Ÿ˜‘ ๋ฐฐ๊ฒฝ

HeidiSQL๋กœ ์„œ๋ฒ„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘๊ทผํ•˜๋ ค๊ณ   ์‹คํ–‰ํ–ˆ๋Š”๋ฐ, ๊ฐ‘์ž๊ธฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”์‹œ์ง€(Too many connections)๊ฐ€ ๋‚˜์˜ค๋ฉด์„œ ์ ‘์†์ด ๋ถˆ๊ฐ€๋Šฅํ–ˆ๋‹ค. ํ•ด๋‹น ๋ฌธ์ œ ๋ฐœ์ƒ ์›์ธ๊ณผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ํ–ˆ๋˜ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๊ณต์œ ํ•˜๊ณ ์ž ํ•œ๋‹ค.

 

๐Ÿ”Ž ์›์ธ

ํ•ด๋‹น DB ์„œ๋ฒ„๊ฐ€ ์„ค์น˜๋œ ์„œ๋ฒ„์— ์ ‘๊ทผํ•ด์„œ netstat -ano | findstr 3306์„ ํ†ตํ•ด์„œ ์—ฐ๊ฒฐ ๊ฐœ์ˆ˜๋ฅผ ํ™•์ธํ–ˆ๋”๋‹ˆ, ์ •ํ•ด์ง„ ์ปค๋„ฅ์…˜ ํ’€๋ณด๋‹ค ๋งŽ์€ ์ˆ˜์˜ ์—ฐ๊ฒฐ์ด ESTABLISH(์—ฐ๊ฒฐ๋˜์–ด ์žˆ์Œ) ์ƒํƒœ๋กœ ์žกํ˜€ ์žˆ์—ˆ๋‹ค. ์„œ๋น„์Šค์—์„œ ์ปค๋„ฅ์…˜์„ ๋ฌผ๊ณ  ์ฃฝ์€ ๊ฒƒ์ด๋‹ค.

๐Ÿท๏ธ ํ•ด๊ฒฐ

1. ์šฐ์„ ์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ๋จผ์ € ํ™•์ธํ•˜๊ณ  ์ฃฝ์ธ๋‹ค.

show processlist

 

(1) Sleep ์ƒํƒœ์ด๋ฉฐ,

(2) ์ƒ๋‹นํ•œ ์‹œ๊ฐ„์ด(Time) ์ง€๋‚ฌ๊ณ ,

(3) netstat ๋ช…๋ น์–ด ์ˆ˜ํ–‰ ํ›„์— ESTABLISH๋กœ ์žกํžˆ๋Š” ๋ชฉ๋ก์„ ์ถ”๋ฆฐ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  id์— ์ ํžŒ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์‚ญ์ œํ•œ๋‹ค.

 

kill ํ”„๋กœ์„ธ์ŠคID;

 

์‚ญ์ œํ•ด์•ผ ํ•  ๋Œ€์ƒ์ด ๋งŽ๋‹ค๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ด์„œ ์ง€์šธ ์ˆ˜๋„ ์žˆ๋‹ค.

 

select concat('KILL ',id,';') from information_schema.processlist where user='๋Œ€์ƒID' AND Command='Sleep';

 

ํ•ด๋‹น ๋ช…๋ น์–ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉด ์•„๋ž˜ ์ด๋ฏธ์ง€์™€ ๊ฐ™์ด ์ œ๊ฑฐ ๋ช…๋ น์–ด๋ฅผ ์ผ๊ด„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

์ผ๊ด„ ์„ ํƒ ํ›„ ๋ณต์‚ฌํ•˜์—ฌ ๋ช…๋ น์–ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉด ํ•œ ๋ฒˆ์— ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

2. ์ปค๋„ฅ์…˜ ์ˆ˜๋ฅผ ์ถฉ๋ถ„ํžˆ ๋Š˜๋ฆฐ๋‹ค.

์šฐ์„ , DB์—์„œ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ํด๋ผ์ด์–ธํŠธ ๊ฐœ์ˆ˜๋ฅผ ํ™•์ธํ•œ๋‹ค.

 

show variables like '%max_connections%';

 

 

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ํ•ด๋‹น ์ปค๋„ฅ์…˜ 151๊ฐœ๋กœ๋Š” ๋ถ€์กฑํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ 300๊ฐœ๋กœ ๋ณ€๊ฒฝํ•ด ๋ณธ๋‹ค.

 

SET GLOBAL max_connections = 300;

 

๋‹ค์‹œ ์ปค๋„ฅ์…˜์„ ํ™•์ธํ•ด ๋ณธ๋‹ค.

 

 

300๊ฐœ๋กœ ์ •์ƒ์ ์œผ๋กœ ๋Š˜์–ด๋‚œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ“š REFERENCE

https://intro0517.tistory.com/238

https://dev.mysql.com/doc/refman/5.5/en/too-many-connections.html

https://dev.mysql.com/doc/refman/8.0/en/show-processlist.html

'SQL > MariaDB' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

ํ•„๋“œ 1๋ถ€ํ„ฐ N๊นŒ์ง€ ์ž๋™์œผ๋กœ ์ฑ„์šฐ๊ธฐ (+ ๋žญํ‚น)  (0) 2023.12.10

๋Œ“๊ธ€