Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzoHv-0006Kr-P8 for pgsql-general@arkaria.postgresql.org; Fri, 01 Mar 2019 19:57:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzoHu-0003Jo-K0 for pgsql-general@arkaria.postgresql.org; Fri, 01 Mar 2019 19:57:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzoHu-0003Ja-BX for pgsql-general@lists.postgresql.org; Fri, 01 Mar 2019 19:57:42 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzoHs-0005XV-4y for pgsql-general@lists.postgresql.org; Fri, 01 Mar 2019 19:57:41 +0000 Received: by mail-pg1-x544.google.com with SMTP id u9so11920671pgo.7 for ; Fri, 01 Mar 2019 11:57:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=KxXwcc/fxnKrxBtnbAA01Oq8mjukHJOVEIb4FSbL+U4=; b=KgHXkBMneXOeXjVj4YIGAluC6yKlYajI8RNM+N5Cr7tV1URQMBGW/mUjcmG7u2aVVY oZb2l1U6DfFeF/mNuwLhE04rRm38YLNXrnm6K+ZJm9WqPMuegBev7GxZVmOEWKDJu6y0 0TJxW3T1i+Cmb06dWqXS9Uado5c5B3te4AMxUqD64Z8DAGymaUXeY5i7tiMMae7WZSEQ aBbcdCLal5gmRvQ94o5YWaeS4GcmgOph8BN+pnk+giJJDl5MsQO+zVA04aYhe9Lxd+ut S3FVwPRTCy3MziLf8vKbtZRpi7NUgeOhG5b8N3zBrVJStAdTBWmnSb0vnNzQ596e97sF F86g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=KxXwcc/fxnKrxBtnbAA01Oq8mjukHJOVEIb4FSbL+U4=; b=FqT64fO2M1tP7wR8PIYx46U6nkxBb+AWrJeE73NUBUtuDnHZUfMaOx4rjwCZaWagFf RGmq0o/TeCxtSrlLYAfRTYC9uXuET1DJToFHYVSaV7FY0InoYFP2jbZu3o05j+b8VQTC vFuemrIxjn/mg8oEx8xn2V950g1wXBHasjX5EYQ0pvTeNHbEQ/Fi/oDdoYYOchagfZkz gqCDXw2bkttUbZNjpzmlytYtabKB3GE2PUdU9h4sPYHc7LoNKWRqlFLS1Q4lUrtapMcF du8d4qj8cpq8qX3p5HONaBNQFSD7ymde6vm25UBsxPL+NoSZ94hZjrUhpnSdbRe2EX+5 0htA== X-Gm-Message-State: APjAAAVIzFYBdk4OCdRzDif3UPZKX47n/SlHbnxJYNP+kzJh7Xj9fYlm GNiFH0eo8Onh7dwBF1XI8qHDSEWR X-Google-Smtp-Source: APXvYqwHbkmHfBlxXUGeTvIpBC+udLeiTSQm1vFgfWd9/sOobuRSwCP+RqN0q/nUQ8mTdyjCAxxtww== X-Received: by 2002:a65:6651:: with SMTP id z17mr6150551pgv.95.1551470256852; Fri, 01 Mar 2019 11:57:36 -0800 (PST) Received: from [10.0.0.102] (c-73-223-6-106.hsd1.ca.comcast.net. [73.223.6.106]) by smtp.gmail.com with ESMTPSA id k72sm36170800pfb.122.2019.03.01.11.57.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 11:57:35 -0800 (PST) Subject: Re: Methods to quickly spin up copies of an existing databases To: pgsql-general@lists.postgresql.org References: From: Kevin Wilkinson Message-ID: Date: Fri, 1 Mar 2019 11:57:30 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------6BE7A5D732677032B6F62748" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------6BE7A5D732677032B6F62748 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------6BE7A5D732677032B6F62748 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

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
--------------6BE7A5D732677032B6F62748--