Re: Q: extract database name from directory dump

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Q: extract database name from directory dump
Date: 2016-03-12 21:17:07
Message-ID: CANu8FizLpnN9o9rw5eO4XJ08Od_o7kunOAGEBFzmMama1k3j_Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 applied to ANY database.

On Sat, Mar 12, 2016 at 4:12 PM, John R Pierce <pierce(at)hogranch(dot)com> wrote:

> 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 format of the toc.dat file contained in
> that directory format pg_dump output (short of reading the source to
> pg_dump/restore?) but I tried a hexdump...
>
> $ hexdump -C junky/toc.dat
> 00000000 50 47 44 4d 50 01 0c 00 04 08 03 01 01 00 00 00
> |PGDMP...........|
> 00000010 00 24 00 00 00 00 2d 00 00 00 00 0c 00 00 00 00
> |.$....-.........|
> 00000020 0c 00 00 00 00 02 00 00 00 00 74 00 00 00 00 00
> |..........t.....|
> 00000030 00 00 00 00 04 00 00 00 6a 75 6e 6b 00 06 00 00
> |........junk....|
> 00000040 00 39 2e 33 2e 31 31 00 06 00 00 00 39 2e 33 2e
> |.9.3.11.....9.3.|
> (tons more deleted)
>
> and note that 'junk' is in fact the name of the database. But I doubt
> the format of this toc.dat file is guaranteed to be immutable
>
>
>
> --
> john r pierce, recycling bits in santa cruz
>
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2016-03-12 21:19:49 Re: Q: extract database name from directory dump
Previous Message Karsten Hilbert 2016-03-12 21:16:31 Re: Q: extract database name from directory dump