Обсуждение: timestams in the the pg_standby output

Поиск
Список
Период
Сортировка

timestams in the the pg_standby output

От
Tim Uckun
Дата:
Is there a way to get pg_standby to put timestamps in the output it
generates? I am currently piping the output to a log fie but since it
contains no timestamps it's of limited use to me.

Re: timestams in the the pg_standby output

От
Fujii Masao
Дата:
On Tue, Jan 5, 2010 at 11:20 AM, Tim Uckun <timuckun@gmail.com> wrote:
> Is there a way to get pg_standby to put timestamps in the output it
> generates?

No.

> I am currently piping the output to a log fie but since it
> contains no timestamps it's of limited use to me.

You can create the script which adds the timestamp into the head of
the output by using awk, perl, etc.

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Re: timestams in the the pg_standby output

От
Greg Smith
Дата:
Tim Uckun wrote:
Is there a way to get pg_standby to put timestamps in the output it
generates? I am currently piping the output to a log fie but since it
contains no timestamps it's of limited use to me. 

Nope; already on my TODO list to take care of one day since it annoys me too.  What you can do is run another program in parallel that does something similar to the "tail -f" behavior, letting you watch new files added to the log file.  As each line is read, timestamps it and print the line.  There's a sample that's almost what you want at http://stackoverflow.com/questions/441437/how-do-i-implement-tail-f-with-timeout-on-read-in-perl ; basically you'd just need to replace

    print "$item";
   
print "\n" if ($line_no % DOTS_PER_LINE == 0);
    printf
"%s\n", strftime("%Y-%m-%d %H:%M:%S", localtime(time))
       
if ($line_no % (DOTS_PER_LINE * LINES_PER_BREAK) == 0);

With something like this:

    printf "%s %s\n", strftime("%Y-%m-%d %H:%M:%S", localtime(time)), $item

(untested, and I am not a regular Perl programmer, its but File::Tail is the best library I know of to do this sort of thing)

-- 
Greg Smith    2ndQuadrant   Baltimore, MD
PostgreSQL Training, Services and Support
greg@2ndQuadrant.com  www.2ndQuadrant.com

Re: timestams in the the pg_standby output

От
Tim Uckun
Дата:
>     printf "%s %s\n", strftime("%Y-%m-%d %H:%M:%S", localtime(time)), $item
>
> (untested, and I am not a regular Perl programmer, its but File::Tail is the
> best library I know of to do this sort of thing)
>


Ah if I am going to do that I suppose something like this would work.

#!/bin/sh
while read data; do
    echo "`date +%H:%M:%S` : $data" >> logfile.log
done

Re: timestams in the the pg_standby output

От
Greg Smith
Дата:
Tim Uckun wrote:
> Ah if I am going to do that I suppose something like this would work.
>
> #!/bin/sh
> while read data; do
>     echo "`date +%H:%M:%S` : $data" >> logfile.log
> done
>

If that works, great.  I'm not sure if you'll run afoul of output
buffering in this situation.  Clearly you've got the right idea, just
need to make sure it behaves as you expect and doesn't clump the line
reads into larger chunks.

The main improvement in the Perl implementation over this is the ability
to do things like adjust timeout behavior easily.

--
Greg Smith    2ndQuadrant   Baltimore, MD
PostgreSQL Training, Services and Support
greg@2ndQuadrant.com  www.2ndQuadrant.com


Re: timestams in the the pg_standby output

От
Tim Uckun
Дата:
>
> If that works, great.  I'm not sure if you'll run afoul of output buffering
> in this situation.  Clearly you've got the right idea, just need to make
> sure it behaves as you expect and doesn't clump the line reads into larger
> chunks.

Actually I could not get it to send the output to the pipe at all. I
tried several things like writing to log file from the script or send
the output of the script to STDOUT and redirecting from there but no
matter what I did if I sent the output of the pg_standby to the pipe
the script received nothing and all the output went to postgres log
file.

The last thing I tried looked like this.

restore_command = '/usr/lib/postgresql/8.3/bin/pg_standby -l -d -s 30
-t /var/lib/postgresql/pgsql.trigger /var/lib/postgresql/archive %f %p
%r 2 | /var/lib/postgresql/prepend_timestamp.sh >>
/var/lib/postgresql/standby.log'

As I said I tried several things like not redirecting to a file,
redirecting in the script etc.

I guess the next thing to try is to tail the log file and create a new
log file with the timestamps.

Re: timestams in the the pg_standby output

От
Greg Smith
Дата:
Tim Uckun wrote:
> I guess the next thing to try is to tail the log file and create a new
> log file with the timestamps.
>

See, told you it was harder than it looked :)

I knew there was a gotcha here in the seemingly easy way to approach
this but just couldn't remember the details of why it fell apart.
There's a gotcha in running "tail -f" into some programs too--for
example, to pipe that into grep you need to change grep's buffering
mode.  I suspect the Perl program I suggested will look less like
overkill by the time you're done here.

--
Greg Smith    2ndQuadrant   Baltimore, MD
PostgreSQL Training, Services and Support
greg@2ndQuadrant.com  www.2ndQuadrant.com