Re: Q: extract database name from directory dump

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Q: extract database name from directory dump
Date: 2016-03-12 21:40:25
Message-ID: 56E48CC9.4080403@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2016-03-12 21:55:26 Re: Q: extract database name from directory dump
Previous Message Chris Ruprecht 2016-03-12 21:33:01 Re: OS X 10.11.3, psql, bus error 10, 9.5.1