<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="performance-schema-socket-instances-table">
      </a>
      29.12.3.5 The socket_instances Table
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045073446624">
  </a>
  <a class="indexterm" name="idm46045073445136">
  </a>
  <a class="indexterm" name="idm46045073443648">
  </a>
  <a class="indexterm" name="idm46045073442576">
  </a>
  <p>
   The
   <a class="link" href="performance-schema-socket-instances-table.html" title="29.12.3.5 The socket_instances Table">
    <code class="literal">
     socket_instances
    </code>
   </a>
   table
          provides a real-time snapshot of the active connections to the
          MySQL server. The table contains one row per TCP/IP or Unix
          socket file connection. Information available in this table
          provides a real-time snapshot of the active connections to the
          server. (Additional information is available in socket summary
          tables, including network activity such as socket operations
          and number of bytes transmitted and received; see
   <a class="xref" href="performance-schema-socket-summary-tables.html" title="29.12.20.9 Socket Summary Tables">
    Section 29.12.20.9, “Socket Summary Tables”
   </a>
   ).
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa78887612"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>socket_instances\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
           EVENT_NAME<span class="token punctuation">:</span> wait/io/socket/sql/server_unix_socket
OBJECT_INSTANCE_BEGIN<span class="token punctuation">:</span> 4316619408
            THREAD_ID<span class="token punctuation">:</span> 1
            SOCKET_ID<span class="token punctuation">:</span> 16
                   IP<span class="token punctuation">:</span>
                 PORT<span class="token punctuation">:</span> 0
                STATE<span class="token punctuation">:</span> ACTIVE
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 2. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
           EVENT_NAME<span class="token punctuation">:</span> wait/io/socket/sql/client_connection
OBJECT_INSTANCE_BEGIN<span class="token punctuation">:</span> 4316644608
            THREAD_ID<span class="token punctuation">:</span> 21
            SOCKET_ID<span class="token punctuation">:</span> 39
                   IP<span class="token punctuation">:</span> 127.0.0.1
                 PORT<span class="token punctuation">:</span> 55233
                STATE<span class="token punctuation">:</span> ACTIVE
<span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 3. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
           EVENT_NAME<span class="token punctuation">:</span> wait/io/socket/sql/server_tcpip_socket
OBJECT_INSTANCE_BEGIN<span class="token punctuation">:</span> 4316699040
            THREAD_ID<span class="token punctuation">:</span> 1
            SOCKET_ID<span class="token punctuation">:</span> 14
                   IP<span class="token punctuation">:</span> 0.0.0.0
                 PORT<span class="token punctuation">:</span> 50603
                STATE<span class="token punctuation">:</span> ACTIVE</span></code></pre>
  </div>
  <p>
   Socket instruments have names of the form
   <code class="literal">
    wait/io/socket/sql/
    <em class="replaceable">
     <code>
      socket_type
     </code>
    </em>
   </code>
   and are used like this:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      The server has a listening socket for each network
              protocol that it supports. The instruments associated with
              listening sockets for TCP/IP or Unix socket file
              connections have a
      <em class="replaceable">
       <code>
        socket_type
       </code>
      </em>
      value of
      <code class="literal">
       server_tcpip_socket
      </code>
      or
      <code class="literal">
       server_unix_socket
      </code>
      , respectively.
     </p>
    </li>
    <li class="listitem">
     <p>
      When a listening socket detects a connection, the server
              transfers the connection to a new socket managed by a
              separate thread. The instrument for the new connection
              thread has a
      <em class="replaceable">
       <code>
        socket_type
       </code>
      </em>
      value
              of
      <code class="literal">
       client_connection
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      When a connection terminates, the row in
      <a class="link" href="performance-schema-socket-instances-table.html" title="29.12.3.5 The socket_instances Table">
       <code class="literal">
        socket_instances
       </code>
      </a>
      corresponding to it is deleted.
     </p>
    </li>
   </ol>
  </div>
  <p>
   The
   <a class="link" href="performance-schema-socket-instances-table.html" title="29.12.3.5 The socket_instances Table">
    <code class="literal">
     socket_instances
    </code>
   </a>
   table has
          these columns:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       EVENT_NAME
      </code>
     </p>
     <p>
      The name of the
      <code class="literal">
       wait/io/socket/*
      </code>
      instrument that produced the event. This is a
      <code class="literal">
       NAME
      </code>
      value from the
      <a class="link" href="performance-schema-setup-instruments-table.html" title="29.12.2.3 The setup_instruments Table">
       <code class="literal">
        setup_instruments
       </code>
      </a>
      table.
              Instrument names may have multiple parts and form a
              hierarchy, as discussed in
      <a class="xref" href="performance-schema-instrument-naming.html" title="29.6 Performance Schema Instrument Naming Conventions">
       Section 29.6, “Performance Schema Instrument Naming Conventions”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       OBJECT_INSTANCE_BEGIN
      </code>
     </p>
     <p>
      This column uniquely identifies the socket. The value is
              the address of an object in memory.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       THREAD_ID
      </code>
     </p>
     <p>
      The internal thread identifier assigned by the server.
              Each socket is managed by a single thread, so each socket
              can be mapped to a thread which can be mapped to a server
              process.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       SOCKET_ID
      </code>
     </p>
     <p>
      The internal file handle assigned to the socket.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       IP
      </code>
     </p>
     <p>
      The client IP address. The value may be either an IPv4 or
              IPv6 address, or blank to indicate a Unix socket file
              connection.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       PORT
      </code>
     </p>
     <p>
      The TCP/IP port number, in the range from 0 to 65535.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       STATE
      </code>
     </p>
     <p>
      The socket status, either
      <code class="literal">
       IDLE
      </code>
      or
      <code class="literal">
       ACTIVE
      </code>
      . Wait times for active sockets
              are tracked using the corresponding socket instrument.
              Wait times for idle sockets are tracked using the
      <code class="literal">
       idle
      </code>
      instrument.
     </p>
     <p>
      A socket is idle if it is waiting for a request from the
              client. When a socket becomes idle, the event row in
      <a class="link" href="performance-schema-socket-instances-table.html" title="29.12.3.5 The socket_instances Table">
       <code class="literal">
        socket_instances
       </code>
      </a>
      that is
              tracking the socket switches from a status of
      <code class="literal">
       ACTIVE
      </code>
      to
      <code class="literal">
       IDLE
      </code>
      . The
      <code class="literal">
       EVENT_NAME
      </code>
      value remains
      <code class="literal">
       wait/io/socket/*
      </code>
      , but timing for the
              instrument is suspended. Instead, an event is generated in
              the
      <a class="link" href="performance-schema-events-waits-current-table.html" title="29.12.4.1 The events_waits_current Table">
       <code class="literal">
        events_waits_current
       </code>
      </a>
      table with an
      <code class="literal">
       EVENT_NAME
      </code>
      value of
      <code class="literal">
       idle
      </code>
      .
     </p>
     <p>
      When the next request is received, the
      <code class="literal">
       idle
      </code>
      event terminates, the socket
              instance switches from
      <code class="literal">
       IDLE
      </code>
      to
      <code class="literal">
       ACTIVE
      </code>
      , and timing of the socket
              instrument resumes.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The
   <a class="link" href="performance-schema-socket-instances-table.html" title="29.12.3.5 The socket_instances Table">
    <code class="literal">
     socket_instances
    </code>
   </a>
   table has
          these indexes:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Primary key on (
      <code class="literal">
       OBJECT_INSTANCE_BEGIN
      </code>
      )
     </p>
    </li>
    <li class="listitem">
     <p>
      Index on (
      <code class="literal">
       THREAD_ID
      </code>
      )
     </p>
    </li>
    <li class="listitem">
     <p>
      Index on (
      <code class="literal">
       SOCKET_ID
      </code>
      )
     </p>
    </li>
    <li class="listitem">
     <p>
      Index on (
      <code class="literal">
       IP
      </code>
      ,
      <code class="literal">
       PORT
      </code>
      )
     </p>
    </li>
   </ul>
  </div>
  <p>
   <a class="link" href="truncate-table.html" title="15.1.37 TRUNCATE TABLE Statement">
    <code class="literal">
     TRUNCATE TABLE
    </code>
   </a>
   is not permitted
          for the
   <a class="link" href="performance-schema-socket-instances-table.html" title="29.12.3.5 The socket_instances Table">
    <code class="literal">
     socket_instances
    </code>
   </a>
   table.
  </p>
  <p>
   The
   <code class="literal">
    IP:PORT
   </code>
   column combination value
          identifies the connection. This combination value is used in
          the
   <code class="literal">
    OBJECT_NAME
   </code>
   column of the
   <code class="literal">
    events_waits_
    <em class="replaceable">
     <code>
      xxx
     </code>
    </em>
   </code>
   tables, to identify the connection from which socket events
          come:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      For the Unix domain listener socket
              (
      <code class="literal">
       server_unix_socket
      </code>
      ), the port is 0,
              and the IP is
      <code class="literal">
       ''
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For client connections via the Unix domain listener
              (
      <code class="literal">
       client_connection
      </code>
      ), the port is 0, and
              the IP is
      <code class="literal">
       ''
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For the TCP/IP server listener socket
              (
      <code class="literal">
       server_tcpip_socket
      </code>
      ), the port is
              always the master port (for example, 3306), and the IP is
              always
      <code class="literal">
       0.0.0.0
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For client connections via the TCP/IP listener
              (
      <code class="literal">
       client_connection
      </code>
      ), the port is
              whatever the server assigns, but never 0. The IP is the IP
              of the originating host (
      <code class="literal">
       127.0.0.1
      </code>
      or
      <code class="literal">
       ::1
      </code>
      for the local host)
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
