Thread: [GENERAL] Unlogged Crash Detection
Is there a reliable way to distinguish between an empty unlogged table to an unlogged table which has been truncated due to a crash?
Gersner.
On Tue, Aug 29, 2017 at 5:17 PM, Gersner <gersner@gmail.com> wrote: > Is there a reliable way to distinguish between an empty unlogged table to an > unlogged table which has been truncated due to a crash? Why do you want to make such a difference? At the beginning of a crash recovery all the, the existing relation files of unlogged tables are all removed, and replaced by the init forknum which represents their initial state. You can see by yourself ResetUnloggedRelations & friends in reinit.c. -- Michael
I see, interesting.
We have lots of unlogged tables, upon a crash we want to create a feedback/alert that data disappeared.
Not very familiar with the internal structure, but is it possible to identify if the current table is the INIT_FORKNUM?
Gersner
We have lots of unlogged tables, upon a crash we want to create a feedback/alert that data disappeared.
Not very familiar with the internal structure, but is it possible to identify if the current table is the INIT_FORKNUM?
Gersner
On Tue, Aug 29, 2017 at 11:27 AM, Michael Paquier <michael.paquier@gmail.com> wrote:
On Tue, Aug 29, 2017 at 5:17 PM, Gersner <gersner@gmail.com> wrote:
> Is there a reliable way to distinguish between an empty unlogged table to an
> unlogged table which has been truncated due to a crash?
Why do you want to make such a difference? At the beginning of a crash
recovery all the, the existing relation files of unlogged tables are
all removed, and replaced by the init forknum which represents their
initial state. You can see by yourself ResetUnloggedRelations &
friends in reinit.c.
--
Michael
On Tue, Aug 29, 2017 at 6:06 PM, Gersner <gersner@gmail.com> wrote: > I see, interesting. Please do not top-post. This is not the recommended way of dealing with threads on this mailing list. > We have lots of unlogged tables, upon a crash we want to create a > feedback/alert that data disappeared. > > Not very familiar with the internal structure, but is it possible to > identify if the current table is the INIT_FORKNUM? Using pg_relation_filepath, you can know the path to a relation file on disk. So a simple idea would be to use pg_read_binary_file with the path of the file and the path of the init fork, which is suffixed with "_init", and then a comparison between both. If the data read is the same, the relation has been untouched. Note that you can only do such a thing as a superuser, and that the data is read from disk, not from shared buffers. So that's not perfect, but it give an indication. -- Michael
On 2017-08-29 20:19:52 +0900, Michael Paquier wrote: > On Tue, Aug 29, 2017 at 6:06 PM, Gersner <gersner@gmail.com> wrote: > > I see, interesting. > > Please do not top-post. This is not the recommended way of dealing > with threads on this mailing list. > > > We have lots of unlogged tables, upon a crash we want to create a > > feedback/alert that data disappeared. > > > > Not very familiar with the internal structure, but is it possible to > > identify if the current table is the INIT_FORKNUM? > > Using pg_relation_filepath, you can know the path to a relation file > on disk. So a simple idea would be to use pg_read_binary_file with the > path of the file and the path of the init fork, which is suffixed with > "_init", and then a comparison between both. If the data read is the > same, the relation has been untouched. Huh, but that's not particularly meaningful, is it? That'll just as well be the case for a freshly created relation, no? - Andres
On Tue, Aug 29, 2017 at 11:09 PM, Andres Freund <andres@anarazel.de> wrote: > Huh, but that's not particularly meaningful, is it? That'll just as well > be the case for a freshly created relation, no? I have assumed that the OP has some control on the timing of the relations, using an event trigger for example. There is no perfect method I am afraid. -- Michael