SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
pg proctab
Accessing System Stats in PostgreSQL


           Mark Wong
      markwkm@postgresql.org

        LinuxFest Northwest 2009


         April 25 - 26, 2009
Slides available on slideshare




   http://www.slideshare.net/markwkm
What is pg proctab?



  Collection of 4 C stored functions:
        pg proctab
    ◮

        pg cputime
    ◮

        pg loadavg
    ◮

        pg memusage
    ◮

  Download it from:
  http://git.postgresql.org/gitweb?p=pg_proctab.git
  Change it:
  git clone git://git.postgresql.org/git/pg_proctab.git
What can do you with pg proctab?




        Query operating system process table
    ◮

        Query operating system statistics
    ◮
              Processor time
          ◮

              Memory usage
          ◮

              Load averages
          ◮


  Don’t forget you can query the PostgreSQL system catalog tables
  for database statistics, i.e. pg stat activity,
  pg stat all tables, pg stat all indexes
pg cputime() Example




  SELECT *
  FROM pg_cputime();

    user | nice | system |       idle    | iowait
  --------+--------+--------+------------+--------
   681317 | 109924 | 395481 | 1466101128 | 462661
  (1 row)
pg cputime() Column Description




  From Linux kernel source code at
  Documentation/filesystems/proc.txt:
  user: normal processes executing in user mode
  nice: niced processes executing in user mode
  system: processes executing in kernel mode
  idle: twiddling thumbs
  iowait: waiting for I/O to complete
pg loadavg() Example




  SELECT *
  FROM pg_loadavg();

   load1 | load5 | load15 | last_pid
  -------+-------+--------+----------
    0.99 | 0.78 |    0.67 |    27719
  (1 row)
pg loadavg() Column Description




  load1: load average of last minute
  load5: load average of last 5 minutes
  load15: load average of last 15 minutes
  last pid: last pid running
pg memusage() Example




  SELECT *
  FROM pg_memusage();

   memused | memfree | memshared | membuffers | memcached | swapused | swapfree | swapcached
  ---------+---------+-----------+------------+-----------+----------+----------+------------
   3809140 | 224084 |          0|       60656 |   2389700 |       76 | 8385844 |           0
  (1 row)
pg memusage() Column Description


  Paraphrased from Linux kernel source code at
  Documentation/filesystems/proc.txt:
  memused: Total physical RAM used
  memfree: Total physical RAM not used
  memshared: Not used, always 0. (I don’t remember why. . . )
  membuffers: Temporary storage for raw disk blocks
  memcached: In-memory cache for files read from disk
  swapused: Total swap space used
  swapfree: Memory evicted from RAM that is now temporary on
  disk
  swapcached: Memory that was swapped out, now swapped in but
  still in swap
pg proctab() Partial Column Description

   Everything from the operating system such as /proc/<pid>/stat,
   /proc/<pid>/io and /proc/<pid>/cmdline as well as data
   from PostgreSQL system catalog such as pg stat activity table
   are available but we’ll only cover some of the fields here:
   Informative:
         pid
     ◮

         comm - filename of the executable
     ◮

         fullcomm (/proc/<pid>/cmdline)
     ◮

         uid
     ◮

         username
     ◮

   Processor:
         utime - user mode jiffies
     ◮

         stime - kernel mode jiffies
     ◮

   ...
pg proctab() Partial Column Description (cont.)

   Memory:
          vsize - virtual memory size
     ◮

          rss - resident set memory size
     ◮

   I/O:
          syscr - number of read I/O operations
     ◮

          syscw - number of write I/O operations
     ◮

          reads - number of bytes which this process really did cause to
     ◮
          be fetched from the storage layer
          writes - number of bytes which this process really did cause to
     ◮
          be sent from the storage layer
          cwrites - number of bytes which this process caused to not
     ◮
          happen, by truncating pagecache
pg proctab() Example 1




  SELECT datname, procpid, usesysid, usename, uid, username
  FROM pg_stat_activity, pg_proctab()
  WHERE procpid = pid;

   datname | procpid | usesysid | usename | uid | username
  ---------+---------+----------+----------+-----+----------
   markwkm |   27801 |       10 | markwkm | 500 | markwkm
   dbt3    |   27787 |    16770 | postgres | 500 | markwkm
  (2 rows)
pg proctab() Example 2



  SELECT datname, procpid, processor, state, fullcomm
  FROM pg_stat_activity, pg_proctab()
  WHERE procpid = pid;

   datname | procpid | processor | state |                 fullcomm
  ---------+---------+-----------+-------+------------------------------------------
   markwkm |   27801 |         0|R       | postgres: markwkm markwkm [local] SELECT
   dbt3    |   29325 |         3|R       | postgres: markwkm dbt3 [local] SELECT
   dbt3    |   29327 |         0|R       | postgres: markwkm dbt3 [local] SELECT
   dbt3    |   29333 |         3|R       | postgres: markwkm dbt3 [local] SELECT
   dbt3    |   29328 |         2|R       | postgres: markwkm dbt3 [local] SELECT
   dbt3    |   29329 |         0|R       | postgres: markwkm dbt3 [local] SELECT
   dbt3    |   29324 |         3|R       | postgres: markwkm dbt3 [local] SELECT
   dbt3    |   29331 |         0|R       | postgres: markwkm dbt3 [local] SELECT
   dbt3    |   27787 |         1|S       | postgres: postgres dbt3 [local] idle
  (9 rows)
__      __     /                    
         / ~~~/  . o O | Let’s try something |
   ,----(      oo    )   | more useful.         |
  /      __      __/                        /
 /|          ( |(
^    /___ / |
   |__|   |__|-quot;
__      __      /                     
         / ~~~/  . o O | Collecting statitiscs |
   ,----(      oo    )   | from a query.          |
  /      __      __/                          /
 /|          ( |(
^    /___ / |
   |__|   |__|-quot;
The following examples are in the pg proctab contrib directory.
Identify yourself.


   SELECT *
   FROM pg_backend_pid();

    pg_backend_pid
   ----------------
             4509
   (1 row)


   Note: The following series of SQL statements are made from the
   same psql session. Otherwise the pg backend pid will change. This
   is important because stats are collected in the operating system by
   process ID (pid).
Take a snapshot before the running the query



   i ps_procstat-snap.sql

   BEGIN

    ps_snap_stats
   ---------------
                1
   (1 row)

   COMMIT
Execute the query

   Don’t focus too much on the actual query, the idea is that is you
   want to collect statistics for a single query:
   SELECT   nation,
            o_year,
            Sum(amount) AS sum_profit
   FROM     (SELECT n_name                                                          AS nation,
                    Extract(YEAR FROM o_orderdate)                                  AS o_year,
                    l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity AS amount
             FROM   part,
                    supplier,
                    lineitem,
                    partsupp,
                    orders,
                    nation
             WHERE s_suppkey = l_suppkey
             AND ps_suppkey = l_suppkey
             AND ps_partkey = l_partkey
             AND p_partkey = l_partkey
             AND o_orderkey = l_orderkey
             AND s_nationkey = n_nationkey
             AND p_name LIKE ’%white%’) AS profit
   GROUP BY nation,
            o_year
   ORDER BY nation,
            o_year DESC;
Take a snapshot after the running the query



   i ps_procstat-snap.sql

   BEGIN

    ps_snap_stats
   ---------------
                2
   (1 row)

   COMMIT
Calculate Processor Utilization

   $ ./ps-processor-utilization.sh 4590 1 2
   Processor Utilization = 1.00 %


   Example (partial):
   SELECT stime, utime, stime + utime AS total,
          extract(epoch FROM time)
   FROM ps_snaps a, ps_procstat b
   WHERE pid = ${PID}
     AND a.snap = b.snap
     AND a.snap = ${SNAP1}


   TIMEDIFF=‘echo quot;scale = 2; (${TIME2} - ${TIME1}) * ${HZ}quot; | bc -l‘

   U=‘echo quot;scale = 2; (${TOTAL2} - ${TOTAL1}) / ${TIMEDIFF} * 100quot; | bc -l‘
Calculate Disk Utilization


   $ ./ps-io-utilization.sh 4590 1 2
   Reads = 276981
   Writes = 63803
   Reads (Bytes) = 2164604928
   Writes (Bytes) = 508166144
   Cancelled (Bytes) = 36880384

   SELECT syscr, syscw, reads, writes, cwrites
   FROM ps_snaps a, ps_procstat b
   WHERE pid = ${PID}
     AND a.snap = b.snap
     AND a.snap = ${SNAP1}
__      __     /                
         / ~~~/  . o O | Creating Custom |
   ,----(      oo    )   | Reports!         |
  /      __      __/                    /
 /|          ( |(
^    /___ / |
   |__|   |__|-quot;
Another example from pg proctab contrib



   $ ./ps-report.pl 4590 1 2



             __      __      /                      
            / ~~~/  . o O | Warning! Too much data |
      ,----(      oo    )   | to fit on the screen! |
     /      __      __/                           /
    /|          ( |(
   ^    /___ / |
      |__|   |__|-quot;
Creating Reports: Section 1


   Database       : dbt3
   Snapshot Start : 2009-04-18 00:43:56.716034-07
   Snapshot End   : 2009-04-18 00:45:17.031167-07

   -------------------
   Database Statistics
   -------------------
   Commits     :0
   Rollbacks   :2
   Blocks Read : 213295
   Blocks Hit : 1679509
Creating Reports: Section 2
   ================
   Table Statistics
   ================
   ------------------------------------------ -------- ------------ -------- ------------- --------- --------
   Schema.Relation                            Seq Scan Seq Tup Read Idx Scan Idx Tup Fetch N Tup Ins N Tup Up
   ------------------------------------------ -------- ------------ -------- ------------- --------- --------
   information_schema.sql_features                   0            0        0             0         0
   information_schema.sql_implementation_info        0            0        0             0         0
   information_schema.sql_languages                  0            0        0             0         0
   information_schema.sql_packages                   0            0        0             0         0
   information_schema.sql_parts                      0            0        0             0         0
   information_schema.sql_sizing                     0            0        0             0         0
   information_schema.sql_sizing_profiles            0            0        0             0         0
   pg_catalog.pg_aggregate                           0            0        2             2         0
   pg_catalog.pg_am                                  1            1        0             0         0
   pg_catalog.pg_amop                                0            0       19            46         0
   pg_catalog.pg_amproc                              0            0       11            11         0
   pg_catalog.pg_attrdef                             0            0        1             2         0
   pg_catalog.pg_attribute                           0            0      137           331         0
   pg_catalog.pg_auth_members                        0            0        0             0         0
   pg_catalog.pg_authid                              3            2        0             0         0
   pg_catalog.pg_autovacuum                          0            0        0             0         0
   pg_catalog.pg_cast                                0            0      160            51         0
   pg_catalog.pg_class                               3          747      101            88         0
   pg_catalog.pg_constraint                          0            0        0             0         0
   pg_catalog.pg_conversion                          0            0        0             0         0
   pg_catalog.pg_database                            5           12        0             0         0
   pg_catalog.pg_depend                              0            0        0             0         0
   pg_catalog.pg_description                         0            0        0             0         0
   pg_catalog.pg_index                               2          200       39            50         0

   ...
Creating Reports: Section 2 - Falling off the right side...




         N Tup Upd
     ◮

         N Tup Del
     ◮

         Last Vacuum
     ◮

         Last Autovacuum
     ◮

         Last Analyze
     ◮

         Last Autoanalyze
     ◮
Creating Reports: Section 3
   ================
   Index Statistics
   ================
   ------------------------------------------------------------ -------- ------------ -------------
   Schema.Relation.Index                                        Idx Scan Idx Tup Read Idx Tup Fetch
   ------------------------------------------------------------ -------- ------------ -------------
   pg_catalog.pg_aggregate.pg_aggregate_fnoid_index                    2            2             2
   pg_catalog.pg_am.pg_am_name_index                                   0            0             0
   pg_catalog.pg_am.pg_am_oid_index                                    0            0             0
   pg_catalog.pg_amop.pg_amop_opc_strat_index                         12           36            36
   pg_catalog.pg_amop.pg_amop_opr_opc_index                            7           10            10
   pg_catalog.pg_amproc.pg_amproc_opc_proc_index                      11           11            11
   pg_catalog.pg_attrdef.pg_attrdef_adrelid_adnum_index                1            2             2
   pg_catalog.pg_attrdef.pg_attrdef_oid_index                          0            0             0
   pg_catalog.pg_attribute.pg_attribute_relid_attnam_index             0            0             0
   pg_catalog.pg_attribute.pg_attribute_relid_attnum_index           137          331           331
   pg_catalog.pg_auth_members.pg_auth_members_member_role_index        0            0             0
   pg_catalog.pg_auth_members.pg_auth_members_role_member_index        0            0             0
   pg_catalog.pg_authid.pg_authid_oid_index                            0            0             0
   pg_catalog.pg_authid.pg_authid_rolname_index                        0            0             0
   pg_catalog.pg_autovacuum.pg_autovacuum_vacrelid_index               0            0             0
   pg_catalog.pg_cast.pg_cast_oid_index                                0            0             0
   pg_catalog.pg_cast.pg_cast_source_target_index                    160           51            51
   pg_catalog.pg_class.pg_class_oid_index                             71           71            71
   pg_catalog.pg_class.pg_class_relname_nsp_index                     30           17            17
   pg_catalog.pg_constraint.pg_constraint_conname_nsp_index            0            0             0
   pg_catalog.pg_constraint.pg_constraint_conrelid_index               0            0             0
   pg_catalog.pg_constraint.pg_constraint_contypid_index               0            0             0
   pg_catalog.pg_constraint.pg_constraint_oid_index                    0            0             0
   pg_catalog.pg_conversion.pg_conversion_default_index                0            0             0

   ...
What else can we do with pg proctab?




   Enable pg top to monitor remote databases by providing access to
   the database system’s operating system process table.
pg top
__      __
         / ~~~/  . o O ( Thank you! )
   ,----(      oo    )
  /      __      __/
 /|          ( |(
^    /___ / |
   |__|   |__|-quot;
Acknowledgements



  Haley Jane Wakenshaw

            __      __
           / ~~~/ 
     ,----(      oo    )
    /      __      __/
   /|          ( |(
  ^    /___ / |
     |__|   |__|-quot;
License




   This work is licensed under a Creative Commons Attribution 3.0
   Unported License. To view a copy of this license, (a) visit
   http://creativecommons.org/licenses/by/3.0/us/; or, (b)
   send a letter to Creative Commons, 171 2nd Street, Suite 300, San
   Francisco, California, 94105, USA.

Contenu connexe

Tendances

Apache Hadoop for System Administrators
Apache Hadoop for System AdministratorsApache Hadoop for System Administrators
Apache Hadoop for System AdministratorsAllen Wittenauer
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationAlexey Lesovsky
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Alexey Lesovsky
 
Tibero sql execution plan guide en
Tibero sql execution plan guide enTibero sql execution plan guide en
Tibero sql execution plan guide enssusered8afe
 
Linea de comandos bioface zem800
Linea de comandos bioface zem800Linea de comandos bioface zem800
Linea de comandos bioface zem800thomaswarnerherrera
 
Quick reference for mongo shell commands
Quick reference for mongo shell commandsQuick reference for mongo shell commands
Quick reference for mongo shell commandsRajkumar Asohan, PMP
 
PostgreSQL - Haute disponibilité avec Patroni
PostgreSQL - Haute disponibilité avec PatroniPostgreSQL - Haute disponibilité avec Patroni
PostgreSQL - Haute disponibilité avec Patronislardiere
 
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQPostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQPostgreSQL-Consulting
 
Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)Anastasia Lubennikova
 
List command linux fidora
List command linux fidoraList command linux fidora
List command linux fidoraJinyuan Loh
 
Terminal linux commands_ Fedora based
Terminal  linux commands_ Fedora basedTerminal  linux commands_ Fedora based
Terminal linux commands_ Fedora basedNavin Thapa
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteAllen Wittenauer
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PgDay.Seoul
 
計算機性能の限界点とその考え方
計算機性能の限界点とその考え方計算機性能の限界点とその考え方
計算機性能の限界点とその考え方Naoto MATSUMOTO
 

Tendances (18)

Apache Hadoop for System Administrators
Apache Hadoop for System AdministratorsApache Hadoop for System Administrators
Apache Hadoop for System Administrators
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming Replication
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Tibero sql execution plan guide en
Tibero sql execution plan guide enTibero sql execution plan guide en
Tibero sql execution plan guide en
 
Linea de comandos bioface zem800
Linea de comandos bioface zem800Linea de comandos bioface zem800
Linea de comandos bioface zem800
 
Quick reference for mongo shell commands
Quick reference for mongo shell commandsQuick reference for mongo shell commands
Quick reference for mongo shell commands
 
PostgreSQL - Haute disponibilité avec Patroni
PostgreSQL - Haute disponibilité avec PatroniPostgreSQL - Haute disponibilité avec Patroni
PostgreSQL - Haute disponibilité avec Patroni
 
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQPostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQ
 
PgconfSV compression
PgconfSV compressionPgconfSV compression
PgconfSV compression
 
Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)
 
List command linux fidora
List command linux fidoraList command linux fidora
List command linux fidora
 
Terminal linux commands_ Fedora based
Terminal  linux commands_ Fedora basedTerminal  linux commands_ Fedora based
Terminal linux commands_ Fedora based
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개PostgreSQL 9.6 새 기능 소개
PostgreSQL 9.6 새 기능 소개
 
Pgcenter overview
Pgcenter overviewPgcenter overview
Pgcenter overview
 
8.4 Upcoming Features
8.4 Upcoming Features 8.4 Upcoming Features
8.4 Upcoming Features
 
計算機性能の限界点とその考え方
計算機性能の限界点とその考え方計算機性能の限界点とその考え方
計算機性能の限界点とその考え方
 
Backups
BackupsBackups
Backups
 

Similaire à Access PostgreSQL System Stats with pg_proctab

pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
What’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorWhat’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorMasahiko Sawada
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoPostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoMark Wong
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Alexey Lesovsky
 
Best Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesBest Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesOdoo
 
Deep dive into PostgreSQL internal statistics / Алексей Лесовский (PostgreSQL...
Deep dive into PostgreSQL internal statistics / Алексей Лесовский (PostgreSQL...Deep dive into PostgreSQL internal statistics / Алексей Лесовский (PostgreSQL...
Deep dive into PostgreSQL internal statistics / Алексей Лесовский (PostgreSQL...Ontico
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and ArchitectureSidney Chen
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016Brendan Gregg
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak PROIDEA
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2PgTraining
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby SystemsEngine Yard
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...Mark Wong
 
Tests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTapTests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTapRodolphe Quiédeville
 
LISA2019 Linux Systems Performance
LISA2019 Linux Systems PerformanceLISA2019 Linux Systems Performance
LISA2019 Linux Systems PerformanceBrendan Gregg
 

Similaire à Access PostgreSQL System Stats with pg_proctab (20)

pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
What’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributorWhat’s new in 9.6, by PostgreSQL contributor
What’s new in 9.6, by PostgreSQL contributor
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 HowtoPostgreSQL Portland Performance Practice Project - Database Test 2 Howto
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Best Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesBest Practices in Handling Performance Issues
Best Practices in Handling Performance Issues
 
Deep dive into PostgreSQL internal statistics / Алексей Лесовский (PostgreSQL...
Deep dive into PostgreSQL internal statistics / Алексей Лесовский (PostgreSQL...Deep dive into PostgreSQL internal statistics / Алексей Лесовский (PostgreSQL...
Deep dive into PostgreSQL internal statistics / Алексей Лесовский (PostgreSQL...
 
Explain this!
Explain this!Explain this!
Explain this!
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and Architecture
 
Debug generic process
Debug generic processDebug generic process
Debug generic process
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby Systems
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
 
Pro PostgreSQL
Pro PostgreSQLPro PostgreSQL
Pro PostgreSQL
 
Tests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTapTests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTap
 
test
testtest
test
 
LISA2019 Linux Systems Performance
LISA2019 Linux Systems PerformanceLISA2019 Linux Systems Performance
LISA2019 Linux Systems Performance
 

Plus de Mark Wong

OHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryOHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryMark Wong
 
OHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportOHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportMark Wong
 
collectd & PostgreSQL
collectd & PostgreSQLcollectd & PostgreSQL
collectd & PostgreSQLMark Wong
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQLMark Wong
 
PGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appPGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appMark Wong
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLMark Wong
 
Developing PGTop for Android
Developing PGTop for AndroidDeveloping PGTop for Android
Developing PGTop for AndroidMark Wong
 
Pg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationPg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningPostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningMark Wong
 
Filesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveFilesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...Mark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundPostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundMark Wong
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...Mark Wong
 
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabpg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabMark Wong
 
Linux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreLinux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreMark Wong
 
pg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLpg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLMark Wong
 
What Is Going On?
What Is Going On?What Is Going On?
What Is Going On?Mark Wong
 

Plus de Mark Wong (17)

OHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 MockumentaryOHAI, my name is Chelnik! PGCon 2014 Mockumentary
OHAI, my name is Chelnik! PGCon 2014 Mockumentary
 
OHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 ReportOHAI, my name is Chelnik! Postgres Open 2013 Report
OHAI, my name is Chelnik! Postgres Open 2013 Report
 
collectd & PostgreSQL
collectd & PostgreSQLcollectd & PostgreSQL
collectd & PostgreSQL
 
Android & PostgreSQL
Android & PostgreSQLAndroid & PostgreSQL
Android & PostgreSQL
 
PGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this appPGTop for Android: Things I learned making this app
PGTop for Android: Things I learned making this app
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
Developing PGTop for Android
Developing PGTop for AndroidDeveloping PGTop for Android
Developing PGTop for Android
 
Pg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentationPg in-the-brazilian-armed-forces-presentation
Pg in-the-brazilian-armed-forces-presentation
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 TuningPostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
PostgreSQL Portland Performance Practice Project - Database Test 2 Tuning
 
Filesystem Performance from a Database Perspective
Filesystem Performance from a Database PerspectiveFilesystem Performance from a Database Perspective
Filesystem Performance from a Database Perspective
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 BackgroundPostgreSQL Portland Performance Practice Project - Database Test 2 Background
PostgreSQL Portland Performance Practice Project - Database Test 2 Background
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
PostgreSQL Portland Performance Practice Project - Database Test 2 Series Ove...
 
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctabpg_top is 'top' for PostgreSQL: pg_top + pg_proctab
pg_top is 'top' for PostgreSQL: pg_top + pg_proctab
 
Linux Filesystems, RAID, and more
Linux Filesystems, RAID, and moreLinux Filesystems, RAID, and more
Linux Filesystems, RAID, and more
 
pg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQLpg_top is 'top' for PostgreSQL
pg_top is 'top' for PostgreSQL
 
What Is Going On?
What Is Going On?What Is Going On?
What Is Going On?
 

Dernier

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Dernier (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

Access PostgreSQL System Stats with pg_proctab

  • 1. pg proctab Accessing System Stats in PostgreSQL Mark Wong markwkm@postgresql.org LinuxFest Northwest 2009 April 25 - 26, 2009
  • 2. Slides available on slideshare http://www.slideshare.net/markwkm
  • 3. What is pg proctab? Collection of 4 C stored functions: pg proctab ◮ pg cputime ◮ pg loadavg ◮ pg memusage ◮ Download it from: http://git.postgresql.org/gitweb?p=pg_proctab.git Change it: git clone git://git.postgresql.org/git/pg_proctab.git
  • 4. What can do you with pg proctab? Query operating system process table ◮ Query operating system statistics ◮ Processor time ◮ Memory usage ◮ Load averages ◮ Don’t forget you can query the PostgreSQL system catalog tables for database statistics, i.e. pg stat activity, pg stat all tables, pg stat all indexes
  • 5. pg cputime() Example SELECT * FROM pg_cputime(); user | nice | system | idle | iowait --------+--------+--------+------------+-------- 681317 | 109924 | 395481 | 1466101128 | 462661 (1 row)
  • 6. pg cputime() Column Description From Linux kernel source code at Documentation/filesystems/proc.txt: user: normal processes executing in user mode nice: niced processes executing in user mode system: processes executing in kernel mode idle: twiddling thumbs iowait: waiting for I/O to complete
  • 7. pg loadavg() Example SELECT * FROM pg_loadavg(); load1 | load5 | load15 | last_pid -------+-------+--------+---------- 0.99 | 0.78 | 0.67 | 27719 (1 row)
  • 8. pg loadavg() Column Description load1: load average of last minute load5: load average of last 5 minutes load15: load average of last 15 minutes last pid: last pid running
  • 9. pg memusage() Example SELECT * FROM pg_memusage(); memused | memfree | memshared | membuffers | memcached | swapused | swapfree | swapcached ---------+---------+-----------+------------+-----------+----------+----------+------------ 3809140 | 224084 | 0| 60656 | 2389700 | 76 | 8385844 | 0 (1 row)
  • 10. pg memusage() Column Description Paraphrased from Linux kernel source code at Documentation/filesystems/proc.txt: memused: Total physical RAM used memfree: Total physical RAM not used memshared: Not used, always 0. (I don’t remember why. . . ) membuffers: Temporary storage for raw disk blocks memcached: In-memory cache for files read from disk swapused: Total swap space used swapfree: Memory evicted from RAM that is now temporary on disk swapcached: Memory that was swapped out, now swapped in but still in swap
  • 11. pg proctab() Partial Column Description Everything from the operating system such as /proc/<pid>/stat, /proc/<pid>/io and /proc/<pid>/cmdline as well as data from PostgreSQL system catalog such as pg stat activity table are available but we’ll only cover some of the fields here: Informative: pid ◮ comm - filename of the executable ◮ fullcomm (/proc/<pid>/cmdline) ◮ uid ◮ username ◮ Processor: utime - user mode jiffies ◮ stime - kernel mode jiffies ◮ ...
  • 12. pg proctab() Partial Column Description (cont.) Memory: vsize - virtual memory size ◮ rss - resident set memory size ◮ I/O: syscr - number of read I/O operations ◮ syscw - number of write I/O operations ◮ reads - number of bytes which this process really did cause to ◮ be fetched from the storage layer writes - number of bytes which this process really did cause to ◮ be sent from the storage layer cwrites - number of bytes which this process caused to not ◮ happen, by truncating pagecache
  • 13. pg proctab() Example 1 SELECT datname, procpid, usesysid, usename, uid, username FROM pg_stat_activity, pg_proctab() WHERE procpid = pid; datname | procpid | usesysid | usename | uid | username ---------+---------+----------+----------+-----+---------- markwkm | 27801 | 10 | markwkm | 500 | markwkm dbt3 | 27787 | 16770 | postgres | 500 | markwkm (2 rows)
  • 14. pg proctab() Example 2 SELECT datname, procpid, processor, state, fullcomm FROM pg_stat_activity, pg_proctab() WHERE procpid = pid; datname | procpid | processor | state | fullcomm ---------+---------+-----------+-------+------------------------------------------ markwkm | 27801 | 0|R | postgres: markwkm markwkm [local] SELECT dbt3 | 29325 | 3|R | postgres: markwkm dbt3 [local] SELECT dbt3 | 29327 | 0|R | postgres: markwkm dbt3 [local] SELECT dbt3 | 29333 | 3|R | postgres: markwkm dbt3 [local] SELECT dbt3 | 29328 | 2|R | postgres: markwkm dbt3 [local] SELECT dbt3 | 29329 | 0|R | postgres: markwkm dbt3 [local] SELECT dbt3 | 29324 | 3|R | postgres: markwkm dbt3 [local] SELECT dbt3 | 29331 | 0|R | postgres: markwkm dbt3 [local] SELECT dbt3 | 27787 | 1|S | postgres: postgres dbt3 [local] idle (9 rows)
  • 15. __ __ / / ~~~/ . o O | Let’s try something | ,----( oo ) | more useful. | / __ __/ / /| ( |( ^ /___ / | |__| |__|-quot;
  • 16. __ __ / / ~~~/ . o O | Collecting statitiscs | ,----( oo ) | from a query. | / __ __/ / /| ( |( ^ /___ / | |__| |__|-quot;
  • 17. The following examples are in the pg proctab contrib directory.
  • 18. Identify yourself. SELECT * FROM pg_backend_pid(); pg_backend_pid ---------------- 4509 (1 row) Note: The following series of SQL statements are made from the same psql session. Otherwise the pg backend pid will change. This is important because stats are collected in the operating system by process ID (pid).
  • 19. Take a snapshot before the running the query i ps_procstat-snap.sql BEGIN ps_snap_stats --------------- 1 (1 row) COMMIT
  • 20. Execute the query Don’t focus too much on the actual query, the idea is that is you want to collect statistics for a single query: SELECT nation, o_year, Sum(amount) AS sum_profit FROM (SELECT n_name AS nation, Extract(YEAR FROM o_orderdate) AS o_year, l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity AS amount FROM part, supplier, lineitem, partsupp, orders, nation WHERE s_suppkey = l_suppkey AND ps_suppkey = l_suppkey AND ps_partkey = l_partkey AND p_partkey = l_partkey AND o_orderkey = l_orderkey AND s_nationkey = n_nationkey AND p_name LIKE ’%white%’) AS profit GROUP BY nation, o_year ORDER BY nation, o_year DESC;
  • 21. Take a snapshot after the running the query i ps_procstat-snap.sql BEGIN ps_snap_stats --------------- 2 (1 row) COMMIT
  • 22. Calculate Processor Utilization $ ./ps-processor-utilization.sh 4590 1 2 Processor Utilization = 1.00 % Example (partial): SELECT stime, utime, stime + utime AS total, extract(epoch FROM time) FROM ps_snaps a, ps_procstat b WHERE pid = ${PID} AND a.snap = b.snap AND a.snap = ${SNAP1} TIMEDIFF=‘echo quot;scale = 2; (${TIME2} - ${TIME1}) * ${HZ}quot; | bc -l‘ U=‘echo quot;scale = 2; (${TOTAL2} - ${TOTAL1}) / ${TIMEDIFF} * 100quot; | bc -l‘
  • 23. Calculate Disk Utilization $ ./ps-io-utilization.sh 4590 1 2 Reads = 276981 Writes = 63803 Reads (Bytes) = 2164604928 Writes (Bytes) = 508166144 Cancelled (Bytes) = 36880384 SELECT syscr, syscw, reads, writes, cwrites FROM ps_snaps a, ps_procstat b WHERE pid = ${PID} AND a.snap = b.snap AND a.snap = ${SNAP1}
  • 24. __ __ / / ~~~/ . o O | Creating Custom | ,----( oo ) | Reports! | / __ __/ / /| ( |( ^ /___ / | |__| |__|-quot;
  • 25. Another example from pg proctab contrib $ ./ps-report.pl 4590 1 2 __ __ / / ~~~/ . o O | Warning! Too much data | ,----( oo ) | to fit on the screen! | / __ __/ / /| ( |( ^ /___ / | |__| |__|-quot;
  • 26. Creating Reports: Section 1 Database : dbt3 Snapshot Start : 2009-04-18 00:43:56.716034-07 Snapshot End : 2009-04-18 00:45:17.031167-07 ------------------- Database Statistics ------------------- Commits :0 Rollbacks :2 Blocks Read : 213295 Blocks Hit : 1679509
  • 27. Creating Reports: Section 2 ================ Table Statistics ================ ------------------------------------------ -------- ------------ -------- ------------- --------- -------- Schema.Relation Seq Scan Seq Tup Read Idx Scan Idx Tup Fetch N Tup Ins N Tup Up ------------------------------------------ -------- ------------ -------- ------------- --------- -------- information_schema.sql_features 0 0 0 0 0 information_schema.sql_implementation_info 0 0 0 0 0 information_schema.sql_languages 0 0 0 0 0 information_schema.sql_packages 0 0 0 0 0 information_schema.sql_parts 0 0 0 0 0 information_schema.sql_sizing 0 0 0 0 0 information_schema.sql_sizing_profiles 0 0 0 0 0 pg_catalog.pg_aggregate 0 0 2 2 0 pg_catalog.pg_am 1 1 0 0 0 pg_catalog.pg_amop 0 0 19 46 0 pg_catalog.pg_amproc 0 0 11 11 0 pg_catalog.pg_attrdef 0 0 1 2 0 pg_catalog.pg_attribute 0 0 137 331 0 pg_catalog.pg_auth_members 0 0 0 0 0 pg_catalog.pg_authid 3 2 0 0 0 pg_catalog.pg_autovacuum 0 0 0 0 0 pg_catalog.pg_cast 0 0 160 51 0 pg_catalog.pg_class 3 747 101 88 0 pg_catalog.pg_constraint 0 0 0 0 0 pg_catalog.pg_conversion 0 0 0 0 0 pg_catalog.pg_database 5 12 0 0 0 pg_catalog.pg_depend 0 0 0 0 0 pg_catalog.pg_description 0 0 0 0 0 pg_catalog.pg_index 2 200 39 50 0 ...
  • 28. Creating Reports: Section 2 - Falling off the right side... N Tup Upd ◮ N Tup Del ◮ Last Vacuum ◮ Last Autovacuum ◮ Last Analyze ◮ Last Autoanalyze ◮
  • 29. Creating Reports: Section 3 ================ Index Statistics ================ ------------------------------------------------------------ -------- ------------ ------------- Schema.Relation.Index Idx Scan Idx Tup Read Idx Tup Fetch ------------------------------------------------------------ -------- ------------ ------------- pg_catalog.pg_aggregate.pg_aggregate_fnoid_index 2 2 2 pg_catalog.pg_am.pg_am_name_index 0 0 0 pg_catalog.pg_am.pg_am_oid_index 0 0 0 pg_catalog.pg_amop.pg_amop_opc_strat_index 12 36 36 pg_catalog.pg_amop.pg_amop_opr_opc_index 7 10 10 pg_catalog.pg_amproc.pg_amproc_opc_proc_index 11 11 11 pg_catalog.pg_attrdef.pg_attrdef_adrelid_adnum_index 1 2 2 pg_catalog.pg_attrdef.pg_attrdef_oid_index 0 0 0 pg_catalog.pg_attribute.pg_attribute_relid_attnam_index 0 0 0 pg_catalog.pg_attribute.pg_attribute_relid_attnum_index 137 331 331 pg_catalog.pg_auth_members.pg_auth_members_member_role_index 0 0 0 pg_catalog.pg_auth_members.pg_auth_members_role_member_index 0 0 0 pg_catalog.pg_authid.pg_authid_oid_index 0 0 0 pg_catalog.pg_authid.pg_authid_rolname_index 0 0 0 pg_catalog.pg_autovacuum.pg_autovacuum_vacrelid_index 0 0 0 pg_catalog.pg_cast.pg_cast_oid_index 0 0 0 pg_catalog.pg_cast.pg_cast_source_target_index 160 51 51 pg_catalog.pg_class.pg_class_oid_index 71 71 71 pg_catalog.pg_class.pg_class_relname_nsp_index 30 17 17 pg_catalog.pg_constraint.pg_constraint_conname_nsp_index 0 0 0 pg_catalog.pg_constraint.pg_constraint_conrelid_index 0 0 0 pg_catalog.pg_constraint.pg_constraint_contypid_index 0 0 0 pg_catalog.pg_constraint.pg_constraint_oid_index 0 0 0 pg_catalog.pg_conversion.pg_conversion_default_index 0 0 0 ...
  • 30. What else can we do with pg proctab? Enable pg top to monitor remote databases by providing access to the database system’s operating system process table.
  • 32. __ __ / ~~~/ . o O ( Thank you! ) ,----( oo ) / __ __/ /| ( |( ^ /___ / | |__| |__|-quot;
  • 33. Acknowledgements Haley Jane Wakenshaw __ __ / ~~~/ ,----( oo ) / __ __/ /| ( |( ^ /___ / | |__| |__|-quot;
  • 34. License This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, (a) visit http://creativecommons.org/licenses/by/3.0/us/; or, (b) send a letter to Creative Commons, 171 2nd Street, Suite 300, San Francisco, California, 94105, USA.