Attached.

Gavin
Index: contrib/dbsize/dbsize.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/contrib/dbsize/dbsize.c,v
retrieving revision 1.10
diff -2 -c -r1.10 dbsize.c
*** contrib/dbsize/dbsize.c     23 Feb 2004 23:03:10 -0000      1.10
--- contrib/dbsize/dbsize.c     6 Aug 2004 11:24:48 -0000
***************
*** 7,11 ****
--- 7,13 ----
  #include "access/heapam.h"
  #include "catalog/catalog.h"
+ #include "catalog/catname.h"
  #include "catalog/namespace.h"
+ #include "catalog/pg_tablespace.h"
  #include "commands/dbcommands.h"
  #include "fmgr.h"
***************
*** 14,17 ****
--- 16,22 ----
  
  
+ static int64
+ get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK);
+ 
  static char *
  psnprintf(size_t len, const char *fmt,...)
***************
*** 45,52 ****
  
        Oid                     dbid;
-       char       *dbpath;
-       DIR                *dirdesc;
-       struct dirent *direntry;
        int64           totalsize;
  
        dbid = get_database_oid(NameStr(*dbname));
--- 50,59 ----
  
        Oid                     dbid;
        int64           totalsize;
+ #ifdef SYMLINK
+       Relation                dbrel;
+       HeapScanDesc    scan;
+       HeapTuple               tuple;
+ #endif
  
        dbid = get_database_oid(NameStr(*dbname));
***************
*** 56,67 ****
                        errmsg("database \"%s\" does not exist", NameStr(*dbname))));
  
!       dbpath = GetDatabasePath(dbid);
  
        dirdesc = AllocateDir(dbpath);
        if (!dirdesc)
!               ereport(ERROR,
                                (errcode_for_file_access(),
                                 errmsg("could not open directory \"%s\": %m", 
dbpath)));
! 
        totalsize = 0;
        for (;;)
--- 63,115 ----
                        errmsg("database \"%s\" does not exist", NameStr(*dbname))));
  
! #ifdef SYMLINK 
! 
!       dbrel = heap_openr(TableSpaceRelationName, AccessShareLock);    
!       scan = heap_beginscan(dbrel, SnapshotNow, 0, (ScanKey) NULL);
! 
!       totalsize = 0;
! 
!       while((tuple = heap_getnext(scan, ForwardScanDirection)))
!       {
!               Oid spcid = HeapTupleGetOid(tuple);
!               if(spcid != GLOBALTABLESPACE_OID)
!                       totalsize += get_tablespace_size(dbid, spcid, true);
!       }
!       heap_endscan(scan);
!       heap_close(dbrel, AccessShareLock);
! #else
!       /* Same as always */
!       totalsize = get_tablespace_size(dbid, DEFAULTTABLESPACE_OID, false);
! #endif
! 
!       /*
!        * We need to keep in mind that we may not be called from the database
!        * whose size we're reporting so, we need to look in every tablespace
!        * to see if our database has data in there
!        */
! 
!       PG_RETURN_INT64(totalsize);
! }
! 
! static int64
! get_tablespace_size(Oid dbid, Oid spcid, bool baddirOK)
! {
!       char            *dbpath;
!       DIR                     *dirdesc;
!       struct dirent *direntry;
!       int64           totalsize;
! 
!       dbpath = GetDatabasePath(dbid, spcid);
  
        dirdesc = AllocateDir(dbpath);
        if (!dirdesc)
!       {
!               if(baddirOK)
!                       return 0;
!               else
!                       ereport(ERROR,
                                (errcode_for_file_access(),
                                 errmsg("could not open directory \"%s\": %m", 
dbpath)));
!       }
        totalsize = 0;
        for (;;)
***************
*** 88,92 ****
                                        (errcode_for_file_access(),
                                         errmsg("could not stat \"%s\": %m", 
fullname)));
- 
                totalsize += statbuf.st_size;
                pfree(fullname);
--- 136,139 ----
***************
*** 94,102 ****
  
        FreeDir(dirdesc);
! 
!       PG_RETURN_INT64(totalsize);
  }
- 
- 
  
  /*
--- 141,146 ----
  
        FreeDir(dirdesc);
!       return (totalsize);
  }
  
  /*
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to