pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Methods to quickly spin up copies of an existing databases
7+ messages / 6 participants
[nested] [flat]

* Methods to quickly spin up copies of an existing databases
@ 2019-03-01 20:08 Arjun Ranade <ranade@nodalexchange.com>
  2019-03-01 19:57 ` Re: Methods to quickly spin up copies of an existing databases Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Arjun Ranade @ 2019-03-01 20:08 UTC (permalink / raw)
  To: pgsql-general

I'm working on a project that requires on-demand creation of a fresh
database as quick as possible (seconds).  Essentially, this is a build
server that will require a cloned instance of Postgres to run unit tests
on.  So the pattern of use would be:


   - Build is triggered
   - New postgres instance is created and connection details are provided
   to build server
   - Build runs unit tests that connect to the database
   - Build completes, database is no longer needed and can be thrown away

The "template" database will be approximately 50gb in size so my question
is what is the fastest way to spin up new instances of this database?  I've
thought of using "CREATE DATABASE WITH TEMPLATE..." but that takes too
long.  I've also thought about cloning the $PGDATA directory, changing the
port number in postgresql.conf, and starting a new instance of postgres
pointing to the cloned data directory.

Both of these methods take longer than I'd like, so I'm wondering if anyone
else has this use case and what methods they've used to solve this.

Thanks,
Arjun

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Methods to quickly spin up copies of an existing databases
  2019-03-01 20:08 Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
@ 2019-03-01 19:57 ` Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  2019-03-01 20:00   ` Re: Methods to quickly spin up copies of an existing databases Kenneth Marshall <ktm@rice.edu>
  0 siblings, 1 reply; 7+ messages in thread

From: Kevin Wilkinson @ 2019-03-01 19:57 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

if you are able/willing to use ZFS (rather than ext4, xfs, ...) to store 
your database, then it might work for you. ZFS is copy-on-write so it 
can very quickly clone a database.

kevin

On 3/1/2019 12:08 PM, Arjun Ranade wrote:
> I'm working on a project that requires on-demand creation of a fresh 
> database as quick as possible (seconds). Essentially, this is a build 
> server that will require a cloned instance of Postgres to run unit 
> tests on.  So the pattern of use would be:
>
>   * Build is triggered
>   * New postgres instance is created and connection details are
>     provided to build server
>   * Build runs unit tests that connect to the database
>   * Build completes, database is no longer needed and can be thrown away
>
> The "template" database will be approximately 50gb in size so my 
> question is what is the fastest way to spin up new instances of this 
> database?  I've thought of using "CREATE DATABASE WITH TEMPLATE..." 
> but that takes too long. I've also thought about cloning the $PGDATA 
> directory, changing the port number in postgresql.conf, and starting a 
> new instance of postgres pointing to the cloned data directory.
>
> Both of these methods take longer than I'd like, so I'm wondering if 
> anyone else has this use case and what methods they've used to solve this.
>
> Thanks,
> Arjun

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Methods to quickly spin up copies of an existing databases
  2019-03-01 20:08 Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
  2019-03-01 19:57 ` Re: Methods to quickly spin up copies of an existing databases Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
@ 2019-03-01 20:00   ` Kenneth Marshall <ktm@rice.edu>
  2019-03-01 21:08     ` Re: Methods to quickly spin up copies of an existing databases Jerry Sievers <gsievers19@comcast.net>
  0 siblings, 1 reply; 7+ messages in thread

From: Kenneth Marshall @ 2019-03-01 20:00 UTC (permalink / raw)
  To: Kevin Wilkinson <w.kevin.wilkinson@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

On Fri, Mar 01, 2019 at 11:57:30AM -0800, Kevin Wilkinson wrote:
> if you are able/willing to use ZFS (rather than ext4, xfs, ...) to
> store your database, then it might work for you. ZFS is
> copy-on-write so it can very quickly clone a database.
> 
> kevin

Hi Arjun

Redhat 7 does have LVM snapshots that does something similar. Kevin is
correct, COW is the secret.

Regards,
Ken




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Methods to quickly spin up copies of an existing databases
  2019-03-01 20:08 Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
  2019-03-01 19:57 ` Re: Methods to quickly spin up copies of an existing databases Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  2019-03-01 20:00   ` Re: Methods to quickly spin up copies of an existing databases Kenneth Marshall <ktm@rice.edu>
@ 2019-03-01 21:08     ` Jerry Sievers <gsievers19@comcast.net>
  2019-03-01 21:28       ` Re: Methods to quickly spin up copies of an existing databases Bruce Klein <brucek@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Jerry Sievers @ 2019-03-01 21:08 UTC (permalink / raw)
  To: Kenneth Marshall <ktm@rice.edu>; +Cc: Kevin Wilkinson <w.kevin.wilkinson@gmail.com>; pgsql-general@lists.postgresql.org

Kenneth Marshall <ktm@rice.edu> writes:

> On Fri, Mar 01, 2019 at 11:57:30AM -0800, Kevin Wilkinson wrote:
>
>> if you are able/willing to use ZFS (rather than ext4, xfs, ...) to
>> store your database, then it might work for you. ZFS is
>> copy-on-write so it can very quickly clone a database.
>> 
>> kevin
>
> Hi Arjun
>
> Redhat 7 does have LVM snapshots that does something similar. Kevin is
> correct, COW is the secret.

Going a bit further...

Any sort of storage backend that can support *atomic* snapshots across
*all* volumes (in case multiple tablespaces ar involved), can be used to
permit $instantaneous cloning where instantaneous relates to the actual
snapshot time and crash recovery.

Inability to make *atomic* snaps but perhaps seperate snaps very
quickly, combined with PITR can result in clones of high-churn systems
sized in TBs (as in our use case) to be provisioned in about 1 minute.

Nothing but the most trivial system can be cloned rapidly and perhaps
any number of times in succession without employment of
thin-provisioning, copy-on-write (as mentioned already), etc.

                   Virtual copy is more and more compelling as physical
                   size, or more precisely, *physical* copy time grow.

HTH



>
> Regards,
> Ken
>
>

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




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Methods to quickly spin up copies of an existing databases
  2019-03-01 20:08 Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
  2019-03-01 19:57 ` Re: Methods to quickly spin up copies of an existing databases Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  2019-03-01 20:00   ` Re: Methods to quickly spin up copies of an existing databases Kenneth Marshall <ktm@rice.edu>
  2019-03-01 21:08     ` Re: Methods to quickly spin up copies of an existing databases Jerry Sievers <gsievers19@comcast.net>
@ 2019-03-01 21:28       ` Bruce Klein <brucek@gmail.com>
  2019-03-01 21:51         ` Re: Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Bruce Klein @ 2019-03-01 21:28 UTC (permalink / raw)
  To: Jerry Sievers <gsievers19@comcast.net>; +Cc: Kenneth Marshall <ktm@rice.edu>; Kevin Wilkinson <w.kevin.wilkinson@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Apologies for the low tech suggestion, but if this really is a clone of a
previously existing template, could the clone operation just be done ahead
of time? I.e., have the build server keep X copies ready for use and
generate additional copies as those are consumed, so that the cloning is no
longer on the critical path?

On Fri, Mar 1, 2019 at 11:09 AM Jerry Sievers <gsievers19@comcast.net>
wrote:

> Kenneth Marshall <ktm@rice.edu> writes:
>
> > On Fri, Mar 01, 2019 at 11:57:30AM -0800, Kevin Wilkinson wrote:
> >
> >> if you are able/willing to use ZFS (rather than ext4, xfs, ...) to
> >> store your database, then it might work for you. ZFS is
> >> copy-on-write so it can very quickly clone a database.
> >>
> >> kevin
> >
> > Hi Arjun
> >
> > Redhat 7 does have LVM snapshots that does something similar. Kevin is
> > correct, COW is the secret.
>
> Going a bit further...
>
> Any sort of storage backend that can support *atomic* snapshots across
> *all* volumes (in case multiple tablespaces ar involved), can be used to
> permit $instantaneous cloning where instantaneous relates to the actual
> snapshot time and crash recovery.
>
> Inability to make *atomic* snaps but perhaps seperate snaps very
> quickly, combined with PITR can result in clones of high-churn systems
> sized in TBs (as in our use case) to be provisioned in about 1 minute.
>
> Nothing but the most trivial system can be cloned rapidly and perhaps
> any number of times in succession without employment of
> thin-provisioning, copy-on-write (as mentioned already), etc.
>
>                    Virtual copy is more and more compelling as physical
>                    size, or more precisely, *physical* copy time grow.
>
> HTH
>
>
>
> >
> > Regards,
> > Ken
> >
> >
>
> --
> Jerry Sievers
> Postgres DBA/Development Consulting
> e: postgres.consulting@comcast.net
>
>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Methods to quickly spin up copies of an existing databases
  2019-03-01 20:08 Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
  2019-03-01 19:57 ` Re: Methods to quickly spin up copies of an existing databases Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  2019-03-01 20:00   ` Re: Methods to quickly spin up copies of an existing databases Kenneth Marshall <ktm@rice.edu>
  2019-03-01 21:08     ` Re: Methods to quickly spin up copies of an existing databases Jerry Sievers <gsievers19@comcast.net>
  2019-03-01 21:28       ` Re: Methods to quickly spin up copies of an existing databases Bruce Klein <brucek@gmail.com>
@ 2019-03-01 21:51         ` Arjun Ranade <ranade@nodalexchange.com>
  2019-03-02 13:16           ` Re: Methods to quickly spin up copies of an existing databases Karsten Hilbert <Karsten.Hilbert@gmx.net>
  0 siblings, 1 reply; 7+ messages in thread

From: Arjun Ranade @ 2019-03-01 21:51 UTC (permalink / raw)
  To: Bruce Klein <brucek@gmail.com>; +Cc: Jerry Sievers <gsievers19@comcast.net>; Kenneth Marshall <ktm@rice.edu>; Kevin Wilkinson <w.kevin.wilkinson@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Pre-copying is not really an option since we could potentially need 1-X
instances so it needs to be scalable.  XFS also allows for "cp --reflink"
which I could do on a PGDATA directory and then change the port number.
That's probably the method I'll try first.

We do use barman, but again a barman recover operation is pretty much just
an rsync.

I will first try XFS, then ZFS, and if those don't work, I'll look into a
SAN option.



On Fri, Mar 1, 2019 at 4:29 PM Bruce Klein <brucek@gmail.com> wrote:

> Apologies for the low tech suggestion, but if this really is a clone of a
> previously existing template, could the clone operation just be done ahead
> of time? I.e., have the build server keep X copies ready for use and
> generate additional copies as those are consumed, so that the cloning is no
> longer on the critical path?
>
> On Fri, Mar 1, 2019 at 11:09 AM Jerry Sievers <gsievers19@comcast.net>
> wrote:
>
>> Kenneth Marshall <ktm@rice.edu> writes:
>>
>> > On Fri, Mar 01, 2019 at 11:57:30AM -0800, Kevin Wilkinson wrote:
>> >
>> >> if you are able/willing to use ZFS (rather than ext4, xfs, ...) to
>> >> store your database, then it might work for you. ZFS is
>> >> copy-on-write so it can very quickly clone a database.
>> >>
>> >> kevin
>> >
>> > Hi Arjun
>> >
>> > Redhat 7 does have LVM snapshots that does something similar. Kevin is
>> > correct, COW is the secret.
>>
>> Going a bit further...
>>
>> Any sort of storage backend that can support *atomic* snapshots across
>> *all* volumes (in case multiple tablespaces ar involved), can be used to
>> permit $instantaneous cloning where instantaneous relates to the actual
>> snapshot time and crash recovery.
>>
>> Inability to make *atomic* snaps but perhaps seperate snaps very
>> quickly, combined with PITR can result in clones of high-churn systems
>> sized in TBs (as in our use case) to be provisioned in about 1 minute.
>>
>> Nothing but the most trivial system can be cloned rapidly and perhaps
>> any number of times in succession without employment of
>> thin-provisioning, copy-on-write (as mentioned already), etc.
>>
>>                    Virtual copy is more and more compelling as physical
>>                    size, or more precisely, *physical* copy time grow.
>>
>> HTH
>>
>>
>>
>> >
>> > Regards,
>> > Ken
>> >
>> >
>>
>> --
>> Jerry Sievers
>> Postgres DBA/Development Consulting
>> e: postgres.consulting@comcast.net
>>
>>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Methods to quickly spin up copies of an existing databases
  2019-03-01 20:08 Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
  2019-03-01 19:57 ` Re: Methods to quickly spin up copies of an existing databases Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
  2019-03-01 20:00   ` Re: Methods to quickly spin up copies of an existing databases Kenneth Marshall <ktm@rice.edu>
  2019-03-01 21:08     ` Re: Methods to quickly spin up copies of an existing databases Jerry Sievers <gsievers19@comcast.net>
  2019-03-01 21:28       ` Re: Methods to quickly spin up copies of an existing databases Bruce Klein <brucek@gmail.com>
  2019-03-01 21:51         ` Re: Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
@ 2019-03-02 13:16           ` Karsten Hilbert <Karsten.Hilbert@gmx.net>
  0 siblings, 0 replies; 7+ messages in thread

From: Karsten Hilbert @ 2019-03-02 13:16 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On Fri, Mar 01, 2019 at 04:51:32PM -0500, Arjun Ranade wrote:

> Pre-copying is not really an option since we could potentially need 1-X
> instances so it needs to be scalable.

Would it work to have a PG instance with a ready-to-use
cluster/DB inside a VM, and make a copy of that as needed ? 
The copies then get thrown away.

Same here, pre-copying a bunch of VMs would help. Disk space
is (apparently) cheaper than time (for your use case).

Karsten
-- 
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2019-03-02 13:16 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01 20:08 Methods to quickly spin up copies of an existing databases Arjun Ranade <ranade@nodalexchange.com>
2019-03-01 19:57 ` Kevin Wilkinson <w.kevin.wilkinson@gmail.com>
2019-03-01 20:00   ` Kenneth Marshall <ktm@rice.edu>
2019-03-01 21:08     ` Jerry Sievers <gsievers19@comcast.net>
2019-03-01 21:28       ` Bruce Klein <brucek@gmail.com>
2019-03-01 21:51         ` Arjun Ranade <ranade@nodalexchange.com>
2019-03-02 13:16           ` Karsten Hilbert <Karsten.Hilbert@gmx.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox