Mainly information are following items
-- pg_statsinfo1.0 (for PG8.3)
---------------------------------------- DB Activity Information ---------------------------------------- Database Size : 52440684 Connection Average Number : 1 Database Frozen Xid(Age) : 5233 Commit Number : 5049 Rollback Number : 0 Block Read : 921 Block Hit : 106000 Cache Hit Ratio : 99.14 Return Tuples : 197067 Fetched Tuples : 18468 INSERT Tuples : 5006 UPDATE Tuples : 15007 DELETE Tuples : 0 Total User Table Number : 4 --------------------------------------------------------------------- Instance Disk Usage Information --------------------------------------------------------------------- Space_name Device_ID Device_name Location USED AVAIL TOTAL RATIO --------------------------------------------------------------------------------------------------------------------------------- pg_default 2080 /dev/sdc /array1/data 112 GB 474 GB 586 GB 19.16 pg_global 2080 /dev/sdc /array1/data 112 GB 474 GB 586 GB 19.16 2097 /dev/sdd1 /var/lib/pgsql/archive_dir/ 32 MB 952 MB 984 MB 3.25 2051 /dev/root /array1/data/pg_xlog 27 GB 38 GB 64 GB 41.82 --------------------------------------- Fragmented Table worst 10 --------------------------------------- Table name dead record live record dead record ratio ----------------------------------------------------------------------------- accounts 4476 300000 1.49 pg_statistic 7 361 1.94 pg_amop 0 347 0.00 pg_type 0 289 0.00 pg_proc 0 2164 0.00 pg_class 0 239 0.00 pg_shdepend 0 1 0.00 pg_cast 0 191 0.00 pg_namespace 0 6 0.00 pg_index 0 93 0.00 --------------------------------------- Much Access Table Top 10 --------------------------------------- Table name seq scanread records records per scan -------------------------------------------------------------------------------- tellers 5462 150000 27.46 branches 8088 15003 1.85 pg_class 23 5497 239.00 pg_attribute 2 3696 1848.00 pg_index 5 465 93.00 pg_database 10 41 4.10 pg_am 8 8 1.00 pg_tablespace 2 4 2.00 accounts 0 0 0.00 pg_authid 1 0 0.00
-- check exapmle -- $ rpm -qa | grep Text-Template perl-Text-Template-1.44-1.2.el5.rf $ rpm -qa | grep DBD perl-DBD-Pg-1.49-1.fc6 $ rpm -qa | grep DBI perl-DBI-1.52-1.fc6If they are not installed, please get sources or RPM packeages and install them. You can get RPM packages from following Link. (If you want to install pg_statsinfo by RPM package, you have to install perl modlues by RPM package.)
# rpm -i perl-Text-Template-1.44-1.2.el5.rf.noarch.rpm # rpm -i perl-DBD-Pg-1.49-1.fc6.x86_64.rpm # rpm -i perl-DBI-1.52-1.fc6.x86_64.rpm
psql -dThen, create role with superuser-privilege on monitoring-target-DB.ALTER USER user_name SET search_path = statsinfo, "$user", public;
$ psql -dCREATE ROLE some_user SUPERUSER;
t_dbconn descrition Column | Type | description --------------------+---------+------------------- dbid | bigint | DB's ID. It is sequence. Please set "default" on inserting. dbname | text | Target DB name. hostname | text | Host name. Set IP or name port | integer | Port number of DB Cluster. Normally 5432. username | text | User who connect to Traget DB. Required superuser-privilege. password | text | Password to connect Target DB. It is stored with encryption. is_snapshot_target | boolean | Flag whether targte the automatic snapshot or not. As will hereinafter be described in detail.Follwoing example is user "postgres" will connect to "target" DB on DB cluster active on "5432" on "localhost" host by using "passwd".
INSERT INTO statsinfo.t_dbconn VALUES (default, 'target', 'localhost', 5432, 'postgres', 'passwd', 't'); INSERT 1 0
$ psql stats =# SELECT statsinfo.get_stats(); get_stats ----------- t (1 row) =# SELECT statsinfo.get_stats(1); get_stats ----------- t (1 row)Return 't' if successed. DBID is confirmed by following SQL.
=# SELECT dbid, dbname, hostname, port, username FROM statsinfo.t_dbconn; dbid | dbname | hostname | port | username ------+--------+--------------+------+---------- 1 | target | localhost | 5432 | postgres 2 | user1 | 172.20.16.99 | 5433 | admin
=# SELECT * FROM statsinfo.snapshot_history ; snapshot_id | snapshot_date | hostname | dbname | port | level | description -------------+------------------------+-----------+--------+------+-------+------------- 1 | 2009-03-04 15:20:02+09 | localhost | target | 5432 | 0 | 2 | 2009-03-04 15:20:32+09 | localhost | target | 5432 | 0 | 3 | 2009-03-04 15:20:33+09 | localhost | target | 5432 | 0 |
# id specified pg_make_report.pl --host=localhost --dbname=stats --port=5432 --user=postgres --output-prefix=/tmp/report.log \ --startid=1 --endid=10 --template=$REPORT/pg_statsreport.tmpl # timestamp specified pg_make_report.pl --host=localhost --dbname=stats --port=5432 --user=postgres --output-prefix=/tmp/report.log \ --startdate='2009-03-01 10:00:00' --enddate='2009-03-02 10:00:00' --template=$REPORT/pg_statsreport.tmpl # timestamp and dbid specified pg_make_report.pl --host=localhost --dbname=stats --port=5432 --user=postgres --output-prefix=/tmp/report.log \ --startdate='2009-03-01 10:00:00' --enddate='2009-03-02 10:00:00' --targetdbid=1 --template=$REPORT/pg_statsreport.tmpl # timestamp and hostname, port number and target dbname specified pg_make_report.pl --host=localhost --dbname=stats --port=5432 --user=postgres --output-prefix=/tmp/report.log \ --startdate='2009-03-01 10:00:00' --enddate='2009-03-02 10:00:00' --targetstring=localhost:5432/target_db --template=$REPORT/pg_statsreport.tmplAbout how to read report、please see this documentation.
=# SELECT statsinfo.delete_stats(11); delete_stats -------------- t (1 row)If you want to delete some snapshot in specified date range, use snapshot_hisyory view.
# In case that we delete some snapshot older than certain date (ex '2009-03-04 15:21:00'). =# SELECT * FROM statsinfo.snapshot_history ; snapshot_id | snapshot_date | hostname | dbname | port | level | description -------------+------------------------+-----------+--------+------+-------+------------- 1 | 2009-03-04 15:20:02+09 | localhost | target | 5432 | 0 | 2 | 2009-03-04 15:20:32+09 | localhost | target | 5432 | 0 | 3 | 2009-03-04 15:20:33+09 | localhost | target | 5432 | 0 | 4 | 2009-03-04 15:20:40+09 | localhost | target | 5432 | 0 | 5 | 2009-03-04 15:21:35+09 | localhost | target | 5432 | 0 | (5 rows) =# SELECT statsinfo.delete_stats(snapshot_id) FROM snapshot_history WHERE snapshot_date <='2009-03-04 15:21:00'; delete_stats -------------- t t t t (4 rows) =# SELECT * FROM statsinfo.snapshot_history ; snapshot_id | snapshot_date | hostname | dbname | port | level | description -------------+------------------------+-----------+--------+------+-------+------------- 5 | 2009-03-04 15:21:35+09 | localhost | target | 5432 | 0 | (1 row)
## In case you install pg_statsinfo by RPM $ psql -f /usr/share/pgsql/contrib/pgstatsinfo/uninstall_stats_info.sql -d stats $ psql -f /usr/share/pgsql/contrib/pgstatsinfo/uninstall_target_db.sql -d targetIf you use log-filter, stop PostgreSQL server and restart without log-filter. And if you use RPMs, uninstall pg_statsinfo-*.rpm by using "rpm -e"