Re: Printing LSN made easy

2021-02-18 Thread Michael Paquier
On Fri, Feb 19, 2021 at 10:54:05AM +0900, Kyotaro Horiguchi wrote: > At Thu, 18 Feb 2021 18:51:37 +0530, Ashutosh Bapat > wrote in >> On Thu, Feb 18, 2021 at 6:19 PM Peter Eisentraut < >> peter.eisentr...@2ndquadrant.com> wrote: >>> Here is an updated patch that just introduces

Re: Printing LSN made easy

2021-02-18 Thread Kyotaro Horiguchi
At Thu, 18 Feb 2021 18:51:37 +0530, Ashutosh Bapat wrote in > On Thu, Feb 18, 2021 at 6:19 PM Peter Eisentraut < > peter.eisentr...@2ndquadrant.com> wrote: > > > Here is an updated patch that just introduces LSN_FORMAT_ARGS(). I > > think the result is quite pleasant. > > > > Thanks a lot

Re: Printing LSN made easy

2021-02-18 Thread Ashutosh Bapat
On Thu, Feb 18, 2021 at 6:19 PM Peter Eisentraut < peter.eisentr...@2ndquadrant.com> wrote: > Here is an updated patch that just introduces LSN_FORMAT_ARGS(). I > think the result is quite pleasant. > Thanks a lot Peter for producing this patch. I am fine with it. The way this is defined

Re: Printing LSN made easy

2021-02-18 Thread Peter Eisentraut
Here is an updated patch that just introduces LSN_FORMAT_ARGS(). I think the result is quite pleasant. -- Peter Eisentraut 2ndQuadrant, an EDB company https://www.2ndquadrant.com/ From 91d831518c8a71b010bdc835caacaedb20ffb896 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 18 Feb

Re: Printing LSN made easy

2021-01-21 Thread Ashutosh Bapat
On Thu, Jan 21, 2021 at 3:53 PM Peter Eisentraut < peter.eisentr...@2ndquadrant.com> wrote: > On 2021-01-20 08:50, Ashutosh Bapat wrote: > > Thanks for looking into this. I would like to keep both the LSN_FORMAT > > and LSN_FORMAT_ARGS but with a note that the first can not be used in > > elog()

Re: Printing LSN made easy

2021-01-21 Thread Peter Eisentraut
On 2021-01-20 08:50, Ashutosh Bapat wrote: Thanks for looking into this. I would like to keep both the LSN_FORMAT and LSN_FORMAT_ARGS but with a note that the first can not be used in elog() or in messages which require localization. We have many other places doing snprintf() and such stuff,

Re: Printing LSN made easy

2021-01-20 Thread Kyotaro Horiguchi
At Wed, 20 Jan 2021 16:40:59 +0900, Michael Paquier wrote in > On Wed, Jan 20, 2021 at 07:25:37AM +0100, Peter Eisentraut wrote: > > It looks like we are not getting any consensus on this approach. One > > reduced version I would consider is just the second part, so you'd write > > something

Re: Printing LSN made easy

2021-01-19 Thread Ashutosh Bapat
On Wed, Jan 20, 2021 at 11:55 AM Peter Eisentraut < peter.eisentr...@2ndquadrant.com> wrote: > On 2020-11-27 11:40, Ashutosh Bapat wrote: > > The solution seems to be simple though. In the attached patch, I have > > added two macros > > #define LSN_FORMAT "%X/%X" > > #define LSN_FORMAT_ARG(lsn)

Re: Printing LSN made easy

2021-01-19 Thread Michael Paquier
On Wed, Jan 20, 2021 at 07:25:37AM +0100, Peter Eisentraut wrote: > It looks like we are not getting any consensus on this approach. One > reduced version I would consider is just the second part, so you'd write > something like > > snprintf(lsnchar, sizeof(lsnchar), "%X/%X", >

Re: Printing LSN made easy

2021-01-19 Thread Peter Eisentraut
On 2020-11-27 11:40, Ashutosh Bapat wrote: The solution seems to be simple though. In the attached patch, I have added two macros #define LSN_FORMAT "%X/%X" #define LSN_FORMAT_ARG(lsn) (uint32) ((lsn) >> 32), (uint32) (lsn) which can be used instead. It looks like we are not getting any

Re: Printing LSN made easy

2020-12-02 Thread Ashutosh Bapat
On Mon, Nov 30, 2020 at 8:07 PM Alvaro Herrera wrote: > On 2020-Nov-30, Ashutosh Bapat wrote: > > > Peter Eisentraut explained that the translation system can not handle > > strings broken by macros, e.g. errmsg("foo" MACRO "bar"), since it > doesn't > > know statically what the macro resolves

Re: Printing LSN made easy

2020-12-02 Thread Ashutosh Bapat
On Mon, Nov 30, 2020 at 7:38 PM Li Japin wrote: > Hi, > > On Nov 30, 2020, at 9:06 PM, Ashutosh Bapat > wrote: > > On Fri, Nov 27, 2020 at 9:51 PM Li Japin wrote: > > > Hi, > > Here, we cannot use sizeof(but) to get the buf size, because it is a > pointer, so it always > 8 bytes on 64-bit or 4

Re: Printing LSN made easy

2020-11-30 Thread Andres Freund
Hi, On 2020-11-29 12:10:21 -0500, Tom Lane wrote: > Agreed. snprintf.c is meant to implement a recognized standard > (ok, %m is a GNU extension, but it's still pretty standard). > I'm not on board with putting PG-only extensions in there. I wonder if there's something we could layer on the

Re: Printing LSN made easy

2020-11-30 Thread Alvaro Herrera
On 2020-Nov-30, Ashutosh Bapat wrote: > Peter Eisentraut explained that the translation system can not handle > strings broken by macros, e.g. errmsg("foo" MACRO "bar"), since it doesn't > know statically what the macro resolves to. But I am not familiar with our > translation system myself. But

Re: Printing LSN made easy

2020-11-30 Thread Li Japin
Hi, On Nov 30, 2020, at 9:06 PM, Ashutosh Bapat mailto:ashutosh.bapat@gmail.com>> wrote: On Fri, Nov 27, 2020 at 9:51 PM Li Japin mailto:japi...@hotmail.com>> wrote: Hi, Here, we cannot use sizeof(but) to get the buf size, because it is a pointer, so it always 8 bytes on 64-bit or 4

Re: Printing LSN made easy

2020-11-30 Thread Ashutosh Bapat
On Sun, Nov 29, 2020 at 10:40 PM Tom Lane wrote: > Michael Paquier writes: > > On Fri, Nov 27, 2020 at 04:10:27PM +0530, Ashutosh Bapat wrote: > >> Off list Craig Ringer suggested introducing a new format specifier > >> similar to %m for LSN but I did not get time to take a look at the > >>

Re: Printing LSN made easy

2020-11-30 Thread Ashutosh Bapat
On Sun, Nov 29, 2020 at 1:23 PM Michael Paquier wrote: > On Fri, Nov 27, 2020 at 04:10:27PM +0530, Ashutosh Bapat wrote: > > LSN_FORMAT_ARG expands to two comma separated arguments and is kinda > > open at both ends but it's handy that way. > > Agreed that's useful. > > > Off list Peter

Re: Printing LSN made easy

2020-11-30 Thread Ashutosh Bapat
On Fri, Nov 27, 2020 at 9:51 PM Li Japin wrote: > > Hi, > > Here, we cannot use sizeof(but) to get the buf size, because it is a pointer, > so it always > 8 bytes on 64-bit or 4 bytes on 32-bit machine. For an array, the sizeof() returns the size of memory consumed by the array. See section

Re: Printing LSN made easy

2020-11-30 Thread Ashutosh Bapat
On Fri, Nov 27, 2020 at 7:54 PM Alexey Kondratov wrote: > > Hi, > > On 2020-11-27 13:40, Ashutosh Bapat wrote: > > > > Off list Peter Eisentraut pointed out that we can not use these macros > > in elog/ereport since it creates problems for translations. He > > suggested adding functions which

Re: Printing LSN made easy

2020-11-29 Thread Craig Ringer
On Mon, Nov 30, 2020 at 1:10 AM Tom Lane wrote: > Michael Paquier writes: > > On Fri, Nov 27, 2020 at 04:10:27PM +0530, Ashutosh Bapat wrote: > >> Off list Craig Ringer suggested introducing a new format specifier > >> similar to %m for LSN but I did not get time to take a look at the > >>

Re: Printing LSN made easy

2020-11-29 Thread Tom Lane
Michael Paquier writes: > On Fri, Nov 27, 2020 at 04:10:27PM +0530, Ashutosh Bapat wrote: >> Off list Craig Ringer suggested introducing a new format specifier >> similar to %m for LSN but I did not get time to take a look at the >> relevant code. AFAIU it's available only to elog/ereport, so may

Re: Printing LSN made easy

2020-11-28 Thread Michael Paquier
On Fri, Nov 27, 2020 at 04:10:27PM +0530, Ashutosh Bapat wrote: > LSN_FORMAT_ARG expands to two comma separated arguments and is kinda > open at both ends but it's handy that way. Agreed that's useful. > Off list Peter Eisentraut pointed out that we can not use these macros > in elog/ereport

Re: Printing LSN made easy

2020-11-27 Thread Li Japin
Hi, Here, we cannot use sizeof(but) to get the buf size, because it is a pointer, so it always 8 bytes on 64-bit or 4 bytes on 32-bit machine. +char * +pg_lsn_out_buffer(XLogRecPtr lsn, char *buf) +{ + snprintf(buf, sizeof(buf), LSN_FORMAT, LSN_FORMAT_ARG(lsn)); + + return buf; +}

Re: Printing LSN made easy

2020-11-27 Thread Alexey Kondratov
Hi, On 2020-11-27 13:40, Ashutosh Bapat wrote: Off list Peter Eisentraut pointed out that we can not use these macros in elog/ereport since it creates problems for translations. He suggested adding functions which return strings and use %s when doing so. The patch has two functions