Re: Non-text mode for pg_dumpall

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Mahendra Singh Thalor <mahi6run(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Guillaume Lelarge <guillaume(at)lelarge(dot)info>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Subject: Re: Non-text mode for pg_dumpall
Date: 2025-01-24 15:20:03
Message-ID: CACJufxGwXjG80LZ4miX+dXaT+3z5Kf1Mf0P_7FnR+641oqfUyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 23, 2025 at 6:35 PM Mahendra Singh Thalor
<mahi6run(at)gmail(dot)com> wrote:
>
> On Thu, 23 Jan 2025 at 14:59, jian he <jian(dot)universality(at)gmail(dot)com> wrote:
> >
> > hi.
> > The four patches attached are to solve the
> > TODO1: We need to think for --exclude-database=PATTERN for pg_restore.
> > it is based on your v11_pg_dumpall-with-directory-tar-custom-format-21-jan.patch
> >
> >
> > 0001. pg_dumpall --exclude-database=PATTERN already works,
> > main function resolve pattern matching is expand_dbname_patterns.
> > make it an extern function, so pg_restore --exclude-database can also use it.
>
> Hi Jian,
> We can't use the same expand_dbname_patterns function pg_restore.
>
> In the 1st patch, by mistake I also used this function but then I
> realised that we should not use this function due to some limitation
> for pg_restore.
>
> While doing pg_dumpall, we have all the existence database names in
> the pg_database catalog but while restoring, we don't have all
> databases in the catalog.
> Actually, we will read dbnames from map.dat file to skip matching
> patterns for restore.
>

hi.
After some tests and thinking about your reply, I admit that using
expand_dbname_patterns
in pg_restore will not work.
We need to do pattern matching against the map.dat file.
Please check the attached v12 series based on your
v11_pg_dumpall-with-directory-tar-custom-format-21-jan.patch

v12-0001 cosmetic change.
v12-0002 implement pg_resore --exclude-database=PATTERN.
main gist of implementation:
for each database name in map.dat file,
check if this database name pattern matches with PATTERN or not.
pattern matching is using processSQLNamePattern.

your substring will not work.
some of the test cases.
$BIN10/pg_restore --exclude-database=* -Cd template1 --verbose dir10 >
dir_format 2>&1
$BIN10/pg_restore --exclude-database=*x* -Cd template1 --verbose dir10
> dir_format 2>&1
$BIN10/pg_restore --exclude-database=?* -Cd template1 --verbose dir10
> dir_format 2>&1

Attachment Content-Type Size
v12-0002-pg_restore-exclude-database-PATTERN.no-cfbot application/octet-stream 10.6 KB
v12-0001-coesmetic-change.no-cfbot application/octet-stream 7.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2025-01-24 15:22:30 Re: Purpose of wal_init_zero
Previous Message Maxim Orlov 2025-01-24 15:09:14 Re: postgres_fdw could deparse ArrayCoerceExpr