Installation
-------------

$ make USE_PGXS=1
# make USE_PGXS=1 install

$ psql
=# create extension decoder_stats;

Getting started
---------------

=# create table test (id int);
CREATE TABLE
=# select * from pg_create_logical_replication_slot('slot', 'decoder_stats');
 slot_name |    lsn
-----------+------------
 slot     | 1/5A6DFA00
(1 row)

=# begin; insert into test select generate_series(1, 100000); commit;
INSERT 0 100000
=# select * from pg_logical_slot_get_changes('slot', null, null); -- doesn't show anything
 lsn | xid | data
-----+-----+------
(0 rows)

=# select * from decoder_stats();
      change_type      | change_byte | change_tuple_byte | change_cnt
-----------------------+-------------+-------------------+------------
 INSERT                |    13200000 |           5200000 |     100000
 UPDATE                |           0 |                 0 |          0
 DELETE                |           0 |                 0 |          0
 MESSAGE               |           0 |                 0 |          0
 INVALIDATION          |           0 |                 0 |          0
 INTERNAL_SNAPSHOT     |           0 |                 0 |          0
 INTERNAL_COMMAND_ID   |           0 |                 0 |          0
 INTERNAL_TUPLECID     |           0 |                 0 |          0
 INTERNAL_SPEC_INSERT  |           0 |                 0 |          0
 INTERNAL_SPEC_CONFIRM |           0 |                 0 |          0
 TRUNCATE              |           0 |                 0 |          0
(11 rows)

-- 'change_bytes' is the total size of changes calculated on decoder side.
-- 'tota_bytes' is the total size of changes calculated on the core side (from pg_stat_replication_slots).
=# select * from mystats('slot');
 change_type | change_byte | change_tuple_byte | change_cnt | change_tuple_ratio | total_bytes | total_txns
-------------+-------------+-------------------+------------+--------------------+-------------+------------
 INSERT      | 13 MB       | 5078 kB           |     100000 |          0.3939394 | 13 MB       |          1
(1 row)

Test
----

$ make USE_PGXS=1 installcheck

The test always fails due to missing expected file. This is intentional. You can check the result by checking results/stat.out file.