You are here

function _prod_check_dbstatus_pgsql in Production check & Production monitor 6

Same name and namespace in other branches
  1. 7 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 908

Code

function _prod_check_dbstatus_pgsql($db_name, $details) {
  global $active_db;

  // Set title & version.
  $server = db_result(db_query('SELECT version()'));
  $title = t('Running @version', array(
    '@version' => $server,
  ));
  $variables = array(
    'server_version',
    'server_encoding',
    'client_encoding',
    'is_superuser',
    'session_authorization',
    'DateStyle',
    'TimeZone',
    'integer_datetimes',
  );
  $status = '';
  foreach ($variables as $variable) {
    $status .= $variable . ': ' . pg_parameter_status($active_db, $variable) . "<br />\n";
  }

  // 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');
    while ($row = db_fetch_object($result)) {

      /* 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'");
    while ($row = db_fetch_object($result)) {
      $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');
    while ($row = db_fetch_object($result)) {
      $rows[] = array(
        $row->datname,
      );
    }
  } catch (Exception $e) {
  }
  if ($rows) {
    $details['databases'] = array(
      'title' => t('Available databases'),
      'header' => array(
        t('Database'),
      ),
      'rows' => $rows,
    );
  }
  return theme('prod_check_dbstatus', $title, $status, $details);
}