Thread: Creating new cluster by copying directory?

Creating new cluster by copying directory?

From
Wells Oliver
Date:
All: it would take ~4 hours to pg_restore a backup. I want to quickly create a duplicate cluster (for testing). My idea:

1. pg_ctlcreatecluster 9.1 test
2. rm /var/lib/postgresql/9.1/test/*
2. cp /var/lib/postgresql/9.1/main /var/lib/postgresql/9.1/test
3. pg_ctlcluster 9.1 test start

Is this viable? If not, is there another way to create a duplicate cluster in a timely fashion?

--
Wells Oliver
wellsoliver@gmail.com

Re: Creating new cluster by copying directory?

From
"Gilberto Castillo"
Date:

> All: it would take ~4 hours to pg_restore a backup. I want to quickly
> create a duplicate cluster (for testing). My idea:
>
> 1. pg_ctlcreatecluster 9.1 test
> 2. rm /var/lib/postgresql/9.1/test/*
> 2. cp /var/lib/postgresql/9.1/main /var/lib/postgresql/9.1/test
> 3. pg_ctlcluster 9.1 test start
>
> Is this viable? If not, is there another way to create a duplicate cluster
> in a timely fashion?

Test Repmgr works with the same philosophy. ;-)


Saludos,
Gilberto Castillo
La Habana, Cuba
---
This message was processed by Kaspersky Mail Gateway 5.6.28/RELEASE running at host imx3.etecsa.cu
Visit our web-site: <http://www.kaspersky.com>, <http://www.viruslist.com>

Re: Creating new cluster by copying directory?

From
Wells Oliver
Date:
So it's safe to copy the files in /var/lib/postgresql/9.1/main to /var/lib/postgresql/9.1/test while main is running?


On Thu, Jul 11, 2013 at 1:41 PM, Gilberto Castillo <gilberto.castillo@etecsa.cu> wrote:


> All: it would take ~4 hours to pg_restore a backup. I want to quickly
> create a duplicate cluster (for testing). My idea:
>
> 1. pg_ctlcreatecluster 9.1 test
> 2. rm /var/lib/postgresql/9.1/test/*
> 2. cp /var/lib/postgresql/9.1/main /var/lib/postgresql/9.1/test
> 3. pg_ctlcluster 9.1 test start
>
> Is this viable? If not, is there another way to create a duplicate cluster
> in a timely fashion?

Test Repmgr works with the same philosophy. ;-)


Saludos,
Gilberto Castillo
La Habana, Cuba

---
This message was processed by Kaspersky Mail Gateway 5.6.28/RELEASE running at host imx3.etecsa.cu
Visit our web-site: <http://www.kaspersky.com>, <http://www.viruslist.com>




--
Wells Oliver
wellsoliver@gmail.com

Re: Creating new cluster by copying directory?

From
Kevin Grittner
Date:
Wells Oliver <wellsoliver@gmail.com> wrote:

> So it's safe to copy the files in /var/lib/postgresql/9.1/main to
> /var/lib/postgresql/9.1/test while main is running?

As long as you copy the whole $PGDATA tree while the source cluster
is stopped, or use PITR recovery techniques:

http://www.postgresql.org/docs/9.2/interactive/backup.html

Of course, the machines must be of the same architecture.

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: Creating new cluster by copying directory?

From
"Gilberto Castillo"
Date:

> So it's safe to copy the files in /var/lib/postgresql/9.1/main to
> /var/lib/postgresql/9.1/test while main is running?
>

Yes, but the server where copy  is stop.

Saludos,
Gilberto Castillo
La Habana, Cuba
---
This message was processed by Kaspersky Mail Gateway 5.6.28/RELEASE running at host imx3.etecsa.cu
Visit our web-site: <http://www.kaspersky.com>, <http://www.viruslist.com>

Re: Creating new cluster by copying directory?

From
Jerry Sievers
Date:
Wells Oliver <wellsoliver@gmail.com> writes:

> So it's safe to copy the files in /var/lib/postgresql/9.1/main to /var/lib/postgresql/9.1/test while main is running?

Yes, provided that you put main in backup mode and then do a PITR when
you bring up this new test instance.

If your main DB is running but absolutely idle, you might get away
just starting it in which case the postmaster will do a regular crash
recovery but I'll presume your source instance 'main' isn't idle.

Study the manual sections relating to backup/PITR.

HTH

> On Thu, Jul 11, 2013 at 1:41 PM, Gilberto Castillo <gilberto.castillo@etecsa.cu> wrote:
>
>     > All: it would take ~4 hours to pg_restore a backup. I want to quickly
>     > create a duplicate cluster (for testing). My idea:
>     >
>     > 1. pg_ctlcreatecluster 9.1 test
>     > 2. rm /var/lib/postgresql/9.1/test/*
>     > 2. cp /var/lib/postgresql/9.1/main /var/lib/postgresql/9.1/test
>     > 3. pg_ctlcluster 9.1 test start
>     >
>     > Is this viable? If not, is there another way to create a duplicate cluster
>     > in a timely fashion?
>
>     Test Repmgr works with the same philosophy. ;-)
>
>     Saludos,
>     Gilberto Castillo
>     La Habana, Cuba
>
>     ---
>     This message was processed by Kaspersky Mail Gateway 5.6.28/RELEASE running at host imx3.etecsa.cu
>     Visit our web-site: <http://www.kaspersky.com>, <http://www.viruslist.com>
>
> --
> Wells Oliver
> wellsoliver@gmail.com
>

--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres.consulting@comcast.net
p: 312.241.7800


Re: Creating new cluster by copying directory?

From
Wells Oliver
Date:
Hmm, is it feasible to create a new cluster by using pg_basebackup, e.g:

1. pg_createcluster 9.1 test
2. pg_basebackup --pgdata=/var/lib/postgresql/9.1/test -h localhost -p 5432
3. pg_ctlcluster 9.1 test start

Would that work?


On Thu, Jul 11, 2013 at 1:54 PM, Jerry Sievers <gsievers19@comcast.net> wrote:
Wells Oliver <wellsoliver@gmail.com> writes:

> So it's safe to copy the files in /var/lib/postgresql/9.1/main to /var/lib/postgresql/9.1/test while main is running?

Yes, provided that you put main in backup mode and then do a PITR when
you bring up this new test instance.

If your main DB is running but absolutely idle, you might get away
just starting it in which case the postmaster will do a regular crash
recovery but I'll presume your source instance 'main' isn't idle.

Study the manual sections relating to backup/PITR.

HTH

> On Thu, Jul 11, 2013 at 1:41 PM, Gilberto Castillo <gilberto.castillo@etecsa.cu> wrote:
>
>     > All: it would take ~4 hours to pg_restore a backup. I want to quickly
>     > create a duplicate cluster (for testing). My idea:
>     >
>     > 1. pg_ctlcreatecluster 9.1 test
>     > 2. rm /var/lib/postgresql/9.1/test/*
>     > 2. cp /var/lib/postgresql/9.1/main /var/lib/postgresql/9.1/test
>     > 3. pg_ctlcluster 9.1 test start
>     >
>     > Is this viable? If not, is there another way to create a duplicate cluster
>     > in a timely fashion?
>
>     Test Repmgr works with the same philosophy. ;-)
>
>     Saludos,
>     Gilberto Castillo
>     La Habana, Cuba
>
>     ---
>     This message was processed by Kaspersky Mail Gateway 5.6.28/RELEASE running at host imx3.etecsa.cu
>     Visit our web-site: <http://www.kaspersky.com>, <http://www.viruslist.com>
>
> --
> Wells Oliver
> wellsoliver@gmail.com
>

--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres.consulting@comcast.net
p: 312.241.7800



--
Wells Oliver
wellsoliver@gmail.com

Re: Creating new cluster by copying directory?

From
Sergey Konoplev
Date:
On Thu, Jul 11, 2013 at 2:36 PM, Wells Oliver <wellsoliver@gmail.com> wrote:
> Hmm, is it feasible to create a new cluster by using pg_basebackup, e.g:
>
> 1. pg_createcluster 9.1 test
> 2. pg_basebackup --pgdata=/var/lib/postgresql/9.1/test -h localhost -p 5432
> 3. pg_ctlcluster 9.1 test start
>
> Would that work?

It should work. I would also suggest you to use --xlog-method=stream
so the copy will be more caught up.

-X method
--xlog-method=method

Includes the required transaction log files (WAL files) in the backup.
This will include all transaction logs generated during the backup. If
this option is specified, it is possible to start a postmaster
directly in the extracted directory without the need to consult the
log archive, thus making this a completely standalone backup.

The following methods for collecting the transaction logs are supported:

[skipped]

s
stream

Stream the transaction log while the backup is created. This will open
a second connection to the server and start streaming the transaction
log in parallel while running the backup. Therefore, it will use up
two slots configured by the max_wal_senders parameter. As long as the
client can keep up with transaction log received, using this mode
requires no extra transaction logs to be saved on the master.



>
>
> On Thu, Jul 11, 2013 at 1:54 PM, Jerry Sievers <gsievers19@comcast.net>
> wrote:
>>
>> Wells Oliver <wellsoliver@gmail.com> writes:
>>
>> > So it's safe to copy the files in /var/lib/postgresql/9.1/main to
>> > /var/lib/postgresql/9.1/test while main is running?
>>
>> Yes, provided that you put main in backup mode and then do a PITR when
>> you bring up this new test instance.
>>
>> If your main DB is running but absolutely idle, you might get away
>> just starting it in which case the postmaster will do a regular crash
>> recovery but I'll presume your source instance 'main' isn't idle.
>>
>> Study the manual sections relating to backup/PITR.
>>
>> HTH
>>
>> > On Thu, Jul 11, 2013 at 1:41 PM, Gilberto Castillo
>> > <gilberto.castillo@etecsa.cu> wrote:
>> >
>> >     > All: it would take ~4 hours to pg_restore a backup. I want to
>> > quickly
>> >     > create a duplicate cluster (for testing). My idea:
>> >     >
>> >     > 1. pg_ctlcreatecluster 9.1 test
>> >     > 2. rm /var/lib/postgresql/9.1/test/*
>> >     > 2. cp /var/lib/postgresql/9.1/main /var/lib/postgresql/9.1/test
>> >     > 3. pg_ctlcluster 9.1 test start
>> >     >
>> >     > Is this viable? If not, is there another way to create a duplicate
>> > cluster
>> >     > in a timely fashion?
>> >
>> >     Test Repmgr works with the same philosophy. ;-)
>> >
>> >     Saludos,
>> >     Gilberto Castillo
>> >     La Habana, Cuba
>> >
>> >     ---
>> >     This message was processed by Kaspersky Mail Gateway 5.6.28/RELEASE
>> > running at host imx3.etecsa.cu
>> >     Visit our web-site: <http://www.kaspersky.com>,
>> > <http://www.viruslist.com>
>> >
>> > --
>> > Wells Oliver
>> > wellsoliver@gmail.com
>> >
>>
>> --
>> Jerry Sievers
>> Postgres DBA/Development Consulting
>> e: postgres.consulting@comcast.net
>> p: 312.241.7800
>
>
>
>
> --
> Wells Oliver
> wellsoliver@gmail.com



--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

Profile: http://www.linkedin.com/in/grayhemp
Phone: USA +1 (415) 867-9984, Russia +7 (901) 903-0499, +7 (988) 888-1979
Skype: gray-hemp
Jabber: gray.ru@gmail.com