Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zg1hV-0004as-An for pgsql-docs@arkaria.postgresql.org; Sun, 27 Sep 2015 02:28:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zg1hT-0005i8-6I for pgsql-docs@arkaria.postgresql.org; Sun, 27 Sep 2015 02:28:27 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Zg1h6-0005L0-7Z for pgsql-docs@postgresql.org; Sun, 27 Sep 2015 02:28:04 +0000 Received: from mout.gmx.com ([74.208.4.200]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.84) (envelope-from ) id 1Zg1h3-00059m-1Q for pgsql-docs@postgresql.org; Sun, 27 Sep 2015 02:28:02 +0000 Received: from anaphora.localdomain ([5.102.218.194]) by mail.gmx.com (mrgmxus002) with ESMTPSA (Nemesis) id 0M6Ryf-1acf5i4Bz9-00yTKd for ; Sun, 27 Sep 2015 04:27:58 +0200 Subject: Re: Updated docs on base backups To: pgsql-docs@postgresql.org References: <56065F0E.3080808@mail.com> From: Amir Rohan Message-ID: <5607542B.7040701@mail.com> Date: Sun, 27 Sep 2015 05:27:55 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <56065F0E.3080808@mail.com> Content-Type: multipart/mixed; boundary="------------010307060709070608030200" X-Provags-ID: V03:K0:rpW51deK9jcfgCswTYjwvXaQjCOX/TYzcMpbE0q/tyP35z57BIJ Bfhi7zuQLMt+9Y2HtottZ1dWBVizDjae9ct2GU25Yoh/Ff+ch1xJ6GHTtIjIlo7Yr9icLjC G6UZMlZWyzos3exYi3azjfN7Cn+tPS6uHoc2R9kJ8MTfqVizz+/Z+d7jJ1LN9Rorce3Jevm qbh4k2Z9gcM3COEfU9ANQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:0IzSaGG8rUw=:FoX8K0+sru0f3ECtXF9rDr rX1d6r77HWNXlRDzQikJSsQ5yIDMPjS2KPh397rViwgc5uXy8opqwxzJ3h7J0MYjWcj7DnFyH kOzjr2LA6kjD0GJMhigT1uPUfC/gdtSCj7EkcG+tFqsiRDMHEMxfP0qS4dgBYHuYH3Ycuz2XF 8QBaueDmt67VJMOeZePKsxvoGphCbva60p5nFohQLwHP906dH8pUbH/GXbIu4zi+/6eMKNGUW /Wp6WkRToUzaGU9/K3wChArDplI7fxYW19tz+ik4uoyDP7c/aRfKBVAY69mboQoc0lRr+HYJk NmzKkksw1Wl+Oq1Uuz4cY6b2HJc4zREe41daZQlcPn3GD2UMSaNowvpmISaemdGG8cicxvCni RYnwL/L+V58Cd7WJjAwediOpnZ9FBCY0/ZWXg9T+GImQL9WtNV40skxTfeMqNMZogtmkzzWq0 AtZHTju956KQNUR92d8X/9Vrg0ac2cYyt0f6x74jfMLz4wo5ksREBl/hf/H06Fs6Oq6xAmpQo VOVQfNlZmF/5HxoS06+SfXhkOxNvfvOk9fl1cuFEK0ogxHlz2dH93LK/c3I/2HPKpGYBtRLBr 63Fs1rOjDvukZwJBJOqSvcoGO2aREEaJeD3SkIJqJisqu/lTmZ4TN4qMDu/wN1VykAJmt+myo qwQArwZE4Qp1/HvBlvveBF3mm5bbfBJVwdb+AgSeRq5AUkuvUqcJS/CybhOGETVGftRIerCLM ZG0/E06K/mEjIGCl X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org This is a multi-part message in MIME format. --------------010307060709070608030200 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 09/26/2015 12:02 PM, Amir Rohan wrote: > Hi all, > > See attached changed to current docs on subject. They have clearly > been reworked by multiple people piecemeal and had many issues > which made less than a joy to read, in fact they were damn frustrating > to read. Further editing. See attached V3. --------------010307060709070608030200 Content-Type: text/x-patch; name="20150928_base_backups_docs_amir_v3.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="20150928_base_backups_docs_amir_v3.patch" From f763259e6e91d69dd1c41f67169fa0666b1f82d9 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 26 Sep 2015 11:50:43 +0300 Subject: [PATCH] Rewritten documentation on base backups V2 diff --git a/doc/src/sgml/backup.sgml b/doc/src/sgml/backup.sgml index 7413666..e2727e1 100644 --- a/doc/src/sgml/backup.sgml +++ b/doc/src/sgml/backup.sgml @@ -427,8 +427,8 @@ tar -cf backup.tar /usr/local/pgsql/data If simultaneous snapshots are not possible, one option is to shut down the database server long enough to establish all the frozen snapshots. - Another option is to perform a continuous archiving base backup () because such backups are immune to file + Another option is to create a base backup using the continuous archiving feature + () because such backups are immune to file system changes during the backup. This requires enabling continuous archiving just during the backup process; restore is done using continuous archive recovery (). @@ -752,60 +752,58 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_xlog/ Making a Base Backup - The easiest way to perform a base backup is to use the - tool. It can create - a base backup either as regular files or as a tar archive. If more - flexibility than can provide is - required, you can also make a base backup using the low level API - (see ). + A base backup consists of one or more WAL files and a . + Together they sufficient to recreate the database's state at some point in the past. + Once a base backup is made, the WAL files that precede its creation are no longer + necessary in order to recover the database to some later point in time. + + + + The interval between base backups should usually be + chosen based on how much storage you want to expend on archived WAL + files, since you must keep all the archived WAL files back to your + last base backup. + You should also consider how long you are prepared to spend + recovering, if recovery should be necessary — the system will have to + replay all those WAL segments, and that could take awhile if it has + been a long time since the last base backup. - It is not necessary to be concerned about the amount of time it takes - to make a base backup. However, if you normally run the - server with full_page_writes disabled, you might notice a drop - in performance while the backup runs since full_page_writes is - effectively forced on during backup mode. + Creating a base backup may be a lengthy process if you have a lots of data. + Be aware that If you normally run the server with full_page_writes + disabled, you might notice a drop in performance while the backup runs since + full_page_writes is effectively forced on during backup mode. To make use of the backup, you will need to keep all the WAL segment files generated during and after the file system backup. - To aid you in doing this, the base backup process - creates a backup history file that is immediately - stored into the WAL archive area. This file is named after the first - WAL segment file that you need for the file system backup. - For example, if the starting WAL file is - 0000000100001234000055CD the backup history file will be - named something like - 0000000100001234000055CD.007C9330.backup. (The second - part of the file name stands for an exact position within the WAL - file, and can ordinarily be ignored.) Once you have safely archived - the file system backup and the WAL segment files used during the - backup (as specified in the backup history file), all archived WAL - segments with names numerically less are no longer needed to recover - the file system backup and can be deleted. However, you should - consider keeping several backup sets to be absolutely certain that - you can recover your data. + To aid you in doing this, the base backup process creates a + a textual file called backup_label when you initiate the + base backup, it in the same directory as your server's + configuration files. Note that if you use the low-level API described + below, the file is only available between the issuing of the pg_start_backup + command and the issuing of the pg_stop_backup command. + + The contents of backup_label include details about the range + of WAL files making up the base backup, together with other useful information + such as the date of the backup, and the text label associated with the backup + which you provide when initiating the backup. - The backup history file is just a small text file. It contains the - label string you gave to , as well as - the starting and ending times and WAL segments of the backup. - If you used the label to identify the associated dump file, - then the archived history file is enough to tell you which dump file to - restore. + The simplest way to perform a base backup is by using , which uses the postgres's replication mechanism to + connect to a running database and create a backup archive or directory. The + backup_label will be included in the root directory of the + archive/directory that pg_basebackup creates for you. - Since you have to keep around all the archived WAL files back to your - last base backup, the interval between base backups should usually be - chosen based on how much storage you want to expend on archived WAL - files. You should also consider how long you are prepared to spend - recovering, if recovery should be necessary — the system will have to - replay all those WAL segments, and that could take awhile if it has - been a long time since the last base backup. + If more flexibility than can provide is + required, you can also make a base backup using the low level API + (see ). @@ -833,82 +831,118 @@ SELECT pg_start_backup('label'); where label is any string you want to use to uniquely identify this backup operation. (One good practice is to use the full path where you intend to put the backup dump file.) - pg_start_backup creates a backup label file, - called backup_label, in the cluster directory with - information about your backup, including the start time and label - string. The function also creates a tablespace map file, - called tablespace_map, in the cluster directory with - information about tablespace symbolic links in pg_tblspc/ - if one or more such link is present. Both files are critical to the - integrity of the backup, should you need to restore from it. + This places the database in backup mode, creating the + backup_label + file described earlier, as well as the tablespace map + file called + tablespace_map which contains information about tablespace + symbolic links in pg_tblspc/, if such links are present. + Both files are created in your cluster directory, alongside + your configuration files, and are critical to the integrity of + the backup. - It does not matter which database within the cluster you connect to to - issue this command. You can ignore the result returned by the function; - but if it reports an error, deal with that before proceeding. + It does not matter which database within the cluster you are connected + to when you issue this command, as the base backup will alway back up + the entire server. + The result returned by the function is + an identifier for the first WAL file in the base backup. You can + use the pg_xlogfile_name function to get the filename + for the actual WAL file it identifies. + If pg_start_backup reports an error, you should resolve the + issue before proceeding. - By default, pg_start_backup can take a long time to finish. - This is because it performs a checkpoint, and the I/O - required for the checkpoint will be spread out over a significant - period of time, by default half your inter-checkpoint interval + The pg_start_backup function performs a checkpoint in preparation + for the backup, spreading the I/O involved over a a period + of time that is set at half your inter-checkpoint interval (see the configuration parameter - ). This is - usually what you want, because it minimizes the impact on query - processing. If you want to start the backup as soon as - possible, use: + ) by default. + This can make the backup process lengthy, but is usually desirable + because it minimizes the impact on query processing during the backup. + If you prefer to start the backup as soon as possible, which can + result in a larger negative impact on your server's performance during + the backup, use: SELECT pg_start_backup('label', true); - This forces the checkpoint to be done as quickly as possible. + Which forces the checkpoint to be done as quickly as possible. - Perform the backup, using any convenient file-system-backup tool + Once pg_start_backup returns, you are ready to perform a + file system level backup (See for more details) + of your server's entire cluster directory. + Note that, when making a file system level backup in conjunction with a + base backup, it is neither necessary nor desirable to stop normal operation + of the database while you create the file system backup. + + + You can use any convenient file-system-backup tool such as tar or cpio (not pg_dump or - pg_dumpall). It is neither - necessary nor desirable to stop normal operation of the database - while you do this. - - + pg_dumpall) to make the copy. + + - Again connect to the database as a superuser, and issue the command: + Once pg_start_backup finishes, and you've created a backup of + your cluster directory, connect to the database again as a superuser again, + and issue the command: SELECT pg_stop_backup(); - This terminates the backup mode and performs an automatic switch to - the next WAL segment. The reason for the switch is to arrange for - the last WAL segment file written during the backup interval to be - ready to archive. + This tells postgres that you have completed the file system level backup + and instructs it to forces a switch to the next WAL segment, allowing + the last WAL segment file in the base backup to be archived. + + pg_stop_backup will + not return until the last segment has been archived. In most cases this + happens quickly, but you are advised to monitor your archive system to + nsure there are no delays. If the archive process has fallen behind because + of failures of the archive command, it will keep retrying until the archive + succeeds and the backup is complete. + If you wish to place a time limit on the execution of + pg_stop_backup, set an appropriate + statement_timeout value. + + The result returned by pg_stop_backup is the identifier for the + last WAL file included in the base backup + - Once the WAL segment files active during the backup are archived, you are - done. The file identified by pg_stop_backup's result is - the last segment that is required to form a complete set of backup files. - If archive_mode is enabled, - pg_stop_backup does not return until the last segment has - been archived. - Archiving of these files happens automatically since you have - already configured archive_command. In most cases this - happens quickly, but you are advised to monitor your archive - system to ensure there are no delays. - If the archive process has fallen behind - because of failures of the archive command, it will keep retrying - until the archive succeeds and the backup is complete. - If you wish to place a time limit on the execution of - pg_stop_backup, set an appropriate - statement_timeout value. + During archiving of the base backup WALs, postgres will also creates + a backup history file in your archive directory. + This is a textual file very similar to the backup_label file. + It contains the backup label you set when initiating the backup, + the backup date, as well as the identifiers for the first and last WAL + in the backup. backup history files have names that match the first WAL + segment file in the base backup they are associated with, and have + the file extension .backup. + For example, if the first WAL file in the range is + 0000000100001234000055CD the backup history file will be + named similarly to 0000000100001234000055CD.007C9330.backup. + (The second part of the file name stands for an exact position within + the WAL file, and can ordinarily be ignored.) - - + + + Once all the WAL files in your base backup have been archived, and + you've created a file system level backup, the base backup is complete. + All archived WAL segments with names numerically less are no longer needed + now to recover the file system backup and can be deleted. + However, you should consider keeping + several backup sets to be absolutely certain that you can recover + your data. + + + Some file system backup tools emit warnings or errors @@ -929,8 +963,11 @@ SELECT pg_stop_backup(); - Be certain that your backup dump includes all of the files under + Make sure that your backup dump includes all of the files under the database cluster directory (e.g., /usr/local/pgsql/data). + This includes the backup_label and + tablespace_map files described earlier. They are crucial + parts of your backup. If you are using tablespaces that do not reside underneath this directory, be careful to include them as well (and be sure that your backup dump archives symbolic links as links, otherwise the restore will corrupt @@ -967,24 +1004,6 @@ SELECT pg_stop_backup(); - It's also worth noting that the pg_start_backup function - makes files named backup_label and - tablespace_map in the database cluster directory, - which are removed by pg_stop_backup. These files will of - course be archived as a part of your backup dump file. The backup label - file includes the label string you gave to pg_start_backup, - as well as the time at which pg_start_backup was run, and - the name of the starting WAL file. In case of confusion it is therefore - possible to look inside a backup dump file and determine exactly which - backup session the dump file came from. The tablespace map file includes - the symbolic link names as they exist in the directory - pg_tblspc/ and the full path of each symbolic link. - These files are not merely for your information; their presence and - contents are critical to the proper operation of the system's recovery - process. - - - It is also possible to make a backup dump while the server is stopped. In this case, you obviously cannot use pg_start_backup or pg_stop_backup, and -- 2.4.3 --------------010307060709070608030200 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs --------------010307060709070608030200--