Giter Site home page Giter Site logo

pg_session_stats's Introduction

pg_session_stats

This extension lets you track PostgreSQL resource usage at the level of a session (connection). Notably, this library properly tracks usage across parallel workers. To instrument a single query, one should create a new session, execute that query, then end the session.

To install, ensure you have sqlite3 installed and run:

make USE_PGXS=1 install

The extension makes a few assumptions that might not stay true, but are true in PG12:

  • That ExecutorEnd hooks are reliably called after all of what could be considered query processing has completed.
  • That the /proc/{PID}/cmdline of worker processes will end with the main executor's PID (if anyone knows a better way to connect worker PIDs to the primary executor, let me know).

Since dealing with PostgreSQL's shared memory and locking system is not my idea of a good time, this extention saves the results into a SQLite3 database. You can set the location of this database by setting pg_session_stats.path in your postgresql.conf.

The created DB has a single table called log with the following schema:

CREATE TABLE log (
    master_pid INT,
    my_pid     INT, 
    usage      REAL,
    procstatus TEXT
);
  • The master_pid column will contain the PID of the main executor process (i.e., the one given by select pg_backend_pid();).
  • The my_pid column contains the PID of executor (which may be equal to master_pid).
  • The usage column contains the total amount of CPU time used by that executor.
  • The procstatus column contains the output of /proc/{PID}/status for that executor after query processing was complete.

pg_session_stats's People

Contributors

ryanmarcus avatar

Stargazers

Georgy Shelkovy avatar  avatar Jin Lianyuan avatar  avatar tsingson avatar Alex Hafner avatar Vishal Sharma avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

zhengtongyan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.