Giter Site home page Giter Site logo

logerrors's Introduction

Extension for PostgreSQL for collecting statistics about messages in logfile.

Configuration variables:

  • logerrors.interval - Time between writing statistic to buffer (ms). Default of 5s, max of 60s;
  • logerrors.intervals_count - Count of intervals in buffer. Default of 120, max of 360. During this count of intervals messages doesn't dropping from statistic;
  • logerrors.excluded_errcodes - Excluded error codes separated by ",".

Install

The extension must be loaded via shared_preload_libraries.

Run psql command:

$ CREATE EXTENSION logerrors;

Tests

The extension uses standard pgxs regression tests. Run make installcheck to run all psql scripts defined in sql directory. Output of each is then evaluated by diff with corresponding expected output stored in the expected directory.

    $ make installcheck
    +++ regress install-check in  +++
    ============== creating temporary instance            ==============
    ============== initializing database system           ==============
    ============== starting postmaster                    ==============
    running on port 51698 with PID 472134
    ============== creating database "contrib_regression" ==============
    CREATE DATABASE
    ALTER DATABASE
    ALTER DATABASE
    ALTER DATABASE
    ALTER DATABASE
    ALTER DATABASE
    ALTER DATABASE
    ============== installing logerrors                   ==============
    CREATE EXTENSION
    ============== creating role "postgres"               ==============
    CREATE ROLE
    GRANT
    ============== running regression test queries        ==============
    test logerrors                    ... ok        15017 ms
    ============== shutting down postmaster               ==============
    ============== removing temporary instance            ==============

=====================
 All 1 tests passed. 
=====================

Usage

After creating extension you can call pg_log_errors_stats() function in psql (without any arguments).

    postgres=# select * from pg_log_errors_stats();
     time_interval |  type   |       message        | count | username | database | sqlstate 
    ---------------+---------+----------------------+-------+----------+----------+----------
                   | WARNING | TOTAL                |     0 |          |          | 
                   | ERROR   | TOTAL                |     1 |          |          | 
                   | FATAL   | TOTAL                |     0 |          |          | 
                 5 | ERROR   | ERRCODE_SYNTAX_ERROR |     1 | postgres | postgres | 42601
               600 | ERROR   | ERRCODE_SYNTAX_ERROR |     1 | postgres | postgres | 42601

In output you can see 7 columns:

time_interval: how long (in seconds) has statistics been collected.
type: postgresql type of message (now supports only these: warning, error, fatal).
message: code of message from log_hook. (or 'TOTAL' for total count of that type messages)
count: count of messages of this type at this time_interval in log.
username: effective role causing the message
database: database where the message comes from
sqlstate: code of the message transformed to the form of sqlstate

To get number of lines in slow log call pg_slow_log_stats():

    postgres=# select * from pg_slow_log_stats();
     slow_count |         reset_time
    ------------+----------------------------
              1 | 2020-06-13 00:19:31.084923
    (1 row)

To reset all statistics use

    postgres=# select pg_log_errors_reset();

logerrors's People

Contributors

munakoiso avatar reshke avatar leborchuk avatar woblerr avatar

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.