pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Dunstan <andrew@dunslane.net>
To: Álvaro Herrera <alvherre@kurilemu.de>
To: Mahendra Singh Thalor <mahi6run@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: pgsql: Non text modes for pg_dumpall, correspondingly change pg_restore
Date: Mon, 14 Apr 2025 16:14:37 -0400
Message-ID: <17b357f9-7a99-4db2-87aa-a16679b52757@dunslane.net> (raw)
In-Reply-To: <6e0e57e5-ace5-4d18-b1c1-7a3b3da36316@dunslane.net>
References: <202504141220.343fmoxfsbj4@alvherre.pgsql>
	<6e0e57e5-ace5-4d18-b1c1-7a3b3da36316@dunslane.net>


On 2025-04-14 Mo 12:28 PM, Andrew Dunstan wrote:
>
>
>>
>> I'm also not sure about the double sscanf() business there ... There
>> must be a better way to do this.
>
>
>
> Yes, probably. I'll look into that if you like.
>
>
>

something like this?


cheers


andrew


--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Attachments:

pg_restore-cleanup.patch (text/x-patch, 1.3K) download diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index ff4bb320fc9..a600f7d9a3b 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -1053,26 +1053,32 @@ get_dbname_oid_list_from_mfile(const char *dumpdirpath, SimpleOidStringList *dbn while ((fgets(line, MAXPGPATH, pfile)) != NULL) { Oid db_oid = InvalidOid; - char db_oid_str[MAXPGPATH + 1] = ""; char *dbname; + char *p = line; /* Extract dboid. */ - sscanf(line, "%u", &db_oid); - sscanf(line, "%20s", db_oid_str); + while(isdigit(*p)) + p++; + if (p > line && *p == ' ') + { + sscanf(line, "%u", &db_oid); + p++; + } /* dbname is the rest of the line */ - dbname = line + strlen(db_oid_str) + 1; + dbname = p; /* Remove \n from dbname. */ dbname[strlen(dbname) - 1] = '\0'; - pg_log_info("found database \"%s\" (OID: %u) in \"%s\"", - dbname, db_oid, map_file_path); - /* Report error and exit if the file has any corrupted data. */ if (!OidIsValid(db_oid) || strlen(dbname) == 0) pg_fatal("invalid entry in \"%s\" at line : %d", map_file_path, count + 1); + else + pg_log_info("found database \"%s\" (OID: %u) in \"%s\"", + dbname, db_oid, map_file_path); + simple_oid_string_list_append(dbname_oid_list, db_oid, dbname); count++;

view thread (10+ messages)  latest in thread

Message-ID: <17b357f9-7a99-4db2-87aa-a16679b52757@dunslane.net>
Permalink:  ../17b357f9-7a99-4db2-87aa-a16679b52757@dunslane.net/
Also on:    postgresql.org/message-id/17b357f9-7a99-4db2-87aa-a16679b52757@dunslane.net

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: andrew@dunslane.net, alvherre@kurilemu.de, mahi6run@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: pgsql: Non text modes for pg_dumpall, correspondingly change pg_restore
  In-Reply-To: <17b357f9-7a99-4db2-87aa-a16679b52757@dunslane.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox