Tables en auto-vacuum

SELECT pid, query FROM pg_stat_activity WHERE query LIKE 'autovacuum: %';

 

Calcul du seuil de déclenchement du vacuum :

vacuum threshold = vacuum base threshold + vacuum scale factor * number of tuples

 

postgres 9.6 :

La vue pg_stat_progress_vacuum peut aider :

                       View "pg_catalog.pg_stat_progress_vacuum"
       Column       |  Type   | Collation | Nullable | Default | Storage  | Description 
--------------------+---------+-----------+----------+---------+----------+-------------
 pid                | integer |           |          |         | plain    | 
 datid              | oid     |           |          |         | plain    | 
 datname            | name    |           |          |         | plain    | 
 relid              | oid     |           |          |         | plain    | 
 phase              | text    |           |          |         | extended | 
 heap_blks_total    | bigint  |           |          |         | plain    | 
 heap_blks_scanned  | bigint  |           |          |         | plain    | 
 heap_blks_vacuumed | bigint  |           |          |         | plain    | 
 index_vacuum_count | bigint  |           |          |         | plain    | 
 max_dead_tuples    | bigint  |           |          |         | plain    | 
 num_dead_tuples    | bigint  |           |          |         | plain    | 
View definition:
 SELECT s.pid,
    s.datid,
    d.datname,
    s.relid,
        CASE s.param1
            WHEN 0 THEN 'initializing'::text
            WHEN 1 THEN 'scanning heap'::text
            WHEN 2 THEN 'vacuuming indexes'::text
            WHEN 3 THEN 'vacuuming heap'::text
            WHEN 4 THEN 'cleaning up indexes'::text
            WHEN 5 THEN 'truncating heap'::text
            WHEN 6 THEN 'performing final cleanup'::text
            ELSE NULL::text
        END AS phase,
    s.param2 AS heap_blks_total,
    s.param3 AS heap_blks_scanned,
    s.param4 AS heap_blks_vacuumed,
    s.param5 AS index_vacuum_count,
    s.param6 AS max_dead_tuples,
    s.param7 AS num_dead_tuples
   FROM pg_stat_get_progress_info('VACUUM'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10)
     JOIN pg_database d ON s.datid = d.oid;

 

Date du dernier vacuum, auto-vacuum, analyse, auto-analyse :

SELECT relname, last_vacuum, last_autovacuum, last_analyze, last_autoanalyze  
FROM pg_stat_all_tables;

 

Durée de l'autovacuum

SELECT datname, usename, pid, current_timestamp - xact_start AS xact_runtime, state, query
FROM pg_stat_activity 
WHERE query LIKE '%autovacuum%' AND query NOT LIKE '%pg_stat_activity%'
ORDER BY xact_start;

Avant d'installer un certificat il est préférable de vérifier que la clé privé corresponde bien au certificat.

Pour ce faire il faut vérifier  la 'signature du csr, de la clé et du certificat  via la commande openssl :

  • signature du certificat :

openssl x509 -noout -modulus -in <fichier_crt.crt> | openssl <xxx>

  • signature de la clé :

openssl rsa -noout -modulus -in <fichier_cle.key> | openssl <xxx>

  • signature du csr :

openssl req -noout -modulus -in <fichier_csr.csr> | openssl <xxx>

<xxx> peut être : md2 , md4, md5 , sha, sha1, base64

Par comparaison :

A faire sur le master :
SELECT pg_current_xlog_location();

A faire sur l'esclave
SELECT pg_last_xlog_receive_location();

Par le lag de la réplication :

A faire sur l'esclave
-> détermination par taille:
SELECT
CASE
WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() THEN 0
 ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INTEGER
END
AS replication_lag;

-> détermination par temps
select now() - pg_last_xact_replay_timestamp() AS replication_delay;


A faire sur le maître :
select client_addr, state, sent_location, write_location, flush_location, replay_location from pg_stat_replication;

 

 

 

Quelques requêtes utiles sur les lignes mortes :

 

  • Tables avec des lignes mortes dans la base :
select relname,n_dead_tup,n_live_tup from pg_stat_all_tables order by n_dead_tup desc;
  • Taille des lignes mortes pour chaque table (postgres superieur à 9) :
CREATE EXTENSION pgstattuple;
SELECT relname as table_name, pg_size_pretty(dead_tuple_len) AS dead_tuple_size
FROM
    (SELECT relname, (pgstattuple(oid)).dead_tuple_len AS dead_tuple_len FROM pg_class WHERE relkind='r')
    AS stattuple
ORDER BY dead_tuple_len DESC;
  • Taille des lignes mortes pour la base (postgres superieur à 9) :
SELECT 
   pg_size_pretty(sum((pgstattuple(oid)).dead_tuple_len)) AS total_dead_tuple_len 
FROM pg_class WHERE relkind='r';