Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Karsten Hilbert
On Sat, Mar 12, 2016 at 02:59:05PM -0700, David G. Johnston wrote: > And a much more reasonable assumption would have been 9.5 - let the user > complain if/when the advice doesn't work because they are on an unstated > older release that doesn't support the feature in question. > > I guess the O/

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread David G. Johnston
On Sat, Mar 12, 2016 at 2:05 PM, Karsten Hilbert wrote: > On Sat, Mar 12, 2016 at 03:55:32PM -0500, Melvin Davidson wrote: > > > hmmm, let's see. You haven't specified PostgreSQL version or O/S as is > > common sense and courtesy, so I will choose one for you. > > :-) Sorry. I am on 9.5.1 on D

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread John R Pierce
On 3/12/2016 1:40 PM, John R Pierce wrote: pg_restore -l junky | awk '/^;\wdbname: (.*)/{print $3}' oops, pasted the wrong one, meant that one to be ... pg_restore -l junky | awk '/^; +dbname: /{print $3}' but I think the 2nd one is more robust -- john r pierce, recycling bits in sant

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread John R Pierce
On 3/12/2016 12:59 PM, Karsten Hilbert wrote: Another option that comes to mind is pg_restore -l $DUMPDIR | grep dbname: | cut -f 7 -d ' ' -s but that is quite fragile on the -f 7 -d ' ' side of things but that's another question. starting with... pg_dump -Fd -f junky "dat

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Karsten Hilbert
On Sat, Mar 12, 2016 at 04:17:07PM -0500, Melvin Davidson wrote: > BTW, other than the obvious of including the name in path or file, if you > are referring to previous/existing dumps I do. > grep -i some_dump_file 'CREATE DATABASE' That will not work (directly) because the dump is in directory

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Karsten Hilbert
On Sat, Mar 12, 2016 at 01:12:52PM -0800, John R Pierce wrote: >> Constraints of the question: >> >> - existing dump in directory format >> - dump was taken of only one particular database > > I know of no documentation on the format of the toc.dat file contained in > that directory format pg_dum

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Melvin Davidson
BTW, other than the obvious of including the name in path or file, if you are referring to previous/existing dumps than one of two options apply. grep -i some_dump_file 'CREATE DATABASE' If it's found, then you know it's from at least one known database. If nothing is found, then the dump can be a

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Karsten Hilbert
On Sat, Mar 12, 2016 at 10:05:47PM +0100, Karsten Hilbert wrote: > :-) Sorry. I am on 9.5.1 on Debian 8.0. Debian Testing to be precise: root@hermes:~/tmp# apt-cache policy postgresql postgresql: Installiert: 9.5+172 Installationskandidat: 9.5+172

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread John R Pierce
On 3/12/2016 12:33 PM, Karsten Hilbert wrote: How can I (programmatically) find out which database a dump was taken from given the dump file ? Constraints of the question: - existing dump in directory format - dump was taken of only one particular database I know of no documentation on the fo

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Karsten Hilbert
On Sat, Mar 12, 2016 at 03:55:32PM -0500, Melvin Davidson wrote: > hmmm, let's see. You haven't specified PostgreSQL version or O/S as is > common sense and courtesy, so I will choose one for you. :-) Sorry. I am on 9.5.1 on Debian 8.0. OTOH, in the wild it could be any OS and PG 9.1.0 upward

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Karsten Hilbert
On Sat, Mar 12, 2016 at 09:38:13PM +0100, Karsten Hilbert wrote: > > Not-so-nice solutions coming to mind: > > > > - rely on the dump file name > > - use pg_restore to create an SQL dump > > with --create and grep the SQL file > > for "create database ..." > > - restore and compare psql -l ou

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Melvin Davidson
hmmm, let's see. You haven't specified PostgreSQL version or O/S as is common sense and courtesy, so I will choose one for you. You are using PostgreSQL version 8.4 on Ubuntu 14.04 Since pg_dump requires an output file, and the database you are dumping must be known, just just the db name in the p

Re: [GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Karsten Hilbert
On Sat, Mar 12, 2016 at 09:33:33PM +0100, Karsten Hilbert wrote: > Not-so-nice solutions coming to mind: > > - rely on the dump file name > - use pg_restore to create an SQL dump > with --create and grep the SQL file > for "create database ..." > - restore and compare psql -l output > befor

[GENERAL] Q: extract database name from directory dump

2016-03-12 Thread Karsten Hilbert
Hi, I have been searching but haven't been able to find the answer to the following question: How can I (programmatically) find out which database a dump was taken from given the dump file ? Constraints of the question: - existing dump in directory format - dump was taken of only one particular