Index: CHANGELOG.txt
===================================================================
RCS file: /projects/pgadmin3/CHANGELOG.txt,v
retrieving revision 1.117
retrieving revision 1.118
diff -LCHANGELOG.txt -LCHANGELOG.txt -u -w -r1.117 -r1.118
--- CHANGELOG.txt
+++ CHANGELOG.txt
@@ -16,6 +16,7 @@
+ - 2004-01-25 AP support of pg_xxx_size if available
- 2004-01-21 AP Improved disconnect handling
- 2004-01-21 AP StatusBar with size handle for frmStatus, dlgFunction and dlgView
- 2004-01-21 AP Update ServerStatus to pg_logdir_ls
Index: pgConn.cpp
===================================================================
RCS file: /projects/pgadmin3/src/db/pgConn.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -Lsrc/db/pgConn.cpp -Lsrc/db/pgConn.cpp -u -w -r1.49 -r1.50
--- src/db/pgConn.cpp
+++ src/db/pgConn.cpp
@@ -16,6 +16,7 @@
// PostgreSQL headers
#include
+#include "features.h"
// Network headers
#ifdef __WXMSW__
@@ -426,3 +427,31 @@
}
return majorVersion > major || (majorVersion == major && minorVersion >= minor);
}
+
+
+bool pgConn::HasFeature(int featureNo)
+{
+ if (!features[FEATURE_INITIALIZED])
+ {
+ features[FEATURE_INITIALIZED] = true;
+
+ features[FEATURE_SIZE] =
+ !ExecuteScalar(
+ wxT("SELECT proname FROM pg_proc\n")
+ wxT(" WHERE proname = 'pg_tablespace_size'")
+ wxT( " AND proargtypes[0] = 26"))
+ .IsEmpty();
+ features[FEATURE_FILEREAD] =
+ !ExecuteScalar(
+ wxT("SELECT proname FROM pg_proc\n")
+ wxT(" WHERE proname = 'pg_file_read'")
+ wxT( " AND proargtypes[0] = 25")
+ wxT( " AND proargtypes[1] = 20")
+ wxT( " AND proargtypes[2] = 20"))
+ .IsEmpty();
+ }
+
+ if (featureNo < 1 ||featureNo >= FEATURE_LAST)
+ return false;
+ return features[featureNo];
+}
\ No newline at end of file
Index: pgTablespace.h
===================================================================
RCS file: /projects/pgadmin3/src/include/pgTablespace.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lsrc/include/pgTablespace.h -Lsrc/include/pgTablespace.h -u -w -r1.2 -r1.3
--- src/include/pgTablespace.h
+++ src/include/pgTablespace.h
@@ -22,8 +22,10 @@
int GetIcon() { return PGICON_TABLESPACE; }
void ShowTreeDetail(wxTreeCtrl *browser, frmMain *form=0, ctlListView *properties=0, ctlSQLBox *sqlPane=0);
- static pgObject *ReadObjects(pgCollection *collection, wxTreeCtrl *browser, const wxString &restriction=wxT(""));
+ void ShowStatistics(frmMain *form, ctlListView *statistics);
void ShowReferencedBy(frmMain *form, ctlListView *referencedBy, const wxString &where=wxEmptyString);
+ static pgObject *ReadObjects(pgCollection *collection, wxTreeCtrl *browser, const wxString &restriction=wxT(""));
+ static void ShowStatistics(pgCollection *collection, ctlListView *statistics);
wxString GetLocation() const { return location; };
void iSetLocation(const wxString& newVal) { location = newVal; }
Index: pgIndex.h
===================================================================
RCS file: /projects/pgadmin3/src/include/pgIndex.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -Lsrc/include/pgIndex.h -Lsrc/include/pgIndex.h -u -w -r1.23 -r1.24
--- src/include/pgIndex.h
+++ src/include/pgIndex.h
@@ -31,6 +31,7 @@
int GetIcon() { return PGICON_INDEX; }
void ShowTreeDetail(wxTreeCtrl *browser, frmMain *form=0, ctlListView *properties=0, ctlSQLBox *sqlPane=0);
+ void ShowStatistics(frmMain *form, ctlListView *statistics);
static pgObject *ReadObjects(pgCollection *collection, wxTreeCtrl *browser, const wxString &restriction);
static pgObject *ReadObjects(pgCollection *collection, wxTreeCtrl *browser);
--- /dev/null
+++ src/include/features.h
@@ -0,0 +1,18 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin III - PostgreSQL Tools
+// RCS-ID: $Id: features.h,v 1.1 2004/07/25 20:33:51 andreas Exp $
+// Copyright (C) 2002 - 2004, The pgAdmin Development Team
+// This software is released under the Artistic Licence
+//
+// features.h PostgreSQL features constants
+//
+//////////////////////////////////////////////////////////////////////////
+
+enum
+{
+ FEATURE_INITIALIZED=0,
+ FEATURE_SIZE,
+ FEATURE_FILEREAD,
+ FEATURE_LAST
+};
Index: pgConn.h
===================================================================
RCS file: /projects/pgadmin3/src/include/pgConn.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -Lsrc/include/pgConn.h -Lsrc/include/pgConn.h -u -w -r1.25 -r1.26
--- src/include/pgConn.h
+++ src/include/pgConn.h
@@ -55,6 +55,7 @@
void Close();
bool HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv);
+ bool HasFeature(int feature=0);
bool ExecuteVoid(const wxString& sql);
wxString ExecuteScalar(const wxString& sql);
pgSet *ExecuteSet(const wxString& sql);
@@ -86,6 +87,8 @@
private:
PGconn *conn;
int lastResultStatus;
+ bool features[32];
+
int connStatus;
int minorVersion, majorVersion;
wxMBConv *conv;
Index: pgObject.cpp
===================================================================
RCS file: /projects/pgadmin3/src/schema/pgObject.cpp,v
retrieving revision 1.71
retrieving revision 1.72
diff -Lsrc/schema/pgObject.cpp -Lsrc/schema/pgObject.cpp -u -w -r1.71 -r1.72
--- src/schema/pgObject.cpp
+++ src/schema/pgObject.cpp
@@ -820,10 +820,12 @@
if (stats)
{
- int col=0;
- while (col++ < stats->NumCols())
+ int col;
+ for (col=0 ; col < stats->NumCols() ; col++)
+ {
if (!stats->ColName(col).IsEmpty())
statistics->AppendItem(stats->ColName(col), stats->GetVal(col));
+ }
delete stats;
}
}
Index: pgTablespace.cpp
===================================================================
RCS file: /projects/pgadmin3/src/schema/pgTablespace.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lsrc/schema/pgTablespace.cpp -Lsrc/schema/pgTablespace.cpp -u -w -r1.6 -r1.7
--- src/schema/pgTablespace.cpp
+++ src/schema/pgTablespace.cpp
@@ -16,6 +16,7 @@
// App headers
#include "pgAdmin3.h"
#include "misc.h"
+#include "features.h"
#include "pgObject.h"
#include "pgTablespace.h"
#include "pgCollection.h"
@@ -140,6 +141,34 @@
}
+void pgTablespace::ShowStatistics(frmMain *form, ctlListView *statistics)
+{
+ if (statistics)
+ {
+ if (GetConnection()->HasFeature(FEATURE_SIZE))
+ {
+ wxLogInfo(wxT("Displaying statistics for %s"), GetTypeName().c_str());
+
+ // Add the statistics view columns
+ CreateListColumns(statistics, _("Statistic"), _("Value"));
+
+ pgSet *stats = GetConnection()->ExecuteSet(
+ wxT("SELECT pg_size_pretty(pg_tablespace_size(") + GetOidStr() + wxT(")) AS ") + qtIdent(_("Tablespace Size")));
+
+ if (stats)
+ {
+ int col;
+ for (col=0 ; col < stats->NumCols() ; col++)
+ {
+ if (!stats->ColName(col).IsEmpty())
+ statistics->AppendItem(stats->ColName(col), stats->GetVal(col));
+ }
+ delete stats;
+ }
+ }
+ }
+}
+
pgObject *pgTablespace::Refresh(wxTreeCtrl *browser, const wxTreeItemId item)
{
@@ -193,3 +222,35 @@
}
return tablespace;
}
+
+
+void pgTablespace::ShowStatistics(pgCollection *collection, ctlListView *statistics)
+{
+ if (collection->GetConnection()->HasFeature(FEATURE_SIZE))
+ {
+ wxLogInfo(wxT("Displaying statistics for tablespaces"));
+
+ // Add the statistics view columns
+ statistics->ClearAll();
+ statistics->AddColumn(_("Tablespace"), 100);
+ statistics->AddColumn(_("Size"), 60);
+
+ pgSet *stats = collection->GetConnection()->ExecuteSet(
+ wxT("SELECT spcname, pg_size_pretty(pg_tablespace_size(oid)) AS size FROM pg_tablespace ORDER BY spcname"));
+
+ if (stats)
+ {
+ long pos=0;
+ while (!stats->Eof())
+ {
+ statistics->InsertItem(pos, stats->GetVal(wxT("spcname")), PGICON_STATISTICS);
+ statistics->SetItem(pos, 1, stats->GetVal(wxT("size")));
+ stats->MoveNext();
+ pos++;
+ }
+
+ delete stats;
+ }
+ }
+}
+
Index: pgCollection.cpp
===================================================================
RCS file: /projects/pgadmin3/src/schema/pgCollection.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -Lsrc/schema/pgCollection.cpp -Lsrc/schema/pgCollection.cpp -u -w -r1.34 -r1.35
--- src/schema/pgCollection.cpp
+++ src/schema/pgCollection.cpp
@@ -298,6 +298,9 @@
case PG_TABLES:
pgTable::ShowStatistics(this, statistics);
break;
+ case PG_TABLESPACES:
+ pgTablespace::ShowStatistics(this, statistics);
+ break;
default:
break;
}
Index: pgDatabase.cpp
===================================================================
RCS file: /projects/pgadmin3/src/schema/pgDatabase.cpp,v
retrieving revision 1.59
retrieving revision 1.60
diff -Lsrc/schema/pgDatabase.cpp -Lsrc/schema/pgDatabase.cpp -u -w -r1.59 -r1.60
--- src/schema/pgDatabase.cpp
+++ src/schema/pgDatabase.cpp
@@ -15,6 +15,7 @@
// App headers
#include "pgAdmin3.h"
#include "misc.h"
+#include "features.h"
#include "pgDatabase.h"
#include "pgObject.h"
#include "pgServer.h"
@@ -429,6 +430,15 @@
{
wxLogInfo(wxT("Displaying statistics for databases on ") + collection->GetServer()->GetIdentifier());
+ bool hasSize=collection->GetConnection()->HasFeature(FEATURE_SIZE);
+
+ wxString sql=wxT("SELECT datname, numbackends, xact_commit, xact_rollback, blks_read, blks_hit");
+
+ if (hasSize)
+ sql += wxT(", pg_size_pretty(pg_database_size(datid)) as size");
+
+ sql += wxT("\n FROM pg_stat_database db ORDER BY datname");
+
// Add the statistics view columns
statistics->ClearAll();
statistics->AddColumn(_("Database"), 60);
@@ -437,8 +447,10 @@
statistics->AddColumn(_("Xact Rolled Back"), 60);
statistics->AddColumn(_("Blocks Read"), 60);
statistics->AddColumn(_("Blocks Hit"), 60);
+ if (hasSize)
+ statistics->AddColumn(_("Size"), 60);
- pgSet *stats = collection->GetServer()->ExecuteSet(wxT("SELECT datname, numbackends, xact_commit, xact_rollback, blks_read, blks_hit FROM pg_stat_database ORDER BY datname"));
+ pgSet *stats = collection->GetServer()->ExecuteSet(sql);
if (stats)
{
while (!stats->Eof())
@@ -449,6 +461,9 @@
statistics->SetItem(stats->CurrentPos() - 1, 3, stats->GetVal(wxT("xact_rollback")));
statistics->SetItem(stats->CurrentPos() - 1, 4, stats->GetVal(wxT("blks_read")));
statistics->SetItem(stats->CurrentPos() - 1, 5, stats->GetVal(wxT("blks_hit")));
+ if (hasSize)
+ statistics->SetItem(stats->CurrentPos() - 1, 6, stats->GetVal(wxT("size")));
+
stats->MoveNext();
}
Index: pgTable.cpp
===================================================================
RCS file: /projects/pgadmin3/src/schema/pgTable.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -Lsrc/schema/pgTable.cpp -Lsrc/schema/pgTable.cpp -u -w -r1.54 -r1.55
--- src/schema/pgTable.cpp
+++ src/schema/pgTable.cpp
@@ -24,6 +24,7 @@
#include "pgForeignKey.h"
#include "pgCheck.h"
#include "sysSettings.h"
+#include "features.h"
pgTable::pgTable(pgSchema *newSchema, const wxString& newName)
: pgSchemaObject(newSchema, PG_TABLE, newName)
@@ -404,7 +405,7 @@
void pgTable::ShowStatistics(frmMain *form, ctlListView *statistics)
{
- DisplayStatistics(statistics,
+ wxString sql =
wxT("SELECT seq_scan AS ") + qtIdent(_("Sequential Scans")) +
wxT(", seq_tup_read AS ") + qtIdent(_("Sequential Tuples Read")) +
wxT(", idx_scan AS ") + qtIdent(_("Index Scans")) +
@@ -419,10 +420,17 @@
wxT(", toast_blks_read AS ") + qtIdent(_("Toast Blocks Read")) +
wxT(", toast_blks_hit AS ") + qtIdent(_("Toast Blocks Hit")) +
wxT(", tidx_blks_read AS ") + qtIdent(_("Toast Index Blocks Read")) +
- wxT(", tidx_blks_hit AS ") + qtIdent(_("Toast Index Blocks Hit")) + wxT("\n")
+ wxT(", tidx_blks_hit AS ") + qtIdent(_("Toast Index Blocks Hit"));
+
+ if (GetConnection()->HasFeature(FEATURE_SIZE))
+ sql += wxT(", pg_size_pretty(pg_relation_size(stat.relid)) AS ") + qtIdent(_("Table Size"));
+
+ sql += wxT("\n")
wxT(" FROM pg_stat_all_tables stat, pg_statio_all_tables statio\n")
wxT(" WHERE stat.relid = statio.relid\n")
- wxT(" AND stat.relid = ") + GetOidStr());
+ wxT(" AND stat.relid = ") + GetOidStr();
+
+ DisplayStatistics(statistics, sql);
}
@@ -511,15 +519,24 @@
{
wxLogInfo(wxT("Displaying statistics for tables on ")+ collection->GetSchema()->GetIdentifier());
+ bool hasSize=collection->GetConnection()->HasFeature(FEATURE_SIZE);
+
// Add the statistics view columns
statistics->ClearAll();
statistics->AddColumn(_("Table"), 100);
statistics->AddColumn(_("Tuples inserted"), 50);
statistics->AddColumn(_("Tuples updated"), 50);
statistics->AddColumn(_("Tuples deleted"), 50);
+ if (hasSize)
+ statistics->AddColumn(_("Size"), 60);
+
+ wxString sql=wxT("SELECT relname, n_tup_ins, n_tup_upd, n_tup_del");
+ if (hasSize)
+ sql += wxT(", pg_size_pretty(pg_relation_size(relid)) AS size");
+
+ sql += wxT("\n FROM pg_stat_all_tables ORDER BY relname");
- pgSet *stats = collection->GetDatabase()->ExecuteSet(wxT(
- "SELECT relname, n_tup_ins, n_tup_upd, n_tup_del FROM pg_stat_all_tables ORDER BY relname"));
+ pgSet *stats = collection->GetDatabase()->ExecuteSet(sql);
if (stats)
{
@@ -530,6 +547,8 @@
statistics->SetItem(pos, 1, stats->GetVal(wxT("n_tup_ins")));
statistics->SetItem(pos, 2, stats->GetVal(wxT("n_tup_upd")));
statistics->SetItem(pos, 3, stats->GetVal(wxT("n_tup_del")));
+ if (hasSize)
+ statistics->SetItem(pos, 4, stats->GetVal(wxT("size")));
stats->MoveNext();
pos++;
}
Index: pgIndex.cpp
===================================================================
RCS file: /projects/pgadmin3/src/schema/pgIndex.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -Lsrc/schema/pgIndex.cpp -Lsrc/schema/pgIndex.cpp -u -w -r1.32 -r1.33
--- src/schema/pgIndex.cpp
+++ src/schema/pgIndex.cpp
@@ -15,6 +15,7 @@
// App headers
#include "pgAdmin3.h"
#include "misc.h"
+#include "features.h"
#include "pgObject.h"
#include "pgIndex.h"
#include "pgIndexConstraint.h"
@@ -214,6 +215,13 @@
}
+void pgIndex::ShowStatistics(frmMain *form, ctlListView *statistics)
+{
+ if (GetConnection()->HasFeature(FEATURE_SIZE))
+ DisplayStatistics(statistics,
+ wxT("SELECT pg_size_pretty(pg_relation_size(") + GetOidStr() + wxT(")) AS ") + qtIdent(_("Index Size")));
+}
+
pgObject *pgIndex::Refresh(wxTreeCtrl *browser, const wxTreeItemId item)
{
Index: frmStatus.cpp
===================================================================
RCS file: /projects/pgadmin3/src/ui/frmStatus.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -Lsrc/ui/frmStatus.cpp -Lsrc/ui/frmStatus.cpp -u -w -r1.34 -r1.35
--- src/ui/frmStatus.cpp
+++ src/ui/frmStatus.cpp
@@ -19,7 +19,7 @@
// App headers
#include "frmStatus.h"
-
+#include "features.h"
// Icons
#include "images/pgAdmin3.xpm"
@@ -117,7 +117,7 @@
lockList->AddColumn(_("Query"), 500);
}
- if (connection->BackendMinimumVersion(7, 5))
+ if (connection->BackendMinimumVersion(7, 5) && connection->HasFeature(FEATURE_FILEREAD))
{
logFormat = connection->ExecuteScalar(wxT("SHOW log_line_prefix"));
if (logFormat == wxT("unset"))