Thread
-
AW: Proposal: More flexible backup/restore via pg_dump
Zeugswetter Andreas SB <zeugswettera@wien.spardat.at> — 2000-06-26T08:17:05Z
> The broad approach would be modify the existing pg_dump as little as > possible; I am inclined to write the data as SQL (as currently done), and > append an 'index' to the output, specifying the offset on the file that > each piece of extractable data can be found. The 'restore' option would > just go to the relevant section(s), and pipe the data to psql. A problem I see with an index at file end is, that you will need to read the file twice, and that may be very undesireable if e.g the backup is on tape or a compressed file. I like your idea of uniquely formatted comments heading separate sections of the dump file, if the "create table ..." is not already enough. Andreas
-
Re: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-06-26T14:30:30Z
At 10:17 26/06/00 +0200, Zeugswetter Andreas SB wrote: > >A problem I see with an index at file end is, that you will need to read the >file twice, and that may be very undesireable if e.g the backup is on tape >or a compressed file. The proposal has actually come a fairly long way after extensive discussions with Tom Lane, and I have added the current plans at the end of this message. The TOC-at-end problem is an issue that I am trying to deal with; I am planning a 'custom' format that has the large parts (data dumps) compressed, to avoid the need of compressing the entire file. This means that you would not need to uncompress the entire file to get to the TOC, or to restore just the schema. It also allows good random access to defns and data. I'm also considering putting the dumped data at the end of the file, but this has issues when you want to restore table data before defining indexes, for example. I must admit that I've been working on the assumption that people using PostgreSQL don't have multi-GB (compressed) database dumps, so that (in theory) a restore can be loaded onto disk from tape before being used. I know this is pretty evil, but it will cover 95% of users. For those people with huge backups, they will have to suffer tapes that go backward and forwards a bit. From the details below, you will see that this is unavoidable. Sanity Check: does fseek work on tapes? If not, what is the correct way to read a particular block/byte from a file on a tape? ----------------------------------------------------------- Updated Proposal: ------------------------- For the sake of argument, call the new utilities pg_backup and pg_restore. pg_backup --------- Dump schema [and data] in OID order (to try to make restores sequential, for when tar/tape storage is used). Each dumped item has a TOC entry which includes the OID and description, and for those items for which we know some dependencies (functions for types & aggregates; types for tables; superclasses for classes; - any more?), it will also dump the dependency OIDs. Each object (table defn, table data, function defn, type defn etc) is dumped to a separate file/thing in the output file. The TOC entries go into a separate file/thing (probably only one file/thing for the whole TOC). The output scheme will be encapsulated, and in the initial version will be a custom format (since I can't see an API for tar files), and a dump-to-a-directory format. Future use of tar, DB, PostgreSQL or even a Make file should not be excluded in the IO design. This last goal *may* not be achieved, but I don't see why it can't be at this stage. Hopefully someone with appropriate skills & motivation can do a tar archive 8-}. The result of a pg_backup should be a single file with metadata and optional data, along with whatever dependency and extra data is available pg_backup, or provided by the DBA. pg_restore ---------- Reads a backup file and dumps SQL suitable for sending to psql. Options will include: - No Data (--no-data? -nd? -s?) - No metadata (--no-schema? -ns? -d?) - Specification of items to dump from an input file; this allows custom ordering AND custom selection of multiple items. Basically, I will allow the user to dump part of the TOC, edit it, and tell pg_restore to use the edited partial TOC. (--item-list=<file>? -l=<file>?) - Dump TOC (--toc-only? -c?) [Wish List] - Data For a single table (--table=<name>? -t=<name>) - Defn/Data for a single OID; (--oid=<oid>? -o=<oid>?) - User definied dependencies. Allow the DB developer to specify once for thier DB what the dependencies are, then use that files as a guide to the restore process. (--deps=<file> -D=<file>) pg_restore will use the same custom IO routines to allow IO to tar/directory/custom files. In the first pass, I will do custom file IO. If a user selects to restore the entire metadata, then it will be dumped according to the defaul policy (OID order). If they select to specify the items from an input file, then the file ordering is used. ------- Typical backup procedure: pg_backup mydb mydb.bkp or *maybe* pg_backup mydb > mydb.bkp BUT AFAIK, fseek does not work on STDOUT, and at the current time pg_backup will use fseek. Typical restore procedure: pg_restore mydb mydb.bkp | psql A user will be able to extract only the schema (-s), only the data (-d), a specific table (-t=name), or even edit the object order and selection via: pg_restore --dump-toc mydb.bkp > mytoc.txt vi mytoc.txt {ie. reorder TOC elements as per known dependency problems} pg_restore --item-list=mytoc.txt mydb.bkp | psql FWIW, I envisage the ---dump-toc output to look like: ID; FUNCTION FRED(INT4) ID; TYPE MY_TYPE ID; TABLE MY_TABLE ID; DATA MY_TABLE ID; INDEX MY_TABLE_IX1 ...etc. so editing and reordering the dump plan should not be too onerous. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: Proposal: More flexible backup/restore via pg_dump
Giles Lean <giles@nemeton.com.au> — 2000-06-26T21:00:41Z
> I must admit that I've been working on the assumption that people using > PostgreSQL don't have multi-GB (compressed) database dumps, so that (in > theory) a restore can be loaded onto disk from tape before being > used. Are you are also assuming that a backup fits in a single file, i.e. that anyone with >2GB of backup has some sort of large file support? > Sanity Check: does fseek work on tapes? If not, what is the correct way to > read a particular block/byte from a file on a tape? As someone else answered: no. You can't portably assume random access to tape blocks. > The output scheme will be encapsulated, and in the initial version will be > a custom format (since I can't see an API for tar files) You can use a standard format without there being a standard API. Using either tar or cpio format as defined for POSIX would allow a lot of us to understand your on-tape format with a very low burden on you for documentation. (If you do go this route you might want to think about cpio format; it is less restrictive about filename length than tar.) There is also plenty of code lying around for reading and writing tar and cpio formats that you could steal^H^H^H^H^H reuse. The BSD pax code should have a suitable license. > pg_restore will use the same custom IO routines to allow IO to > tar/directory/custom files. In the first pass, I will do custom file > IO. Presumably you'd expect this file I/O to be through some standard API that other backends would also use? I'd be interested to see this; I've got code for an experimental libtar somewhere around here, so I could offer comments at least. > BUT AFAIK, fseek does not work on STDOUT, and at the current time pg_backup > will use fseek. It depends what fseek is whether it works on standard output or not. If it's a pipe, no. If it's a file, yes. If it's a tape, no. If it's a ... Not using fseek() would be a win if you can see a way to do it. Regards, Giles
-
Re: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-06-27T09:07:03Z
At 07:00 27/06/00 +1000, Giles Lean wrote: > >Are you are also assuming that a backup fits in a single file, >i.e. that anyone with >2GB of backup has some sort of large file >support? That's up to the format used to save the database; in the case of the 'custom' format, yes. But that is the size after compression. This is not substantially different to pg_dump's behaviour, except that pg_dump can be piped to a tape drive... The objective of the API components are to (a) make it very easy to add new metadata to dump (eg. tablespaces), and (b) make it easy to add new output formats (eg. tar archives). Basically the metadata dumping side makes one call to register the thing to be saved, passing an optional function pointer to dump data (eg. table contents) - this *could* even be used to implement dumping of BLOBs. The 'archiver' format provider must have some basic IO routines: Read/WriteBuf and Read/WriteByte and has a number of hook functions which it can use to output the data. It needs to provide at least one function that actually writes data somewhere. It also has to provide the associated function to read the data. > >As someone else answered: no. You can't portably assume random access >to tape blocks. This is probably an issue. One of the motivations for this utility it to allow partial restores (eg. table data for one table only), and arbitrarilly ordered restores. But I may have a solution: write the schema and TOC out at the start of the file/tape, then compressed data with headers for each indicating which TOC item they correspond to. This metadata can be loaded into /tmp, so fseek is possible. The actual data restoration (assuming constraints are not defined [THIS IS A PROBLEM]) can be done by scanning the rest of the tape in it's own order since RI will not be an issue. I think I'm happy with this. But the problem is the constraints: AFAIK there is no 'ALTER TABLE ADD CONSTRAINT...' so PK, FK, Not Null constraints have to be applied before data load (*please* tell me I'm wrong). This also means that for large databases, I should apply indexes to make PK/FK checks fast, but they will slow data load. Any ideas? >> The output scheme will be encapsulated, and in the initial version will be >> a custom format (since I can't see an API for tar files) > >You can use a standard format without there being a standard API. Being a relatively lazy person, I was hoping to leave that as an excercise for the reader... >Using either tar or cpio format as defined for POSIX would allow a lot >of us to understand your on-tape format with a very low burden on you >for documentation. (If you do go this route you might want to think >about cpio format; it is less restrictive about filename length than >tar.) Tom Lane was also very favorably disposed to tar format. As I said above, the archive interfaces should be pretty amenable to adding tar support - it's just I'd like to get a version working with custom and directory based formats to ensure the flexibility is there. As I see it, the 'backup to directory' format should be easy to use as a basis for the 'backup to tar' code. The problem I have with tar is that it does not support random access to the associated data. For reordering large backups, or (ultimately) single BLOB extraction, this is a performance problem. If you have a tar spec (or suitably licenced code), please mail it to me, and I'll be able to make more informed comments. >Presumably you'd expect this file I/O to be through some standard API >that other backends would also use? I'd be interested to see this; >I've got code for an experimental libtar somewhere around here, so I >could offer comments at least. No problem: I should have a working version pretty soon. The API is strictly purpose-built; it would be adaptable to a more general archibe format, but as you say, tar is fine for most purposes. >> BUT AFAIK, fseek does not work on STDOUT, and at the current time pg_backup >> will use fseek. > >Not using fseek() would be a win if you can see a way to do it. I think I probably can if I can work my way around RI problems. Unfortunately the most effective solution will be to allow reording of the table data restoration order, but that requires multiple passes through the file to find the table data... Bye for now, Philip ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
AW: Proposal: More flexible backup/restore via pg_dump
Zeugswetter Andreas SB <zeugswettera@wien.spardat.at> — 2000-06-27T13:52:01Z
> Maybe; I know BackupExec also does some kind of seek to > update the TOC at > end of a backup (which is what I need to do). Then again, > maybe that's just > a rewind. I don't want to get into custom tape formats... > > Do we have any tape experts out there? Dont lock yourself in on the tape issue, it is the pipes that actually add value to the utility, and those can't rewind, seek or whatever. pipes can: compress, split output, write to storage managers, stripe output, ..... I guess we would want two formats, one for pipe, and one for a standard directory. Andreas
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Tom Lane <tgl@sss.pgh.pa.us> — 2000-06-27T14:48:53Z
Zeugswetter Andreas SB <ZeugswetterA@wien.spardat.at> writes: > pipes can: > compress, split output, write to storage managers, stripe output, > ..... Right, the thing we *really* want is to preserve the fact that pg_dump can write its output to a pipeline ... and that a restore can read from one. If you can improve performance when you find you do have a seekable source/destination file, fine, but the utilities must NOT require it. > I guess we would want two formats, one for pipe, and one for a standard > directory. At the risk of becoming tiresome, "tar" format is eminently pipeable... regards, tom lane
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-06-27T15:08:03Z
At 10:48 27/06/00 -0400, Tom Lane wrote: > >Right, the thing we *really* want is to preserve the fact that pg_dump >can write its output to a pipeline ... and that a restore can read from >one. If you can improve performance when you find you do have a >seekable source/destination file, fine, but the utilities must NOT >require it. OK, the limitation will have to be that reordering of *data* loads (as opposed to metadata) will not be possible in piped data. This is only a problem if RI constraints are loaded. I *could* dump the compressed data to /tmp, but I would guess that in most cases when the archive file is being piped it's because the file won't fit on a local disk. Does this sound reasonable? >> I guess we would want two formats, one for pipe, and one for a standard >> directory. > >At the risk of becoming tiresome, "tar" format is eminently pipeable... > No, it's good...I'll never feel guilty about asking for optimizer hints again. More seriously, though, if I pipe a tar file, I still can't reorder the *data* files without saving them to disk, which is what I want to avoid. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: AW: Proposal: More flexible backup/restore via pg_dump
Tom Lane <tgl@sss.pgh.pa.us> — 2000-06-27T15:23:05Z
Philip Warner <pjw@rhyme.com.au> writes: > More seriously, though, if I pipe a tar file, I still can't reorder the > *data* files without saving them to disk, which is what I want to avoid. True. This is not an issue on the dump side, of course, since you can choose what order you're going to write the tables in. On the restore side, you have no alternative but to restore the tables in the order they appear on tape. Of course the DBA can run the restore utility more than once and extract a subset of tables each time, but I don't see how the restore utility can be expected to do that for him. (Except if it finds it does have the ability to seek in its input file, but I dunno if it's a good idea to use that case for anything except under-the-hood performance improvement, ie quickly skipping over the data you don't need. Features that don't work all the time are not good in my book.) Basically I think we want to assume that pg_dump will write the tables in an order that's OK for restoring. If we can arrange for RI checks not to be installed until after all the data is loaded, this shouldn't be a big problem, seems like. regards, tom lane
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-06-27T17:40:25Z
At 11:23 27/06/00 -0400, Tom Lane wrote: >Of course the DBA can run the restore utility >more than once and extract a subset of tables each time, but I don't >see how the restore utility can be expected to do that for him. Only works with seek (ie. a file). >Features that don't work all the time are not >good in my book.) The *only* bit that won't work is being able to select the table data load order, and I can fix that by writing tables that are wanted later to /tmp if seek is unavailable. This *may* not be a problem, and probably should be presented as an option to the user if restoring from non-seekable media. Assuming that the backup was originally written to seekable media, I will be able to tell the user how much space will be required, which should help. I don't suppose anyone knows of a way of telling if a file handle supports seek? >Basically I think we want to assume that pg_dump will write the tables >in an order that's OK for restoring. If we can arrange for RI checks >not to be installed until after all the data is loaded, this shouldn't >be a big problem, seems like. Part of the motivation for this utility was to allow DBAs to fix the ordering at restore time, but otherwise I totally agree. Unfortunately I don't think the RI checks can be delayed at this stage - can they? I don't suppose there is a 'disable constraints' command? Or the ability to set all constraints as deferrred until commit-time? ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: Proposal: More flexible backup/restore via pg_dump
Stephan Szabo <sszabo@megazone23.bigpanda.com> — 2000-06-27T20:10:00Z
On Tue, 27 Jun 2000, Philip Warner wrote: > But the problem is the constraints: AFAIK there is no 'ALTER TABLE ADD > CONSTRAINT...' so PK, FK, Not Null constraints have to be applied before > data load (*please* tell me I'm wrong). This also means that for large > databases, I should apply indexes to make PK/FK checks fast, but they will > slow data load. Actually, there is an ALTER TABLE ADD CONSTRAINT for foreign key constraints. Of course, if the existing data fails the constraint the constraint doesn't get made. and if you're in a transaction, it'll force a rollback. In fact, you really can't always apply foreign key constraints at schema reload time because you can have tables with circular dependencies. Those would have to be created after data load.
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Giles Lean <giles@nemeton.com.au> — 2000-06-27T22:48:52Z
> I don't suppose anyone knows of a way of telling if a file handle supports > seek? The traditional method is to call lseek() and see what happens. > Part of the motivation for this utility was to allow DBAs to fix the > ordering at restore time, but otherwise I totally agree. Unfortunately I > don't think the RI checks can be delayed at this stage - can they? The current pg_dump handles the data and then adds the constraints. Otherwise there are "chicken and egg" problems where two tables have mutual RI constraints. Even at the tuple level two tuples can be mutually dependent. Regards, Giles
-
Re: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-06-28T03:05:21Z
At 13:10 27/06/00 -0700, Stephan Szabo wrote: > >Actually, there is an ALTER TABLE ADD CONSTRAINT for foreign key >constraints. > This is good to know; presumably at some stage in the future the rest will be added, and the backup/restore can be amended to apply constraints after data load. In the mean time, I suppose people with tape drives who need to reorder the data load will have to make multiple passes (or copy the file locally). ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: AW: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-06-28T03:10:39Z
At 08:48 28/06/00 +1000, Giles Lean wrote: > >> Part of the motivation for this utility was to allow DBAs to fix the >> ordering at restore time, but otherwise I totally agree. Unfortunately I >> don't think the RI checks can be delayed at this stage - can they? > >The current pg_dump handles the data and then adds the constraints. Not as far as I can see; that's what I want to do, bu there is no implemented syntax for doing it. pg_dump simply dumps the table definition with constraints (at least on 7.0.2). >Otherwise there are "chicken and egg" problems where two tables have >mutual RI constraints. Even at the tuple level two tuples can be >mutually dependent. Absolutely. And AFAICT, these happen with pg_dump. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: AW: Proposal: More flexible backup/restore via pg_dump
Stephan Szabo <sszabo@kick.com> — 2000-06-28T19:06:33Z
> At 08:48 28/06/00 +1000, Giles Lean wrote: > >Otherwise there are "chicken and egg" problems where two tables have > >mutual RI constraints. Even at the tuple level two tuples can be > >mutually dependent. > > Absolutely. And AFAICT, these happen with pg_dump. This will happen for check constraints, but not for foreign key constraints... It actually adds the fk constraints later with CREATE CONSTRAINT TRIGGER after the data dump is finished. And, if you do separate schema and data dumps, the wierd statements at the top and bottom of the data dump turn off triggers and then turn them on again (in the most painful way possible). However those cases do not actually guarantee the validity of the data in between.
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-06-29T10:33:03Z
At 12:06 28/06/00 -0700, Stephan Szabo wrote: > >This will happen for check constraints, but not for foreign key >constraints... >It actually adds the fk constraints later with CREATE CONSTRAINT TRIGGER >after the data dump is finished. And, if you do separate schema and data >dumps, the wierd statements at the top and bottom of the data dump turn >off triggers and then turn them on again (in the most painful way possible). Thanks for this information! I had not seen those statements before; I have been mistakenly modifying 6.5.3 sources, not 7.0.2. I will incorporate them in my work. Is there any way of also disabling all constraint checking while loading the data? ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: AW: Proposal: More flexible backup/restore via pg_dump
Stephan Szabo <sszabo@kick.com> — 2000-06-29T18:40:13Z
I think my previous message went dead... > >This will happen for check constraints, but not for foreign key > >constraints... > >It actually adds the fk constraints later with CREATE CONSTRAINT TRIGGER > >after the data dump is finished. And, if you do separate schema and data > >dumps, the wierd statements at the top and bottom of the data dump turn > >off triggers and then turn them on again (in the most painful way possible). > > Thanks for this information! > > I had not seen those statements before; I have been mistakenly modifying > 6.5.3 sources, not 7.0.2. I will incorporate them in my work. Is there any > way of also disabling all constraint checking while loading the data? Well, for unique you could remove/recreate the unique index. NOT NULL is probably not worth bothering with. Check constraints might be able to be turned off for a table by setting relchecks to 0 in the pg_class row and the resetting it after data is loaded (sort of like what we do on data only dumps for triggers). The problem is that the create constraint trigger, playing with reltriggers and playing with relchecks doesn't guarantee that the data being loaded is correct. And if you remove and recreate a unique index, you might not get the index back at the end, and then you've lost the information that there was supposed to be a unique or primary key on the table. It might be a good idea to have some sort of pg_constraint (or whatever) that holds this data, since that would also make it easier to make the constraint naming SQL compliant (no duplicate constraint names within schema - that includes automatically generated ones), and it might help if we ever try to make deferrable check/primary key/etc...
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Tom Lane <tgl@sss.pgh.pa.us> — 2000-06-29T19:24:20Z
"Stephan Szabo" <sszabo@kick.com> writes: >> I had not seen those statements before; I have been mistakenly modifying >> 6.5.3 sources, not 7.0.2. I will incorporate them in my work. Is there any >> way of also disabling all constraint checking while loading the data? > Well, for unique you could remove/recreate the unique index. NOT NULL > is probably not worth bothering with. Check constraints might be able > to be turned off for a table by setting relchecks to 0 in the pg_class > row and the resetting it after data is loaded (sort of like what we do > on data only dumps for triggers). There's no need to disable NOT NULL, nor unique constraints either, since those are purely local to a table --- if they're going to fail, altering load order doesn't prevent it. The things you need to worry about are constraint expressions that cause references to other tables (perhaps indirectly via a function). If we had ALTER TABLE ADD CONSTRAINT then the problem would be largely solved, I believe. This should be a minor exercise --- the heavy lifting is already done, because heap.c's AddRelationRawConstraints() is already set up to be invokable on a pre-existing relation. Also the parser knows how to parse ALTER TABLE ADD CONSTRAINT ... I think all that's missing is a few lines of glue code in command.c. regards, tom lane
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Stephan Szabo <sszabo@kick.com> — 2000-06-29T19:50:02Z
> There's no need to disable NOT NULL, nor unique constraints either, > since those are purely local to a table --- if they're going to fail, > altering load order doesn't prevent it. The things you need to worry Is there a speed difference with doing a copy on a table with an index versus creating the index at the end? I've been assuming that the latter was faster (and that that was part of what he wanted) > about are constraint expressions that cause references to other tables > (perhaps indirectly via a function). Yeah, that's actually a big problem, since that's actually also a constraint on the other table as well, and as far as I know, we aren't yet constraining the other table. > If we had ALTER TABLE ADD CONSTRAINT then the problem would be largely > solved, I believe. This should be a minor exercise --- the heavy > lifting is already done, because heap.c's AddRelationRawConstraints() > is already set up to be invokable on a pre-existing relation. Also > the parser knows how to parse ALTER TABLE ADD CONSTRAINT ... I think > all that's missing is a few lines of glue code in command.c. Does the AddRelationRawConstraints() check that the constraint is satisified as well when you add it? It didn't look like it did, but I could be missing something. That's another requirement of ALTER TABLE ADD CONSTRAINT. That was the bit I wasn't sure how to do for other generic constraints when I added the foreign key one.
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Tom Lane <tgl@sss.pgh.pa.us> — 2000-06-30T00:30:58Z
"Stephan Szabo" <sszabo@kick.com> writes: >> If we had ALTER TABLE ADD CONSTRAINT then the problem would be largely >> solved, I believe. This should be a minor exercise --- the heavy >> lifting is already done, because heap.c's AddRelationRawConstraints() >> is already set up to be invokable on a pre-existing relation. > Does the AddRelationRawConstraints() check that the constraint is > satisified as well when you add it? It didn't look like it did, but I > could be missing something. Oh, you're right, it does not. So you'd first have to run through the table and verify that the constraint holds for each existing tuple. Doesn't seem like a big deal though... regards, tom lane
-
Re: AW: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-06-30T01:46:58Z
At 20:30 29/06/00 -0400, Tom Lane wrote: > >Oh, you're right, it does not. So you'd first have to run through the >table and verify that the constraint holds for each existing tuple. >Doesn't seem like a big deal though... > Does this mean somebody is likely to do it? It'd certainly make backup/restore more reliable. I'm almost at the point of asking for testers with the revised pg_dump/pg_restore, so I'll go with what I have for now, but it would make life a lot less messy. Since the new version *allows* table restoration intermixed with metadata, and in any order, I need to update pg_class repeatedly (I assume there may be system triggers that need to execute when metadata is changed). ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: AW: Proposal: More flexible backup/restore via pg_dump
Stephan Szabo <sszabo@kick.com> — 2000-06-30T02:15:21Z
> At 20:30 29/06/00 -0400, Tom Lane wrote: > > > >Oh, you're right, it does not. So you'd first have to run through the > >table and verify that the constraint holds for each existing tuple. > >Doesn't seem like a big deal though... > > > > Does this mean somebody is likely to do it? It'd certainly make > backup/restore more reliable. I'll take a stab at it. It might take me a while to get stuff working but it shouldn't take too long before the beginnings are there.
-
RE: RE: [HACKERS] pg_dump & blobs - editable dump?
Peter Mount <petermount@it.maidstone.gov.uk> — 2000-07-12T14:25:24Z
No he didn't, just I've been sort of lurking on this subject ;-) Actually, tar files are simply a small header, followed by the file's contents. To add another file, you simply write another header, and contents (which is why you can cat two tar files together and get a working file). http://www.goice.co.jp/member/mo/formats/tar.html has a nice brief description of the header. As for a C api with a compatible licence, if needs must I'll write one to your spec (maidast should be back online in a couple of days, so I'll be back in business development wise). Peter -- Peter Mount Enterprise Support Maidstone Borough Council Any views stated are my own, and not those of Maidstone Borough Council -----Original Message----- From: Philip Warner [mailto:pjw@rhyme.com.au] Sent: Wednesday, July 12, 2000 3:17 PM To: Peter Mount; pgsql-hackers@postgresql.org; pgsql-general@postgresql.org Cc: Pavel@Janik.cz Subject: Re: [GENERAL] RE: [HACKERS] pg_dump & blobs - editable dump? At 14:58 12/07/00 +0100, Peter Mount wrote: >Why not have it using something like tar, and the first file being stored in >ascii? > >That way, you could extract easily the human readable SQL but still pipe the >blobs to stdout. Has Tom Lane paid you to send this message? :-} If anyone can send me a nice interface for reading and writing a tar file from C, I'll do it. I just don't have the inclination to learn about tar internals at the moment. By 'nice' I mean that I would like: - to be able to create the archive and write files sequentially using something similar to fopen/fwrite/fclose. - open an archive and examine and read files sequentially using a similar interface to opendir/readdir/fopen/fread/fclose. - Ideally open a specified file in the archive by name, but if not possible, then it should be easy using the 'opedir' function above. This would be a very useful library, I am sure. It also needs to be licensable under BSD to go into the PG distribution. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
RE: RE: [HACKERS] pg_dump & blobs - editable dump?
Philip Warner <pjw@rhyme.com.au> — 2000-07-12T15:11:04Z
At 15:25 12/07/00 +0100, Peter Mount wrote: >No he didn't, just I've been sort of lurking on this subject ;-) > >Actually, tar files are simply a small header, followed by the file's >contents. To add another file, you simply write another header, and contents >(which is why you can cat two tar files together and get a working file). > >http://www.goice.co.jp/member/mo/formats/tar.html has a nice brief >description of the header. > Damn! I knew someone would call my bluff. As you say, it looks remarkably simple. A couple of questions: 136 12 bytes Modify time (in octal ascii) ...do you know the format of the date (seconds since 1970?). 157 100 bytes Linkname ('\0' terminated, 99 maxmum length) ...what's this? Is it the target for symlinks? 329 8 bytes Major device ID (in octal ascii) 337 8 bytes Minor device ID (in octal ascii)345 167 bytes Padding ...and what should I set these to? >As for a C api with a compatible licence, if needs must I'll write one to >your spec (maidast should be back online in a couple of days, so I'll be >back in business development wise). If you're serious about the offer, I'd be happy. But, given how simple the format is, I can probably tack in into place myself. There is a minor problem. Currently I compress the output stream as I receive it from PG, and send it to the archive. I don't know how big it will be until it is written. The custom output format can handle this, but in streaming a tar file to tape, I have to know the file size first. This means writing to /tmp. I supose that's OK, but I've been trying to avoid it. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: RE: [HACKERS] pg_dump & blobs - editable dump?
Giles Lean <giles@nemeton.com.au> — 2000-07-12T21:58:43Z
> >http://www.goice.co.jp/member/mo/formats/tar.html has a nice brief Best is to look at one of the actual standards, accessible via: http://www.opengroup.org The tar and cpio formats are in the pax specification. > 136 12 bytes Modify time (in octal ascii) > > ...do you know the format of the date (seconds since 1970?). It's just 11 bytes plus \0 in tar's usual encode-this-as-octal format: encode_octal(unsigned char *p, size_t n, unsigned long value) { const unsigned char octal[] = "01234567"; while (n) { *(p + --n) = octal[value & 07]; value >>= 3; } } Warning: some values allowed by tar exceed the size of 'long' on a 32 bit platform. > 157 100 bytes Linkname ('\0' terminated, 99 maxmum length) > > ...what's this? Is it the target for symlinks? Long pathnames get split into two pieces on a '/' as I recall. The code I offered you previously has code to do this too; I appreciate that the code is quite likely not what you want, but you might consider looking at it or other tar/pax code to help you interpret the standard. > 329 8 bytes Major device ID (in octal ascii) > 337 8 bytes Minor device ID (in octal ascii) > 345 167 bytes Padding > > ...and what should I set these to? Zero. > If you're serious about the offer, I'd be happy. But, given how simple the > format is, I can probably tack in into place myself. For the very limited formats you want to create, that's probably the easiest way. You don't care about unpacking, GNU v. POSIX format, device files, etc etc. > There is a minor problem. Currently I compress the output stream as I > receive it from PG, and send it to the archive. I don't know how big it > will be until it is written. The custom output format can handle this, but > in streaming a tar file to tape, I have to know the file size first. This > means writing to /tmp. I supose that's OK, but I've been trying to > avoid it. I recommend you compress the whole stream, not the pieces. Presumably you can determine the size of the pieces you're backing up, and ending with a .tar.gz (or whatever) file is more convenient to manage than a .tar file of compressed pieces unless you really expect people to be extracting individual files from the backup very often. Having to pass everything through /tmp would be really unfortunate. Regards, Giles -
Re: RE: [HACKERS] pg_dump & blobs - editable dump?
Philip Warner <pjw@rhyme.com.au> — 2000-07-13T00:58:06Z
At 07:58 13/07/00 +1000, Giles Lean wrote: > >I recommend you compress the whole stream, not the pieces. Presumably >you can determine the size of the pieces you're backing up, and ending >with a .tar.gz (or whatever) file is more convenient to manage than a >.tar file of compressed pieces unless you really expect people to be >extracting individual files from the backup very often. > >Having to pass everything through /tmp would be really unfortunate. > The only things I compress are the table data and the blobs (ie. the big things); unfortunately, the table data is of unknown uncompressed size. I *could* do two 'COPY TO STDOUT' calls, just to get the size, but that seems like a very bad idea. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.C.N. 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: Proposal: More flexible backup/restore via pg_dump
Bruce Momjian <pgman@candle.pha.pa.us> — 2000-10-11T00:49:52Z
Can I ask on a status? > At 10:17 26/06/00 +0200, Zeugswetter Andreas SB wrote: > > > >A problem I see with an index at file end is, that you will need to read the > >file twice, and that may be very undesireable if e.g the backup is on tape > >or a compressed file. > > The proposal has actually come a fairly long way after extensive > discussions with Tom Lane, and I have added the current plans at the end of > this message. The TOC-at-end problem is an issue that I am trying to deal > with; I am planning a 'custom' format that has the large parts (data dumps) > compressed, to avoid the need of compressing the entire file. This means > that you would not need to uncompress the entire file to get to the TOC, or > to restore just the schema. It also allows good random access to defns and > data. I'm also considering putting the dumped data at the end of the file, > but this has issues when you want to restore table data before defining > indexes, for example. > > I must admit that I've been working on the assumption that people using > PostgreSQL don't have multi-GB (compressed) database dumps, so that (in > theory) a restore can be loaded onto disk from tape before being used. I > know this is pretty evil, but it will cover 95% of users. For those people > with huge backups, they will have to suffer tapes that go backward and > forwards a bit. From the details below, you will see that this is unavoidable. > > Sanity Check: does fseek work on tapes? If not, what is the correct way to > read a particular block/byte from a file on a tape? > > ----------------------------------------------------------- > Updated Proposal: > ------------------------- > > For the sake of argument, call the new utilities pg_backup and pg_restore. > > pg_backup > --------- > > Dump schema [and data] in OID order (to try to make restores sequential, > for when tar/tape storage is used). Each dumped item has a TOC entry which > includes the OID and description, and for those items for which we know > some dependencies (functions for types & aggregates; types for tables; > superclasses for classes; - any more?), it will also dump the dependency OIDs. > > Each object (table defn, table data, function defn, type defn etc) is > dumped to a separate file/thing in the output file. The TOC entries go into > a separate file/thing (probably only one file/thing for the whole TOC). > > The output scheme will be encapsulated, and in the initial version will be > a custom format (since I can't see an API for tar files), and a > dump-to-a-directory format. Future use of tar, DB, PostgreSQL or even a > Make file should not be excluded in the IO design. This last goal *may* not > be achieved, but I don't see why it can't be at this stage. Hopefully > someone with appropriate skills & motivation can do a tar archive 8-}. > > The result of a pg_backup should be a single file with metadata and > optional data, along with whatever dependency and extra data is available > pg_backup, or provided by the DBA. > > > pg_restore > ---------- > > Reads a backup file and dumps SQL suitable for sending to psql. > > Options will include: > > - No Data (--no-data? -nd? -s?) > - No metadata (--no-schema? -ns? -d?) > - Specification of items to dump from an input file; this allows custom > ordering AND custom selection of multiple items. Basically, I will allow > the user to dump part of the TOC, edit it, and tell pg_restore to use the > edited partial TOC. (--item-list=<file>? -l=<file>?) > - Dump TOC (--toc-only? -c?) > > [Wish List] > - Data For a single table (--table=<name>? -t=<name>) > - Defn/Data for a single OID; (--oid=<oid>? -o=<oid>?) > - User definied dependencies. Allow the DB developer to specify once for > thier DB what the dependencies are, then use that files as a guide to the > restore process. (--deps=<file> -D=<file>) > > pg_restore will use the same custom IO routines to allow IO to > tar/directory/custom files. In the first pass, I will do custom file IO. > > If a user selects to restore the entire metadata, then it will be dumped > according to the defaul policy (OID order). If they select to specify the > items from an input file, then the file ordering is used. > > > ------- > > Typical backup procedure: > > pg_backup mydb mydb.bkp > > or *maybe* > > pg_backup mydb > mydb.bkp > > BUT AFAIK, fseek does not work on STDOUT, and at the current time pg_backup > will use fseek. > > > Typical restore procedure: > > pg_restore mydb mydb.bkp | psql > > A user will be able to extract only the schema (-s), only the data (-d), a > specific table (-t=name), or even edit the object order and selection via: > > pg_restore --dump-toc mydb.bkp > mytoc.txt > vi mytoc.txt {ie. reorder TOC elements as per known dependency problems} > pg_restore --item-list=mytoc.txt mydb.bkp | psql > > FWIW, I envisage the ---dump-toc output to look like: > > ID; FUNCTION FRED(INT4) > ID; TYPE MY_TYPE > ID; TABLE MY_TABLE > ID; DATA MY_TABLE > ID; INDEX MY_TABLE_IX1 > ...etc. > > so editing and reordering the dump plan should not be too onerous. > > > ---------------------------------------------------------------- > Philip Warner | __---_____ > Albatross Consulting Pty. Ltd. |----/ - \ > (A.C.N. 008 659 498) | /(@) ______---_ > Tel: (+61) 0500 83 82 81 | _________ \ > Fax: (+61) 0500 83 82 82 | ___________ | > Http://www.rhyme.com.au | / \| > | --________-- > PGP key available upon request, | / > and from pgp5.ai.mit.edu:11371 |/ > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026 -
Re: Proposal: More flexible backup/restore via pg_dump
Philip Warner <pjw@rhyme.com.au> — 2000-10-11T02:09:08Z
At 20:49 10/10/00 -0400, Bruce Momjian wrote: >Can I ask on a status? Done. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.B.N. 75 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: pg_dump and large files - is this a problem?
Philip Warner <pjw@rhyme.com.au> — 2002-10-03T13:10:48Z
At 11:06 AM 2/10/2002 -0400, Tom Lane wrote: >It needs to get done; AFAIK no one has stepped up to do it. Do you want >to? My limited reading of off_t stuff now suggests that it would be brave to assume it is even a simple 64 bit number (or even 3 32 bit numbers). One alternative, which I am not terribly fond of, is to have pg_dump write multiple files - when we get to 1 or 2GB, we just open another file, and record our file positions as a (file number, file position) pair. Low tech, but at least we know it would work. Unless anyone knows of a documented way to get 64 bit uint/int file offsets, I don't see we have mush choice. ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.B.N. 75 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/ -
Re: pg_dump and large files - is this a problem?
Giles Lean <giles@nemeton.com.au> — 2002-10-03T21:15:29Z
Philip Warner writes: > My limited reading of off_t stuff now suggests that it would be brave to > assume it is even a simple 64 bit number (or even 3 32 bit numbers). What are you reading?? If you find a platform with 64 bit file offsets that doesn't support 64 bit integral types I will not just be surprised but amazed. > One alternative, which I am not terribly fond of, is to have pg_dump > write multiple files - when we get to 1 or 2GB, we just open another > file, and record our file positions as a (file number, file > position) pair. Low tech, but at least we know it would work. That does avoid the issue completely, of course, and also avoids problems where a platform might have large file support but a particular filesystem might or might not. > Unless anyone knows of a documented way to get 64 bit uint/int file > offsets, I don't see we have mush choice. If you're on a platform that supports large files it will either have a straightforward 64 bit off_t or else will support the "large files API" that is common on Unix-like operating systems. What are you trying to do, exactly? Regards, Giles
-
Re: pg_dump and large files - is this a problem?
Philip Warner <pjw@rhyme.com.au> — 2002-10-03T23:42:35Z
At 07:15 AM 4/10/2002 +1000, Giles Lean wrote: > > My limited reading of off_t stuff now suggests that it would be brave to > > assume it is even a simple 64 bit number (or even 3 32 bit numbers). > >What are you reading?? If you find a platform with 64 bit file >offsets that doesn't support 64 bit integral types I will not just be >surprised but amazed. Yes, but there is no guarantee that off_t is implemented as such, nor would we be wise to assume so (most docs say explicitly not to do so). > > Unless anyone knows of a documented way to get 64 bit uint/int file > > offsets, I don't see we have mush choice. > >If you're on a platform that supports large files it will either have >a straightforward 64 bit off_t or else will support the "large files >API" that is common on Unix-like operating systems. > >What are you trying to do, exactly? Again yes, but the problem is the same: we need a way of making the *value* of an off_t portable (not just assuming it's a int64). In general that involves knowing how to turn it into a more universal data type (eg. int64, or even a string). Does the large file API have functions for representing the off_t values that is portable across architectures? And is the API also portable? ---------------------------------------------------------------- Philip Warner | __---_____ Albatross Consulting Pty. Ltd. |----/ - \ (A.B.N. 75 008 659 498) | /(@) ______---_ Tel: (+61) 0500 83 82 81 | _________ \ Fax: (+61) 0500 83 82 82 | ___________ | Http://www.rhyme.com.au | / \| | --________-- PGP key available upon request, | / and from pgp5.ai.mit.edu:11371 |/