Обсуждение: Database copy

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

Database copy

От
Kim Heckler
Дата:

All,

 

I have read in the CREATE DATABASE documentation:

 

Although it is possible to copy a database other than template1 by specifying its name as the template, this is not (yet) intended as a general-purpose COPY DATABASE facility. The principal limitation is that no other sessions can be connected to the template database while it is being copied. CREATE DATABASE will fail if any other connection exists when it starts; otherwise, new connections to the template database are locked out until CREATE DATABASE completes. See Section 22.3 for more information.

 

Can I safely use this on a regular basis to copy a database within the same instance/server?  If not, I’ll use pg_dump and pg_restore to complete the ask.

 

Thank you.

 

 

Re: Database copy

От
Bruce Momjian
Дата:
On Thu, Jun  3, 2021 at 05:01:16PM +0000, Kim Heckler wrote:
> All,
> 
>  
> 
> I have read in the CREATE DATABASE documentation:
> 
>  
> 
> Although it is possible to copy a database other than template1 by specifying
> its name as the template, this is not (yet) intended as a general-purpose “COPY
> DATABASE” facility. The principal limitation is that no other sessions can be
> connected to the template database while it is being copied. CREATE DATABASE
> will fail if any other connection exists when it starts; otherwise, new
> connections to the template database are locked out until CREATE DATABASE
> completes. See Section 22.3 for more information.
> 
>  
> 
> Can I safely use this on a regular basis to copy a database within the same
> instance/server?  If not, I’ll use pg_dump and pg_restore to complete the ask.

Yes, you can use it as long as you accept its limitations of locking. 
It is used all the time.

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  If only the physical world exists, free will is an illusion.