Monday, January 30, 2023

Check if the relfrozenxid increases with each dml with in a TX statement (begin/commit or end)

Do dml in session 1 and in parallel after each statement collect data


session 1:

begin work;

INSERT INTO pgtst_schema.pgtst_vacuum

SELECT i, lpad('TST',mod(i,100),'CHK')

FROM generate_series (20001,20005) s(i);


INSERT INTO pgtst_schema.pgtst_vacuum

SELECT i, lpad('TST',mod(i,100),'CHK')

FROM generate_series (20006,20010) s(i);


commit work;


session 2: data collection


1) During the first incremental or small load of 5 records, the TX age of the table increased


Candidate - pg_class:

table:

age                 | 10                                      | age                 | 11


toast:

age                 | 0                                       | age                 | 1


No change in pg_stat_user_tables.


Other table - pg_class:


table:

age                 | 44                                      | age                 | 45


toast:

age                 | 45                                      | age                 | 46


No change in pg_stat_user_tables.


2) During the second incremental or small load of 5 records, the TX age of the table didnt change as expected, since the TX is still open!


No changes in pg_class or pg_stat_user_tables views.


3) Post commit:


Candidate - pg_class:

No changes


Changes observed in pg_stat_user_tables - table:


n_tup_ins           | 30001                                   | n_tup_ins           | 30011

n_live_tup          | 20064                                   | n_live_tup          | 20074

n_mod_since_analyze | 30000                                   | n_mod_since_analyze | 30010

n_ins_since_vacuum  | 0                                       | n_ins_since_vacuum  | 10



Other table - pg_class:


No change in pg_class

No change in pg_stat_user_tables.


Observation: So this means a single TX assigned per whole bunch of DMLs fired between begin/end statement.


No comments:

Post a Comment

Flashback data archive steps

 Objective: Ways to track DML changes in a table Detailed objective: We should be able to track the changes in the table at any point in tim...