Skip site navigation (1) Skip section navigation (2)

[PATCH] Patch to compute Max LSN of Data Pages

From: Amit kapila <amit(dot)kapila(at)huawei(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Patch to compute Max LSN of Data Pages
Date: 2012-07-31 12:09:06
Message-ID: 6C0B27F7206C9E4CA54AE035729E9C382851FFA1@szxeml509-mbs (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
>> Based on the discussion and suggestions in this mail chain, following features can be implemented:
>> 1. To compute the value of max LSN in data pages based on user input whether he wants it for an individual

>>   file,  a particular directory or whole database.
>> 2a. To search the available WAL files for the latest checkpoint record and prints the value.
>> 2b. To search the available WAL files for the latest checkpoint record and recreates a pg_control file pointing at

>> that checkpoint.

>> I have kept both options to address different kind of corruption scenarios.

> I think I can see all of those things being potentially useful.  There
> are a couple of pending patches that will revise the WAL format
> slightly; not sure how much those are likely to interfere with any
> development you might do on (2) in the meantime.

Based on above conclusion, I have prepared a patch which implements Option-1

To find the value of max LSN in data pages based on user input whether he wants for
        - An individual file
        - A particular directory
        - Whole database

Corresponding pg_resetxlog options are as follows
  -p {file | dir}        print max LSN from specified file or directory path
  -P                         print max LSN from whole database

Note: in case of -p {file | dir} input path should be absolute path or relative from data base directory.

These options are useful when pg_control, WAL files and data files are missing or corrupted.
Using above options user can able to find the max LSN number and can be able to compute the next redo log sequence number.

Sample output:
postgres(at)linux:> pg_resetxlog -P /home/postgres/installation/bin/data
Maximum LSN found is: 73325448, WAL segment file name (fileid, seg): 0000000000000004

Based on user option display max LSN.
1. Finding max LSN in an individual file [pg_resetxlog option: -p file-name]
A. Open the given file and check for the number of blocks;
B. Read page header and validate; if valid find the max lsn number; if invalid log the page-id and filename and continue to next page.

2. Finding max LSN a folder (excluding sub directories) [pg_resetxlog option: -p folder-name]
    Note: Here we are not traversing through sub directories, as some times it may possible to have recursive loops because of soft links
Read all the file in the given folder using ReadDir function
        If file name / folder name start with pgsql_tmp ignore and continue to next.
        Find the max LSN in this file (refer 1. Finding max LSN in an individual file)

3. Finding max LSN for whole database [pg_resetxlog option: -P]
    A. Read the base directory
            Format: pgDataDirecoty/base/databaseid/*
               1. Skip the folder if name is equal to “0” or “1”; [skip template database]
2. Form the new folder name as and call the function written in [2. Finding max LSN a folder]
    B. Read the global directory
            Note: here need to exclude the files [pg_controldata, .. ] which are taken care in folder reading function.
    C. Read all table spaces
       Folder structure: pg_tblspc/table space id/<CONSTANT PG VERSION STRING>/Database ID/relfilenodes.
1. Read all table space names in pg_tblspc/*
                1.1. For each folder form the path as
                         pg_tblspc/tblspc-folder-name/<CONSTANT PG VERSION STRING>/
1.2. Read all the directories in pg_tblspc/table space id/<CONSTANT PG VERSION STRING>/*
                1.2.1. For each folder form the path as “pg_tblspc/ tblspc-folder-name /<CONSTANT-PG-VERSION STRING>/db-id-folder-name”


With Regards,

Amit Kapila.

Attachment: pg_resetxlog_find_max_lsn_from_datafiles.patch
Description: text/plain (10.0 KB)


pgsql-hackers by date

Next:From: Etsuro FujitaDate: 2012-07-31 12:28:27
Subject: Re: pgsql_fdw in contrib
Previous:From: Jan UrbańskiDate: 2012-07-31 09:40:18
Subject: Re: Passing tabular data around using python functions

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group