title: Chef: Ohai attribute persistence
body: <p>Chef Server 12.2.0-1. </p>
  
  <p>I'm trying to find a way to query Ohai node attributes from the PostgreSQL database. Having browsed through the table schemas and data, I'm not seeing any tables that would contain those attributes.</p>
  
  <p>Are these attributes stored on Chef server? Is there a way to view them remotely via a database query or a REST call?</p>
  
  <p>List of opscode_chef tables:</p>
  
  <pre><code>checksums
  clients
  containers
  cookbook_artifact_version_checksums
  cookbook_artifact_versions
  cookbook_artifacts
  cookbook_version_checksums
  cookbook_versions
  cookbooks
  data_bag_items
  data_bags
  environments
  groups
  keys
  node_policy
  nodes
  opc_customers
  opc_users
  org_migration_state
  org_user_associations
  org_user_invites
  orgs
  policies
  policy_groups
  policy_revisions
  policy_revisions_policy_groups_association
  roles
  sandboxed_checksums
  users
  </code></pre>
  
  <p><strong>UPDATE 1</strong>: Thanks to @Tensibai. 
  Attributes are stored in table <code>nodes</code>, column <code>serialized_object</code>. The column <code>serialized_object</code> is gzip encoded.</p>
  
  <p>Java code to fetch attributes in json:</p>
  
  <pre><code>String query = "SELECT name, serialized_object FROM nodes";
  PreparedStatement st = conn.prepareStatement(query);
  ResultSet rs = st.executeQuery();
  while (rs.next()) {
      String name = rs.getString("name");
      byte[] arr = rs.getBytes("serialized_object");
      byte[] out = unzip(arr);
      System.out.println(name + " : " + new String(out));
  }
  
  public static byte[] unzip(byte[] in) throws IOException{
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      FileUtils.copy(new GZIPInputStream(new ByteArrayInputStream(in)), out);
      return out.toByteArray();
  }
  </code></pre>
  
  <p>Sample attributes: <a href="https://gist.github.com/rodionos/cb744155539699b5c348" rel="nofollow">https://gist.github.com/rodionos/cb744155539699b5c348</a></p>
  
  <p>I'm not an expert in PostgreSQL. A better solution would probably be to enable a native decompression function as described here: <a href="https://github.com/chef/chef-server/issues/8#issuecomment-99152808" rel="nofollow">https://github.com/chef/chef-server/issues/8#issuecomment-99152808</a></p>