You are here

function _prod_check_dbstatus_pgsql in Production check & Production monitor 7

Same name and namespace in other branches
  1. 6 includes/prod_check.admin.inc \_prod_check_dbstatus_pgsql()

Helper function to return PostgreSQL status info.

Useful links for possible expansion: http://www.php.net/manual/en/book.pgsql.php http://www.alberton.info/postgresql_meta_info.html#.UbXmAFQW3eU http://www.postgresql.org/docs/devel/static/catalog-pg-statistic.html http://www.postgresql.org/docs/9.0/static/functions-info.html http://www.postgresql.org/docs/9.0/static/functions-admin.html

1 call to _prod_check_dbstatus_pgsql()
prod_check_dbstatus in includes/prod_check.admin.inc
Database status page.

File

includes/prod_check.admin.inc, line 956

Code

function _prod_check_dbstatus_pgsql($db_name, $details) {

  // Get detailed status.
  $rows = array();
  try {

    // See http://www.postgresql.org/docs/9.0/static/view-pg-settings.html
    $result = db_query('SELECT * FROM pg_settings');
    foreach ($result as $row) {

      /* TODO: add some more detail here? This is available:

               Column   | Type | Modifiers | Storage  | Description
            ------------+------+-----------+----------+-------------
             name       | text |           | extended |
             setting    | text |           | extended |
             unit       | text |           | extended |
             category   | text |           | extended |
             short_desc | text |           | extended |
             extra_desc | text |           | extended |
             context    | text |           | extended |
             vartype    | text |           | extended |
             source     | text |           | extended |
             min_val    | text |           | extended |
             max_val    | text |           | extended | */
      $rows[] = array(
        $row->name,
        $row->setting,
      );
    }
  } catch (Exception $e) {
  }
  if ($rows) {
    $details['status'] = array(
      'title' => t('Detailed status'),
      'header' => array(
        t('Name'),
        t('Setting'),
      ),
      'rows' => $rows,
    );
  }

  // Get all tables.
  $rows = array();
  try {

    // See http://www.postgresql.org/docs/9.0/static/catalog-pg-class.html
    // relclass: r = ordinary table, i = index, S = sequence, v = view, c = composite type, t = TOAST table
    $result = db_query("SELECT relname FROM pg_class WHERE relname !~ '^(pg_|sql_)' AND relkind = 'r'");
    foreach ($result as $row) {
      $rows[] = array(
        $row->relname,
      );
    }
  } catch (Exception $e) {
  }
  if ($rows) {
    $details['tables'] = array(
      'title' => t('Tables for active database %name', array(
        '%name' => $db_name,
      )),
      'header' => array(
        t('Table'),
      ),
      'rows' => $rows,
    );
  }

  // Get all databases.
  $rows = array();
  try {
    $result = db_query('SELECT datname FROM pg_database');
    foreach ($result as $row) {
      $rows[] = array(
        $row->datname,
      );
    }
  } catch (Exception $e) {
  }
  if ($rows) {
    $details['databases'] = array(
      'title' => t('Available databases'),
      'header' => array(
        t('Database'),
      ),
      'rows' => $rows,
    );
  }
  return $details;
}