Add total memory output to pgsysconf*()
authorCΓ©dric Villemain <cedric@2ndquadrant.fr>
Tue, 8 Mar 2011 22:21:45 +0000 (23:21 +0100)
committerCΓ©dric Villemain <cedric@2ndquadrant.fr>
Tue, 8 Mar 2011 22:21:45 +0000 (23:21 +0100)
ChangeLog
pgfincore.c
pgfincore.sql.in

index 805723498048310534b7532ee875a6f24b0a5693..d66a3097271e02d21104c20655c073b78a9163c1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,8 @@
   * 0.5.0 - Output varbit containing vector information with pgmincore*()
                  - Add Debian packaging (Dimitri Fontaine)
                  - Update to work with PostgreSQL >= 9.1 (Jeff Janes)
-                 - Add function pgsysconf_pretty()
+          - Add total number of pages of memory with pgsysconf()
+          - Add function pgsysconf_pretty()
 
 04/30/2010 CΓ©dric Villemain <cedric@villemain.org>
 
index 53c670a0597d8f4b4f20e44fe1dae5a07825120d..21603f9b22077945fc8fc0c81d93ff007d0d9cdf 100644 (file)
@@ -41,7 +41,7 @@ PG_MODULE_MAGIC;
 #endif
 /* } */
 
-#define PGSYSCONF_COLS  2
+#define PGSYSCONF_COLS  3
 #define PGFINCORE_COLS  6
 
 /*
@@ -53,7 +53,7 @@ PG_MODULE_MAGIC;
 typedef struct
 {
        int action;                             /* the action  mincore, fadvise...*/
-       Relation rel;                           /* the relation */
+       Relation rel;                   /* the relation */
        unsigned int segcount;  /* the segment current number */
        char *relationpath;             /* the relation path */
 } pgfincore_fctx;
@@ -103,16 +103,18 @@ pgsysconf(PG_FUNCTION_ARGS)
 
        tupdesc = CreateTemplateTupleDesc(PGSYSCONF_COLS, false);
        TupleDescInitEntry(tupdesc, (AttrNumber) 1, "block_size",  INT8OID, -1, 0);
-       TupleDescInitEntry(tupdesc, (AttrNumber) 2, "block_free",  INT8OID, -1, 0);
+    TupleDescInitEntry(tupdesc, (AttrNumber) 2, "block_free",  INT8OID, -1, 0);
+    TupleDescInitEntry(tupdesc, (AttrNumber) 3, "total_blocks",  INT8OID, -1, 0);
        tupdesc = BlessTupleDesc(tupdesc);
 
        values[0] = Int64GetDatum(sysconf(_SC_PAGESIZE));  /* Page size */
-       values[1] = Int64GetDatum(sysconf(_SC_AVPHYS_PAGES));  /* free page in memory */
+    values[1] = Int64GetDatum(sysconf(_SC_AVPHYS_PAGES));  /* free page in memory */
+    values[2] = Int64GetDatum(sysconf(_SC_PHYS_PAGES));  /* total memory */
        memset(nulls, 0, sizeof(nulls));
 
        tuple = heap_form_tuple(tupdesc, values, nulls);
-       elog(DEBUG1, "pgsysconf: page_size %lld bytes, free page in memory %lld",
-            (int64) values[0], (int64) values[1]);
+       elog(DEBUG1, "pgsysconf: page_size %lld bytes, free page in memory %lld, total memory pages %lld",
+            (int64) values[0], (int64) values[1], (int64) values[2]);
        PG_RETURN_DATUM( HeapTupleGetDatum(tuple) );
 }
 
index e87dba5b7e11e3f9b0c9c71c9189c5e047c81958..6b4c9faaa671901ab7984a498ff889b186f674c4 100644 (file)
@@ -1,19 +1,22 @@
 SET search_path = public;
 
 CREATE OR REPLACE FUNCTION
-pgsysconf(OUT block_size bigint,
-                 OUT block_free bigint)
+pgsysconf(OUT block_size   bigint,
+          OUT block_free   bigint,
+          OUT total_blocks bigint)
 RETURNS record
 AS 'MODULE_PATHNAME'
 LANGUAGE C;
 
 CREATE OR REPLACE FUNCTION
-pgsysconf_pretty(OUT block_size  text,
-                 OUT free_memory text)
+pgsysconf_pretty(OUT block_size   text,
+                 OUT free_memory  text,
+                 OUT total_memory text)
 RETURNS record
 AS '
 select pg_size_pretty(block_size) as block_size,
-       pg_size_pretty(block_free * block_size) as free_memory
+       pg_size_pretty(block_free * block_size) as free_memory,
+       pg_size_pretty(total_blocks * block_size) as total_memory
 from pgsysconf()'
 LANGUAGE SQL;