Re: Why is a newly created index contains the invalid LSN?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Yury Zhuravlev <u(dot)zhuravlev(at)postgrespro(dot)ru>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Why is a newly created index contains the invalid LSN?
Date: 2016-08-25 17:16:29
Message-ID: CA+Tgmobqp4Ls=p9ioNC+=SZm0_ZxRzRcxs6_57=zN1bY2Wi4tA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Aug 25, 2016 at 1:13 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Thu, Aug 25, 2016 at 10:25 AM, Yury Zhuravlev
> <u(dot)zhuravlev(at)postgrespro(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-08-25 17:19:15 Re: PG_DIAG_SEVERITY and a possible bug in pq_parse_errornotice()
Previous Message Robert Haas 2016-08-25 17:13:06 Re: Why is a newly created index contains the invalid LSN?