Good day! Given: Linux - server with postgresql 9.4.

HDD 350 GB

DB work on this server. It takes 100 GB.

I need to make two more copies of the database on the same server (work2 and work3). Method pg_dump I do not have enough space.

How to copy the database?

ps I do not need a backup. I need a copy with which I will work further. Copies will continue to change. Compression does not help - in fact 20-30 gigs will remain on the server if you make three copies. Does not fit.

  • And, that is, you want to fit 3 identical bases on one server? So if the base weighs 100 GB, you will still have no more than 50 GB, 20-30 is normal. And why do you, by the way? Maybe your task can be done easier. - D-side
  • Yes that's right. Three bases. I need to make various changes to these bases (From one base, one is deleted, and from the other, another) and to start a tricky processing. The fact that no more than 50 GB is normal. The problem is that imagine: 100 GB base. 100GB Dump. 100 GB second base. Total occupied 300. And you need to load another 100 gig to postgres. - Alexandr Blinov
  • Make a backup to another server, a computer, a portable fisk and restore it to the other two bases - Sergey
  • This is a virtual machine, in the cloud, with a sad channel. The task was to do everything without adding space. - Alexandr Blinov

2 answers 2

Found a way. It was necessary to carefully read the documentation .

Run from postgres user:

$ pg_dump -h localhost work | psql -h localhost work2 

You can rotate the "create from template " if no one is connected to the source database (no writing transactions):

 createdb -T старая новая 

Details in man createdb .

  • But the data is not copied to the new database? - Sergey
  • @Sergey what is this all of a sudden? A full copy of the entire database , all objects, including rows. Then there is a restriction so that no one writes data at that time. - D-side
  • The manual does not say that the template == structure + data. Just some teplate and all. - Sergey
  • @Sergey strings are also objects. And they are also copied. Check for yourself if you don't believe :) - D-side