<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Giorgio Sintichakis</title>
    <description>The latest articles on DEV Community by Giorgio Sintichakis (@gsinti).</description>
    <link>https://dev.to/gsinti</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F108258%2Faec0899c-245a-4ad5-b089-7ef8871a6b02.jpeg</url>
      <title>DEV Community: Giorgio Sintichakis</title>
      <link>https://dev.to/gsinti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gsinti"/>
    <language>en</language>
    <item>
      <title>Setting 'open_files_limit' in Percona 5.7 and CentOS 7.5</title>
      <dc:creator>Giorgio Sintichakis</dc:creator>
      <pubDate>Tue, 16 Oct 2018 21:57:49 +0000</pubDate>
      <link>https://dev.to/gsinti/setting-openfileslimit-in-percona-57-w-centos-75-2805</link>
      <guid>https://dev.to/gsinti/setting-openfileslimit-in-percona-57-w-centos-75-2805</guid>
      <description>

&lt;h1&gt;
  
  
  The Issue
&lt;/h1&gt;

&lt;p&gt;One of our database servers was crashing so I looked into the logs and found some typical warnings:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Warning] Changed limits: max_open_files: 5000 (requested 5125)
[Warning] Changed limits: table_open_cache: 1983 (requested 2000)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These default values just wouldn't do, so I made sure the system limits were increased in &lt;code&gt;/etc/security/limits.conf&lt;/code&gt; and restarted the server. However, modifying &lt;code&gt;my.cnf&lt;/code&gt; settings to change the &lt;code&gt;open_files_limit&lt;/code&gt; to use the new limits would not stick and MySQL continued to report the default value for &lt;code&gt;open_files_limit&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Searching for the Answer
&lt;/h1&gt;

&lt;p&gt;Countless hours later, after dozens of blog posts and StackOverflow guides, I still could not get that variable to stick! Each guide did something just a little differently and no two were the same. Some felt too "invasive" and touched too many system files and settings, and none worked to fix my issue. I wanted a simple, straightforward solution that worked for my particular version of Percona and CentOS.&lt;/p&gt;

&lt;p&gt;Finally, I cracked it!&lt;/p&gt;

&lt;p&gt;Thanks to some help from &lt;a href="https://www.percona.com/blog/2017/10/12/open_files_limit-mystery/"&gt;Sveta's post&lt;/a&gt;, I managed to come up with an elegant solution that worked for me.&lt;/p&gt;

&lt;h1&gt;
  
  
  The Fix
&lt;/h1&gt;

&lt;h3&gt;
  
  
  1. Ensure enough resources are available for processes
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vi /etc/security/limits.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Paste the following contents:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* soft nofile 65535
* hard nofile 65535
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Feel free to tweak this to your own needs, as you might want more open files or to specify separate values for the &lt;code&gt;root&lt;/code&gt; or &lt;code&gt;mysql&lt;/code&gt; user instead of using the &lt;code&gt;*&lt;/code&gt; wildcard.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Create a new service configuration file for &lt;code&gt;mysqld&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl edit mysqld
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Paste the following contents:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Service]
LimitNOFILE=infinity
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;infinity&lt;/code&gt; will simply inherit from the system. You may specify any value between your soft and hard limits.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Reload systemd configuration units
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl daemon-reload
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's it! Restart MySQL and the new &lt;code&gt;open_files_limit&lt;/code&gt; value should appear when querying:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; SELECT @@open_files_limit;
+--------------------+
| @@open_files_limit |
+--------------------+
|              65535 |
+--------------------+
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These changes will also persist if you restart the machine or if MySQL is updated, as the settings in the service configuration file will not be overwritten (whereas the main service configuration file will).&lt;/p&gt;

&lt;p&gt;Other guides also recommended creating a new service configuration file but some system differences lead to different spelling (&lt;code&gt;systemctl edit mysql&lt;/code&gt; versus &lt;code&gt;systemctl edit mysqld&lt;/code&gt;), which was my core frustration. Additionally, you do not need to modify &lt;code&gt;my.cnf&lt;/code&gt; to specify the &lt;code&gt;open_files_limit&lt;/code&gt; there as MySQL will inherit from the system. I feel this solution is the simplest and requires the least amount of modification to files.&lt;/p&gt;

&lt;p&gt;Hopefully this works for you if you're having trouble getting this setting to stick!&lt;/p&gt;


</description>
      <category>percona</category>
      <category>centos</category>
      <category>openfileslimit</category>
      <category>systemd</category>
    </item>
  </channel>
</rss>
