pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wim Bertels <wim.bertels@ucll.be>
To: Arnav <justdba03@gmail.com>
To: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: View pervious versions of row
Date: Mon, 20 Apr 2020 11:25:37 +0200
Message-ID: <904691b6c7df23ffb4439572ed2b8ba99185877f.camel@ucll.be> (raw)
In-Reply-To: <CAF0ZvMz+MJHjHfGONv7sBNtvc_ceUONL1tyGv+J5HCdqP2nr_w@mail.gmail.com>
References: <CAF0ZvMz+MJHjHfGONv7sBNtvc_ceUONL1tyGv+J5HCdqP2nr_w@mail.gmail.com>

a few queries with some info:
# \d test                Table "public.test" Column |  Type   |
Collation | Nullable | Default --------+---------+-----------+---------
-+--------- a      | integer |           |          |  b      |
text    |           |          | 
wim=# table test; a | b ---+--- 3 |  3 |  5 |  4 | t 5 | b(5 rows)
# SELECT * FROM heap_page_items(get_raw_page('test', 0));
 lp | lp_off | lp_flags | lp_len | t_xmin | t_xmax | t_field3 | t_ctid
| t_infomask2 | t_infomask | t_hoff | t_bits | t_oid |     t_data     -
---+--------+----------+--------+--------+--------+----------+------
--+-------------+------------+--------+--------+-------+---------------
-  1 |   8160 |        1 |     28 |    938 |      0 |        0 |
(0,1)  |           1 |       2304 |     24 |        |       |
\x03000000  2 |   8128 |        1 |     28 |    939 |      0 |        0
| (0,2)  |           1 |       2304 |     24 |        |       |
\x03000000  3 |   8096 |        1 |     28 |    941 |    942 |        0
| (0,3)  |        8193 |        256 |     24 |        |       |
\x04000000  4 |   8064 |        1 |     28 |    941 |      0 |        0
| (0,4)  |           1 |       2304 |     24 |        |       |
\x05000000  5 |   8032 |        1 |     30 |    944 |      0 |        0
| (0,5)  |           2 |       2050 |     24 |        |       |
\x040000000574  6 |   8000 |        1 |     30 |    944 |      0
|        0 | (0,6)  |           2 |       2050 |     24
|        |       | \x050000000562
so in this example 941 |    942  (t_xmin t_xmax) is the dead row, the
data is in the last row
more info about t_data:# SELECT tuple_data_split('test'::regclass,
t_data, t_infomask, t_infomask2, t_bits),t_xmin,t_xmax FROM
heap_page_items(get_raw_page('test', 0));     tuple_data_split      |
t_xmin | t_xmax ---------------------------+--------+------
-- {"\\x03000000",NULL}      |    938
|      0 {"\\x03000000",NULL}      |    939
|      0 {"\\x04000000",NULL}      |    941
|    942 {"\\x05000000",NULL}      |    941
|      0 {"\\x04000000","\\x0574"} |    944
|      0 {"\\x05000000","\\x0562"} |    944 |      0
# update test set b = 'r' where a=5 and b is null;
# SELECT tuple_data_split('test'::regclass, t_data, t_infomask,
t_infomask2, t_bits),* FROM heap_page_items(get_raw_page('test',
0));     tuple_data_split      | lp | lp_off | lp_flags | lp_len |
t_xmin | t_xmax | t_field3 | t_ctid | t_infomask2 | t_infomask | t_hoff
| t_bits | t_oid |     t_data     ---------------------------+----+--
------+----------+--------+--------+--------+----------+--------+----
---------+------------+--------+--------+-------+--------------
-- {"\\x03000000",NULL}      |  1 |   8160 |        1 |     28 |    938
|      0 |        0 | (0,1)  |           1 |       2304 |     24
|        |       | \x03000000 {"\\x03000000",NULL}      |  2 |   8128
|        1 |     28 |    939 |      0 |        0 | (0,2)  |           1
|       2304 |     24 |        |       |
\x03000000 {"\\x04000000",NULL}      |  3 |   8096 |        1 |     28
|    941 |    942 |        0 | (0,3)  |        8193 |       1280
|     24 |        |       | \x04000000 {"\\x05000000",NULL}      |  4
|   8064 |        1 |     28 |    941 |    945 |        0 |
(0,7)  |       16385 |        256 |     24 |        |       |
\x05000000 {"\\x04000000","\\x0574"} |  5 |   8032 |        1 |     30
|    944 |      0 |        0 | (0,5)  |           2 |       2306
|     24 |        |       | \x040000000574 {"\\x05000000","\\x0562"}
|  6 |   8000 |        1 |     30 |    944 |      0 |        0 |
(0,6)  |           2 |       2306 |     24 |        |       |
\x050000000562 {"\\x05000000","\\x0572"} |  7 |   7968 |        1
|     30 |    945 |      0 |        0 | (0,7)  |       32770
|      10242 |     24 |        |       | \x050000000572
maybe you forget the extension?# create extension pageinspect ;
hth,Wim
Arnav schreef op vr 17-04-2020 om 17:57 [+0530]:
> hi Pgsql-Admin
> 
> What is the command to view the previous version of rows (deleted or
> updated)
> 
> I searched and found some functions like : . But none of them are
> working
>  SELECT * FROM page_header(get_raw_page('school',0));
> SELECT * FROM heap_page_items(get_raw_page('school',0));
>                                   ^
> Sorry if the question sounds stupid
> -- 
> Regards
> Ankush
> 
> 
> 
> 
> Regards
> Arnav


-- 
mvg,
Wim Bertels
--
Lector
UC Leuven-Limburg
--
All I know is what the words know, and dead things, and that
makes a handsome little sum, with a beginning and a middle and
an end, as in the well-built phrase and the long sonata of the dead.
		-- Samuel Beckett

view thread (2+ messages)

Message-ID: <904691b6c7df23ffb4439572ed2b8ba99185877f.camel@ucll.be>
Permalink:  ../904691b6c7df23ffb4439572ed2b8ba99185877f.camel@ucll.be/
Also on:    postgresql.org/message-id/904691b6c7df23ffb4439572ed2b8ba99185877f.camel@ucll.be

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: wim.bertels@ucll.be, justdba03@gmail.com
  Subject: Re: View pervious versions of row
  In-Reply-To: <904691b6c7df23ffb4439572ed2b8ba99185877f.camel@ucll.be>
  References: <CAF0ZvMz+MJHjHfGONv7sBNtvc_ceUONL1tyGv+J5HCdqP2nr_w@mail.gmail.com> <904691b6c7df23ffb4439572ed2b8ba99185877f.camel@ucll.be>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox