Re: Questions on extending a relation

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Questions on extending a relation
Дата
Msg-id 7026.1119883481@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Questions on extending a relation  ("Qingqing Zhou" <zhouqq@cs.toronto.edu>)
Список pgsql-hackers
"Qingqing Zhou" <zhouqq@cs.toronto.edu> writes:
> 1. When we want a new page, we will do something like this:

> LockPage(relation, 0, ExclusiveLock);
> blockNum = smgrnblocks(reln->rd_smgr);
> /* Try to locate this blockNum in buffer pool, but definitely can't? */
> smgrextend(blockNum);
> LockPage(relation, 0, ExclusiveLock);

You should be using ReadBuffer with P_NEW, not calling smgr yourself.

> So if I have concurrently 10 backends reach here, we will have 10 new pages?

Yes.  That's intentional --- otherwise they'd all block each other.

> 2. Suppose an insert on a relation with index is performed in this sequence:

> begin transation;
> extend relation for a new page A;
> insert a heap tuple T on page A;
> insert an index tuple I on another page B;
> page B get written out by bgwriter;
> System crashed.
> System recovered.

> At this time, page A is empty since we won't replay xlog.

Why wouldn't we replay xlog?  Note in particular that the bgwriter is
not allowed to push page B to disk until the xlog entry describing the
index change has been flushed to disk.   Since that will come after the
xlog entry about the heap change, both changes are necessarily on-disk
in the xlog, and both will be remade during replay.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: GiST concurrency commited
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: accessing postgres conf from stored procedure