[BUGS] BUG #14529: Missing non pk data for "before image" in logical decoding

Поиск
Список
Период
Сортировка
Искать

[BUGS] BUG #14529: Missing non pk data for "before image" in logical decoding

От:
philippe.beaudoin@dalibo.com
Дата:
The following bug has been logged on the website:

Bug reference:      14529
Logged by:          Philippe BEAUDOIN
Email address:      philippe.beaudoin@dalibo.com
PostgreSQL version: 9.6.1
Operating system:   Linux
Description:        

I am currently studying the logical decoding mechanism as an alternative to
log triggers for the E-Maj extension.
Using pg_recvlogical and pgbench, I have been able to reproduce an issue
that I met.

In short, I initialize the pgbench environment and set the REPLICA IDENTITY
to FULL on  pgbench tables. Then I inject just 2 pgbench transactions and
collect the changes by pg_recvlogical, using the 'test_logical' output
plugin. The pg_recvlogical output shows the INSERT and the 3 UPDATEs of each
transaction. But for 2 of these UPDATEs, one only gets the value of the pkey
columns. The other columns are missing despite the REPLICA IDENTITY set to
FULL.

Using pg_xlogdump to look at the wal, I remarked that the faulting UPDATES
are "HOT_UPDATE", while the usual "UPDATE" are OK. 

Here is a simple test case script:

#-------------------------------------------------------------------------------
#!/bin/sh

export PGHOST=localhost
export PGPORT=5496
export PGUSER=postgres
export PGDATABASE=testdb

echo "*** -----------------------------"
echo "*** Initializing testdb database"
echo "*** -----------------------------"
dropdb testdb
createdb testdb

pgbench -i --foreign-keys

psql <
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
number of transactions per client: 2
number of transactions actually processed: 2/2
latency average = 15.345 ms
tps = 65.167807 (including connections establishing)
tps = 78.259509 (excluding connections establishing)
*** -----------------------------
*** Stop pg_recvlogical
*** -----------------------------
*** -----------------------------
*** Looking at the end of report
*** !!! UPDATEs on pgbench_tellers and pgbench_branches show truncated old
rows (only pk columns are displayed),
*** while pgbench_account is processed correctly and REPLICA IDENTITY is
correctly set to FULL for all tables.
*** also true with the SQL interface.
*** -----------------------------
BEGIN 5454770
table public.pgbench_accounts: UPDATE: old-key: aid[integer]:24469
bid[integer]:1 abalance[integer]:0 filler[character]:'                      
                                                             ' new-tuple:
aid[integer]:24469 bid[integer]:1 abalance[integer]:-3373
filler[character]:'                                                         
                          '
table public.pgbench_tellers: UPDATE: old-key: tid[integer]:2 bid[integer]:1
tbalance[integer]:0 new-tuple: tid[integer]:2 bid[integer]:1
tbalance[integer]:-3373 filler[character]:null
table public.pgbench_branches: UPDATE: old-key: bid[integer]:1
bbalance[integer]:0 new-tuple: bid[integer]:1 bbalance[integer]:-3373
filler[character]:null
table public.pgbench_history: INSERT: tid[integer]:2 bid[integer]:1
aid[integer]:24469 delta[integer]:-3373 mtime[timestamp without time
zone]:'2017-01-21 09:51:29.728733' filler[character]:null
COMMIT 5454770
BEGIN 5454771
table public.pgbench_accounts: UPDATE: old-key: aid[integer]:4016
bid[integer]:1 abalance[integer]:0 filler[character]:'                      
                                                             ' new-tuple:
aid[integer]:4016 bid[integer]:1 abalance[integer]:3308 filler[character]:' 
                                                                            
     '
table public.pgbench_tellers: UPDATE: old-key: tid[integer]:2 bid[integer]:1
tbalance[integer]:-3373 new-tuple: tid[integer]:2 bid[integer]:1
tbalance[integer]:-65 filler[character]:null
table public.pgbench_branches: UPDATE: old-key: bid[integer]:1
bbalance[integer]:-3373 new-tuple: bid[integer]:1 bbalance[integer]:-65
filler[character]:null
table public.pgbench_history: INSERT: tid[integer]:2 bid[integer]:1
aid[integer]:4016 delta[integer]:3308 mtime[timestamp without time
zone]:'2017-01-21 09:51:29.74555' filler[character]:null
COMMIT 5454771
#-------------------------------------------------------------------------------

The incomplete UPDATEs concern pgbench_tellers and pgbench_branches
tables.



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Re: [BUGS] BUG #14529: Missing non pk data for "before image" inlogical decoding

От:
Petr Jelinek <petr.jelinek@2ndquadrant.com>
Дата:
Hi,

On 06/02/17 17:12, philippe.beaudoin@dalibo.com wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      14529
> Logged by:          Philippe BEAUDOIN
> Email address:      philippe.beaudoin@dalibo.com
> PostgreSQL version: 9.6.1
> Operating system:   Linux
> Description:        
> 
> I am currently studying the logical decoding mechanism as an alternative to
> log triggers for the E-Maj extension.
> Using pg_recvlogical and pgbench, I have been able to reproduce an issue
> that I met.
> 
> [...snip...]
>
> BEGIN 5454770
> table public.pgbench_accounts: UPDATE: old-key: aid[integer]:24469
> bid[integer]:1 abalance[integer]:0 filler[character]:'                      
>                                                              ' new-tuple:
> aid[integer]:24469 bid[integer]:1 abalance[integer]:-3373
> filler[character]:'                                                         
>                           '
> table public.pgbench_tellers: UPDATE: old-key: tid[integer]:2 bid[integer]:1
> tbalance[integer]:0 new-tuple: tid[integer]:2 bid[integer]:1
> tbalance[integer]:-3373 filler[character]:null
> table public.pgbench_branches: UPDATE: old-key: bid[integer]:1
> bbalance[integer]:0 new-tuple: bid[integer]:1 bbalance[integer]:-3373
> filler[character]:null
> table public.pgbench_history: INSERT: tid[integer]:2 bid[integer]:1
> aid[integer]:24469 delta[integer]:-3373 mtime[timestamp without time
> zone]:'2017-01-21 09:51:29.728733' filler[character]:null
> COMMIT 5454770
> BEGIN 5454771
> table public.pgbench_accounts: UPDATE: old-key: aid[integer]:4016
> bid[integer]:1 abalance[integer]:0 filler[character]:'                      
>                                                              ' new-tuple:
> aid[integer]:4016 bid[integer]:1 abalance[integer]:3308 filler[character]:' 
>                                                                             
>      '
> table public.pgbench_tellers: UPDATE: old-key: tid[integer]:2 bid[integer]:1
> tbalance[integer]:-3373 new-tuple: tid[integer]:2 bid[integer]:1
> tbalance[integer]:-65 filler[character]:null
> table public.pgbench_branches: UPDATE: old-key: bid[integer]:1
> bbalance[integer]:-3373 new-tuple: bid[integer]:1 bbalance[integer]:-65
> filler[character]:null
> table public.pgbench_history: INSERT: tid[integer]:2 bid[integer]:1
> aid[integer]:4016 delta[integer]:3308 mtime[timestamp without time
> zone]:'2017-01-21 09:51:29.74555' filler[character]:null
> COMMIT 5454771
> #-------------------------------------------------------------------------------
> 
> The incomplete UPDATEs concern pgbench_tellers and pgbench_branches
> tables.
>

Seems to me like what you see here is not bug but just behavior of
test_decoding plugin which skips NULL values from old-key printing - see
the tuple_to_stringinfo() function and calls to it from pg_decode_change().

-- 
  Petr Jelinek                  http://www.2ndQuadrant.com/
  PostgreSQL Development, 24x7 Support, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Re: [BUGS] BUG #14529: Missing non pk data for "before image" inlogical decoding

От:
Philippe Beaudoin <philippe.beaudoin@dalibo.com>
Дата:

Le 06/02/2017 à 18:01, Petr Jelinek a écrit :
Hi,

On 06/02/17 17:12, philippe.beaudoin@dalibo.com wrote:
The following bug has been logged on the website:

Bug reference:      14529
Logged by:          Philippe BEAUDOIN
Email address:      philippe.beaudoin@dalibo.com
PostgreSQL version: 9.6.1
Operating system:   Linux
Description:        

I am currently studying the logical decoding mechanism as an alternative to
log triggers for the E-Maj extension.
Using pg_recvlogical and pgbench, I have been able to reproduce an issue
that I met.

[...snip...]

BEGIN 5454770
table public.pgbench_accounts: UPDATE: old-key: aid[integer]:24469
bid[integer]:1 abalance[integer]:0 filler[character]:'                                                                                  ' new-tuple:
aid[integer]:24469 bid[integer]:1 abalance[integer]:-3373
filler[character]:'                                                                                  '
table public.pgbench_tellers: UPDATE: old-key: tid[integer]:2 bid[integer]:1
tbalance[integer]:0 new-tuple: tid[integer]:2 bid[integer]:1
tbalance[integer]:-3373 filler[character]:null
table public.pgbench_branches: UPDATE: old-key: bid[integer]:1
bbalance[integer]:0 new-tuple: bid[integer]:1 bbalance[integer]:-3373
filler[character]:null
table public.pgbench_history: INSERT: tid[integer]:2 bid[integer]:1
aid[integer]:24469 delta[integer]:-3373 mtime[timestamp without time
zone]:'2017-01-21 09:51:29.728733' filler[character]:null
COMMIT 5454770
BEGIN 5454771
table public.pgbench_accounts: UPDATE: old-key: aid[integer]:4016
bid[integer]:1 abalance[integer]:0 filler[character]:'                                                                                  ' new-tuple:
aid[integer]:4016 bid[integer]:1 abalance[integer]:3308 filler[character]:'                                                                                '
table public.pgbench_tellers: UPDATE: old-key: tid[integer]:2 bid[integer]:1
tbalance[integer]:-3373 new-tuple: tid[integer]:2 bid[integer]:1
tbalance[integer]:-65 filler[character]:null
table public.pgbench_branches: UPDATE: old-key: bid[integer]:1
bbalance[integer]:-3373 new-tuple: bid[integer]:1 bbalance[integer]:-65
filler[character]:null
table public.pgbench_history: INSERT: tid[integer]:2 bid[integer]:1
aid[integer]:4016 delta[integer]:3308 mtime[timestamp without time
zone]:'2017-01-21 09:51:29.74555' filler[character]:null
COMMIT 5454771
#-------------------------------------------------------------------------------

The incomplete UPDATEs concern pgbench_tellers and pgbench_branches
tables.

Seems to me like what you see here is not bug but just behavior of
test_decoding plugin which skips NULL values from old-key printing - see
the tuple_to_stringinfo() function and calls to it from pg_decode_change().

Thank a lot, Petr, for your quick answer.

Effectively, the code you have pointed out is clear. And looking more closely at the pgbench scenario and table structure confirms your explanation.

The documentation doesn't explain this detail level. But as this output plugin is only an example, I understand the documentation remains light.

Sorry for the trouble.
Philippe.


DALIBO
L'expertise PostgreSQL
10 rue d'Uzès
75002 Paris
Philippe Beaudoin
Consultant Avant-Vente
+33 (0)1 84 19 36 94
+33 (0)7 69 14 67 21
FAQ