Search Postgresql Archives

Re: Q: extract database name from directory dump

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 "databasename"

I think...

 pg_restore -l junky | awk  '/^;\wdbname: (.*)/{print $3}'

is more robust. but it fails on a database name with an embedded space (yes, these are valid).

pg_restore -l junky | grep 'dbname:'  | head -1 | sed 's/^; *dbname: //'

should work even for dbnames with embedded spaces.

the head -1 is just in case there the data 'dbname:' occurs in the database somewhere.


--
john r pierce, recycling bits in santa cruz



--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux