Re: Why is a newly created index contains the invalid LSN? - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Why is a newly created index contains the invalid LSN?
Date
Msg-id CA+Tgmobqp4Ls=p9ioNC+=SZm0_ZxRzRcxs6_57=zN1bY2Wi4tA@mail.gmail.com
Whole thread Raw
In response to Re: Why is a newly created index contains the invalid LSN?  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On Thu, Aug 25, 2016 at 1:13 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Thu, Aug 25, 2016 at 10:25 AM, Yury Zhuravlev
> <u.zhuravlev@postgrespro.ru> wrote:
>> I have a small question. While working on an incremental backup I noticed a
>> strange thing.
>> Newly created index is contains the invalid LSN (0/0).
>> Exmaple:
>> postgres=# select lsn from page_header(get_raw_page('test_a_idx2',0));
>> lsn -----
>> 0/0
>> (1 row)
>>
>> Can you explain me why?
>
> Why not?

Hmm, maybe I can do better than that.  In general, the reason why we
set the page LSN is to prevent the page from being written before the
WAL record that most recently modified it is flushed to disk; this is
a necessary invariant of write-ahead logging.  But for an index build
we don't need to generate any WAL records: if the system crashes, the
entire transaction will be considered to have aborted and the
relfilenode in which the new index was being written will be ignored,
so it doesn't matter whether we recover any of the contents of that
file.  Since there's no WAL being generated, there's no need to set
LSNs on the pages.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Why is a newly created index contains the invalid LSN?
Next
From: Tom Lane
Date:
Subject: Re: PG_DIAG_SEVERITY and a possible bug in pq_parse_errornotice()