Обсуждение: WAL shipping question

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

WAL shipping question

От
SHARMILA JOTHIRAJAH
Дата:
Hi,
Im trying to play a bit with log shipping between 2 servers primary and standby. These servers are running versions 8.3betat3. I had set up continuous archiving at the primary server. The manuals' example of archive_command is
archive_command = 'cp -i %p /mnt/server/archivedir/%f </dev/null'

This basically archives the data in the primary server itself...right!!!
But how can I set up continuous archiving from primary to a directory (WAL archive directory)
on the stand-by server ?

Thanks
sharmila



Never miss a thing. Make Yahoo your homepage.

Re: WAL shipping question

От
Richard Huxton
Дата:
SHARMILA JOTHIRAJAH wrote:
> Hi,
> Im trying to play a bit with log shipping between 2 servers primary and standby. These servers are running versions
8.3betat3.I had set up continuous archiving at the primary server. The manuals' example of archive_command is 
> archive_command = 'cp -i %p /mnt/server/archivedir/%f </dev/null'
>
> This basically archives the data in the primary server itself...right!!!
> But how can I set up continuous archiving from primary to a directory (WAL archive directory)
> on the stand-by server ?

a. Mount the remote directory via NFS/SMBFS/...
b. Use a remote copy, e.g. scp, FTP...

--
   Richard Huxton
   Archonet Ltd

Re: WAL shipping question

От
SHARMILA JOTHIRAJAH
Дата:

> Im trying to play a bit with log shipping between 2 servers primary and standby. These servers are running versions 8.3betat3. I had set up continuous archiving at the primary server. The manuals' example of archive_command is
> archive_command = 'cp -i %p /mnt/server/archivedir/%f </dev/null'
>
> This basically archives the data in the primary server itself...right!!!
> But how can I set up continuous archiving from primary to a directory (WAL archive directory)
> on the stand-by server ?

>>a. Mount the remote directory via NFS/SMBFS/...
>>b. Use a remote copy, e.g. scp, FTP...


Thanks...
I tried this command to both copy in the primary server and scp to standby server.

archive_command = 'cp -i "%p" .../archivedir/"%f" &&
scp -B "%p".../archivedir/"%f"  "%p" user@172.31.0.21:/....archivedir/"%f"'

cp works but scp doesnt work. Is it becoz scp generally asks for password. I can do scp or ssh without password authentication but Im not sure if it is safe to do that.

What is the alternative for getting this done?

Thanks
sharmila









Get easy, one-click access to your favorites. Make Yahoo! your homepage.

Re: WAL shipping question

От
Richard Huxton
Дата:
SHARMILA JOTHIRAJAH wrote:
>> Im trying to play a bit with log shipping between 2 servers primary
>  and standby. These servers are running versions 8.3betat3. I had set up
>  continuous archiving at the primary server. The manuals' example of
>  archive_command is
>> archive_command = 'cp -i %p /mnt/server/archivedir/%f </dev/null'
>>
>> This basically archives the data in the primary server
>  itself...right!!!
>> But how can I set up continuous archiving from primary to a directory
>  (WAL archive directory)
>> on the stand-by server ?
>
>>> a. Mount the remote directory via NFS/SMBFS/...
>>> b. Use a remote copy, e.g. scp, FTP...
>
>
> Thanks...
> I tried this command to both copy in the primary server and scp to standby server.
>
> archive_command = 'cp -i "%p" .../archivedir/"%f" &&
> scp -B "%p".../archivedir/"%f"  "%p" user@172.31.0.21:/....archivedir/"%f"'
>
> cp works but scp doesnt work. Is it becoz scp generally asks for password. I can do scp or ssh without password
authenticationbut Im not sure if it is safe to do that. 
>
> What is the alternative for getting this done?

You can generate a public/private key pair on the database server and
store the public version in ~/.ssh/authorized_keys on the remote server.
Google for details.

--
   Richard Huxton
   Archonet Ltd

Re: WAL shipping question

От
Greg Smith
Дата:
On Tue, 4 Dec 2007, SHARMILA JOTHIRAJAH wrote:

> This basically archives the data in the primary server itself...right!!!
> But how can I set up continuous archiving from primary to a directory
> (WAL archive directory) on the stand-by server ?

The closest thing to a worked out example of how to do this I'm aware of
is at http://archives.postgresql.org/sydpug/2006-10/msg00001.php

That uses rsync as the transport mechanism for reasons it explains (the
'atomic copy' feature).  You can certainly replicate that using ssh, but
you may have to use a secondary directory to hold files while they're
being transferred so the stand-by doesn't try to do something with the
partial copies.  Mounting filesystems and copying the files over
Samba/NFS/etc. is another approach with its own issues.  It's been my
experience that remote filesystems will hang in odd ways when there's a
connectivity problem, while copying with ssh/scp gives you a more
predictable copied/failed return code without retrying too hard.
PostgreSQL can tolerate the archive_command spitting back an error just
fine and will retry automatically, I prefer not to expose the server to a
situation where the archive_command might not return quickly.

The main thing that's improved in 8.3 is the integration of pg_standby as
a more rugged restore_command than most people were coding on their own:

http://www.postgresql.org/docs/8.3/static/pgstandby.html

You should use it instead of the example restore.sh included in the
message I referenced above.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

Re: WAL shipping question

От
SHARMILA JOTHIRAJAH
Дата:

> This basically archives the data in the primary server itself...right!!!
> But how can I set up continuous archiving from primary to a directory
> (WAL archive directory) on the stand-by server ?

The closest thing to a worked out example of how to do this I'm aware of
is at http://archives.postgresql.org/sydpug/2006-10/msg00001.php

That uses rsync as the transport mechanism for reasons it explains (the
'atomic copy' feature).  You can certainly replicate that using ssh, but
you may have to use a secondary directory to hold files while they're
being transferred so the stand-by doesn't try to do something with the
partial copies.  Mounting filesystems and copying the files over
Samba/NFS/etc. is another approach with its own issues.  It's been my
experience that remote filesystems will hang in odd ways when there's a
connectivity problem, while copying with ssh/scp gives you a more
predictable copied/failed return code without retrying too hard.
PostgreSQL can tolerate the archive_command spitting back an error just
fine and will retry automatically, I prefer not to expose the server to a
situation where the archive_command might not return quickly.

The main thing that's improved in 8.3 is the integration of pg_standby as
a more rugged restore_command than most people were coding on their own:

http://www.postgresql.org/docs/8.3/static/pgstandby.html

You should use it instead of the example restore.sh included in the
message I referenced above.

Thanks for your reply. I will look into the pg_standby  and rsync.

I currently have this in my config file

archive_command = 'cp -i "%p" /export/home/user/archivedir/"%f" &&
scp -i userKey "%p" user@172.31.0.27:/export/home/user/archivedir/"%f"'

userKey is a public-private key generated without the passphrase. This works...
   scp -i userKey dummy user@172.31.0.27:/export/home/user/archivedir
and it just copies the dummy file from primary to standby without prompting for a password.

It doesnt scp the wal files from primary to stand-by when i add it to archive_command as given above. I get this error
Warning: Identity file userKey does not exist.
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
Write failed: Broken pipe
lost connection
LOG:  archive command "cp -i "pg_xlog/000000010000000000000039" /export/home/user/archivedir/"000000010000000000000039" && scp -i userKey "pg_xlog/000000010000000000000039" user@172.31.0.27:/export/home/user/archivedir/"000000010000000000000039"" failed: return code 256




Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.

Re: WAL shipping question

От
SHARMILA JOTHIRAJAH
Дата:


> This basically archives the data in the primary server itself...right!!!
> But how can I set up continuous archiving from primary to a directory
> (WAL archive directory) on the stand-by server ?

>>The closest thing to a worked out example of how to do this I'm aware of
>>is at http://archives.postgresql.org/sydpug/2006-10/msg00001.php

I tried this example
I have the primary and standby server setup. The primary server is archiving the wal segments in the standby server's directory. My question is that, as per that example in step 15 the standby server should gives messages in its log whenever some WAL activity is triggered in the master. I see the archive directory in standby server getting filled up, but there are no log messages generated. Whay? What am I missing here?

Also what does step 16 mean in that above example?
" To initiate a failover from the master to the slave, create the 'trigger file':
touch ~/pg82demo/trigger
This should immediately cause the slave to finish processing archived
segments, exitrecovery mode, and come up ready for use "


Does the wal archives are applied to the standby server at this point and it has all the
contents(tables,indexes,tabledata etc) at this point?

Thanks
sharmila






Never miss a thing. Make Yahoo your homepage.

Re: WAL shipping question

От
Erik Jones
Дата:
On Dec 5, 2007, at 1:39 PM, SHARMILA JOTHIRAJAH wrote:

>
>
> > This basically archives the data in the primary server
> itself...right!!!
> > But how can I set up continuous archiving from primary to a
> directory
> > (WAL archive directory) on the stand-by server ?
>
> >>The closest thing to a worked out example of how to do this I'm
> aware of
> >>is at http://archives.postgresql.org/sydpug/2006-10/msg00001.php
>
> I tried this example
> I have the primary and standby server setup. The primary server is
> archiving the wal segments in the standby server's directory. My
> question is that, as per that example in step 15 the standby server
> should gives messages in its log whenever some WAL activity is
> triggered in the master. I see the archive directory in standby
> server getting filled up, but there are no log messages generated.
> Whay? What am I missing here?

Make sure you're looking in the whatever location you have postgres
configured to log in.  If you're still not seeing log messages there,
then you've done something wrong.

> Also what does step 16 mean in that above example?
> " To initiate a failover from the master to the slave, create the
> 'trigger file':
> touch ~/pg82demo/trigger
> This should immediately cause the slave to finish processing archived
> segments, exit  recovery mode, and come up ready for use "

touch is a *nix utility (maybe on windows, too?) that simply creates
a file if it doesn't exist.  In the example standby implementation in
the linked post, the recovery.sh script looks for the existence of
that file named trigger in pg82demo/ and, if it sees it, brings the
standby out of recovery mode and into normal operation.
>
>
> Does the wal archives are applied to the standby server at this
> point and it has all the
> contents(tables,indexes,tabledata etc) at this point?

If you're not getting log output to the effect of wals being
replayed, then no.

Erik Jones

Software Developer | Emma®
erik@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com



Re: WAL shipping question

От
Greg Smith
Дата:
On Wed, 5 Dec 2007, SHARMILA JOTHIRAJAH wrote:

> I see the archive directory in standby server getting filled up, but
> there are no log messages generated. Whay? What am I missing here?

If you're using pg_standby, you can pass it -d to have it log more
information about what's going on, which may help you figure out your
issue.  It may be that you need to adjust the logging settings in the
postgresql.conf file as well.

--
* Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD

Re: WAL shipping question

От
SHARMILA JOTHIRAJAH
Дата:


>The main thing that's improved in 8.3 is the integration of pg_standby as
>a more rugged restore_command than most people were coding on their own:

>http://www.postgresql.org/docs/8.3/static/pgstandby.html

>You should use it instead of the example restore.sh included in the
>message I referenced above.

How do you install pg_standby. I get the following error when i try the Makefile

sj@sys1:~/postgres8.3/pgsql> /export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 3: PROGRAM: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 4: OBJS: command not found
/export/home/sjpostgresql-8.3beta3/contrib/pg_standby/Makefile: line 6: libpq_srcdir: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 6: PG_CPPFLAGS: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 7: libpq_pgport: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 7: PG_LIBS: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 9: ifdef: command not found
/export/home/sjpostgresql-8.3beta3/contrib/pg_standby/Makefile: line 10: PG_CONFIG: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 11: PG_CONFIG: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 11: shell: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 11: PGXS: command not found
/export/home/sjpostgresql-8.3beta3/contrib/pg_standby/Makefile: line 12: PGXS: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 12: include: command not found
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 13: syntax error near unexpected token `else'
/export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile: line 13: `else'

Thanks
sharmila


Never miss a thing. Make Yahoo your homepage.

Re: WAL shipping question

От
Alvaro Herrera
Дата:
SHARMILA JOTHIRAJAH wrote:

> How do you install pg_standby. I get the following error when i try the Makefile
>
> sj@sys1:~/postgres8.3/pgsql> /export/home/sj/postgresql-8.3beta3/contrib/pg_standby/Makefile

The Makefile is not a shell script.  Run just "make" and then "make
install".

--
Alvaro Herrera                 http://www.amazon.com/gp/registry/CTMLCN8V17R4
"You knock on that door or the sun will be shining on places inside you
that the sun doesn't usually shine" (en Death: "The High Cost of Living")