Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u8cdY-008hZt-Gp for pgsql-novice@arkaria.postgresql.org; Sat, 26 Apr 2025 10:19:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u8cdU-002xZq-Ol for pgsql-novice@arkaria.postgresql.org; Sat, 26 Apr 2025 10:19:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u8cdU-002xV8-9E for pgsql-novice@lists.postgresql.org; Sat, 26 Apr 2025 10:19:53 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u8cdS-0022iP-1Q for pgsql-novice@lists.postgresql.org; Sat, 26 Apr 2025 10:19:52 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-b13e0471a2dso2354069a12.2 for ; Sat, 26 Apr 2025 03:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745662790; x=1746267590; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bGIDO0HG2Sm5GryEsikiDFammWsAh19atH4HQTew5UA=; b=KVPgrHq8wHQO9nDj/WheBTTb4gtOJe7dDBAxX1ZlPUANq6sQyX9130ZrfQ1CxyT2oK VKkdrk5qr9BkyErctIwiKeA8y+zqtlRHRi78NG8jMliKBpDK63dLHdnI2fPbQejQOozp K5qyKt7I68IUHBE/K7d1QrapobWObFC0y9VTzLf/doPZxLSxhogwFLjEKwfH4b9Hqxwy AtAebAjBih43OV7wSBbd4GE0nySrP3Pi0QY51wJz5fXXQfwalyn6b/ovDIvLFo4BnhWy vzDajWNpS/UjD64WDbABhmTLOgsKjpMMpk5IndcOssV7IDGo8BZTLUcNfYCVO2UEV5s+ 04XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745662790; x=1746267590; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bGIDO0HG2Sm5GryEsikiDFammWsAh19atH4HQTew5UA=; b=W8P++qJeLte7kzJHXLaahmIEQlPJ+/dys0L6PSX1O45wOZzq1zlZ4KWg0rPCXjrcaV qfRPMgOxYKYivkFnokxdb1XJxblJlUa87UhecUorc+w62sWoTPP+vKAs1/3URe+LUF8n XShTey6l1AXuUoMG9AQdFHy4TUbAaa5Eq53tEEWgbFJ1cwTZ9C5BIFCuhig+jXjLy1xR qhh5TIrDCGmnrzoEMswpeR5VfNfSShhEGfO0dmwSYA9D3+sJEeHMKKkJfZRUB6UMSXuo KsVSMoU28KpggH97sYw/GhapsElley4Ya89SIE/Vn6P8NDPFhBB8ZNBgLNkzO5tYidXZ IX2Q== X-Gm-Message-State: AOJu0YwR1yHIEgsC4DeQV4jqec+8Y39kXNJSfyB/7Y5eTUxqLR4eCJqk q5ERh/dRcC6OXKJ2og/TkYwnrpCErdU4wvcMVSLgbBTc4mtIq5C9QrWEPycw1gdi/H6C8XGT2bm 27auDhKgE0NkBREDbVlcS8SccVHubLQ== X-Gm-Gg: ASbGnctUR/fO+KCK+UcRnm2aOaVIUQUEWN/iYtwYRe6lPg+dYJ97JxvA1HAcRmiHgAM BjkDAOxV9109xtuAYPJYh37aEcEGudggu3pvgWzUJGU0Bn8k/OGRDer+cJYDzkb169Rc5UHXLDG HPNPyLjVSA3ap8Bv48odDxjd/CdIOtBePn7JsMk41LzX6SctneWzCQgIw= X-Google-Smtp-Source: AGHT+IE428+lvbAFi32OoKY9tfUUJU9Gao2SbYPj7Nlk0mfdClAdEvmMa3+6mjarNOOMKBO7MJN/xpF0CPuotK5V3mk= X-Received: by 2002:a17:90b:1f84:b0:2ee:f677:aa14 with SMTP id 98e67ed59e1d1-30a013075b4mr3630630a91.13.1745662789741; Sat, 26 Apr 2025 03:19:49 -0700 (PDT) MIME-Version: 1.0 References: <9b32b21c0b85692f99213a5adb4cf07dd43d3ad3.camel@cybertec.at> In-Reply-To: <9b32b21c0b85692f99213a5adb4cf07dd43d3ad3.camel@cybertec.at> From: Ayden Gera Date: Sat, 26 Apr 2025 22:19:39 +1200 X-Gm-Features: ATxdqUHIHqQ60t4580CGGdf8bA_YLNlxTEy00Jd95lzh-PbA4785omzDL615c7Q Message-ID: Subject: Re: PGDump question/issue To: Laurenz Albe Cc: pgsql-novice@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000007aefea0633abcaa5" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007aefea0633abcaa5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Laurenz, Thank you very much for your reply. Your assumption was close but not quite correct. Database A is SaaS provided PGDump. it comes with Drop tables commands in it. It has no row level security on it. We want to daily populate DB A into a new DB B (supabase), but we want to add row level security to DB B. Issue is the drop table commands in the PGDump A we believe we will lose any RLS we put in place in DB B? We could put data into a DB C (our own PG instance), then extract data only from DB C with PGDump-a, and then insert that into DB B (supabase) but we need a script to drop all data in DB B before uploading PGDump... What is command we can use either separately or part of the restore PGDump commands to first delete all data before restoring data into DB B with PGDump DB A? Or we could put PGDump A into a separate Supabase Db B2, and then somehow stream only that data into DB B.. but unsure if we can script dropping all data automatically in DB B before DB2 streams data into it as data doesn't always have keys/unique identifiers.. so don't want to risk data double-ups.. dropping data from all table in DB B seems best.. but unclear if streaming can accommodate some automated scripting to drop DB B before it starts..? Im open to any other ideas on how to get around the drop table that comes in PG Dump from DB A. Many Thanks. Ayden On Fri, Apr 25, 2025 at 6:15=E2=80=AFPM Laurenz Albe wrote: > On Fri, 2025-04-25 at 09:50 +1200, Ayden Gera wrote: > > Hoping someone may have a solution to this problem. > > We get a daily PGDump file (@3Gb) from our SaaS provider (for BI > purpose). > > In it, it has a Drop Table IF Exists command.. > > This file has no row level security etc. > > We want to use the same file to populate Supabase with and add row lev= el > > security.. but I believe the drop table will destroy the rls each day a= nd > > manually adding it back *unless mabe scripted) isn't an option. > > > > We have an inhouse Postgresql we can also use to potentially load and > then > > do its own PGDump with data only.. > > > > But the other issue we have is the source tables don't always have any > > unique keys that we can tell.. so to be safe and avoid data duplicate > risk.. > > we prefer to delete the entire tables data before inserting.. > > > > Does anyone have any suggestions on how to best automate the daily > updating > > of data into the supabase tables without losing any RLS we might > configure > > on those tables? > > Or what commands should we run on our own PG to get our own data > only/insert > > + commands to drop all data in all tables before running it. > > > > I was also wondering if we could send PGDump from SaaS to Supabase Db1 > and > > then stream data to DB2 (Prod) but unclear if we can and/or risk data > > duplication risk if we cannot somehow delete the tables in Prod just > before > > streaming.. > > I am not sure I understand correctly: your problem is that you want to co= py > data from a database (let's call it database A) to another database B. > In the process, you want to wipe out all the data in B, but not the table > definitions, because there are different row-level security policies on t= he > tables in A and B. > > Correct? > > Then perhaps this will help: > > 1. export the object definitions from B: > > pg_dump -F c --schema-only -f dumpb B > > 2. export the data from A: > > pg_dump -F c --data-only -f dumpa A > > 3. drop database B, create it again and create all the objects: > > pg_restore -d postgres --clean --create --section=3Dpre-data dumpb > > 4. restore the data from A into the new database: > > pg_restore -d B --section=3Ddata dumpa > > 5. restore the original index definitions and constraints: > > pg_restore -d B --section=3Dpost-data dumpb > > Yours, > Laurenz Albe > --0000000000007aefea0633abcaa5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Laurenz,
Thank you very much for your re= ply.
Your assumption was close but not quite correct.
<= br>
Database A is SaaS provided PGDump. it comes with Drop tables= commands in it. It has no row level security on it.
We want to d= aily populate DB A into a new DB B (supabase), but we want to add row level= security to DB B. Issue is the drop table commands in the PGDump A we beli= eve we will lose any RLS we put in place in DB B?

= We could put data into a DB C (our own PG instance), then extract data only= from DB C with PGDump-a, and then insert that into DB B (supabase) but we = need a script to drop all data in DB B before uploading PGDump... What is c= ommand we can use either separately or part of the restore PGDump commands = to first delete all data before restoring data into DB B with PGDump DB A?<= /div>

Or we could put PGDump A into a separate Supabase = Db B2, and then somehow stream only that data into DB B.. but unsure if we = can script dropping all data automatically in DB B before DB2 streams data = into it as data doesn't always have keys/unique identifiers.. so don= 9;t want to risk data double-ups.. dropping data from all table in DB B see= ms best.. but unclear if streaming can accommodate some automated scripting= to drop DB B before it starts..?

Im open to any o= ther ideas on how to get around the drop table that comes in PG Dump from D= B A.

Many Thanks.
Ayden

<= div class=3D"gmail_quote gmail_quote_container">
On Fri, Apr 25, 2025 at 6:15=E2=80=AFPM Laurenz Albe <laurenz.albe@cybertec.at> wrote= :
On Fri, 2025-0= 4-25 at 09:50 +1200, Ayden Gera wrote:
> Hoping someone may have a solution to this problem.
> We get a daily PGDump file (@3Gb) from our SaaS provider (for BI purpo= se).
> In it, it has a Drop Table IF Exists command..
> This file has no row level security etc.
> We want=C2=A0 to use the same file to populate Supabase with and add r= ow level
> security.. but I believe the drop table will destroy the rls each day = and
> manually adding it back *unless mabe scripted) isn't an option. >
> We have an inhouse Postgresql we can also use to potentially load and = then
> do its own PGDump with data only..
>
> But the other issue we have is the source tables don't always have= any
> unique keys that we can tell.. so to be safe and avoid data duplicate = risk..
> we prefer to delete the entire tables data before inserting..
>
> Does anyone have any suggestions on how to best automate the daily upd= ating
> of data into the supabase tables without losing any RLS we might confi= gure
> on those tables?
> Or what commands should we run on our own PG to get our own data only/= insert
> + commands to drop all data in all tables before running it.
>
> I was also wondering if we could send PGDump from SaaS to Supabase Db1= and
> then stream data to DB2 (Prod) but unclear if we can and/or risk data<= br> > duplication risk if we cannot somehow delete the tables in Prod just b= efore
> streaming..

I am not sure I understand correctly: your problem is that you want to copy=
data from a database (let's call it database A) to another database B.<= br> In the process, you want to wipe out all the data in B, but not the table definitions, because there are different row-level security policies on the=
tables in A and B.

Correct?

Then perhaps this will help:

1. export the object definitions from B:

=C2=A0 =C2=A0pg_dump -F c --schema-only -f dumpb B

2. export the data from A:

=C2=A0 =C2=A0pg_dump -F c --data-only -f dumpa A

3. drop database B, create it again and create all the objects:

=C2=A0 =C2=A0pg_restore -d postgres --clean --create --section=3Dpre-data d= umpb

4. restore the data from A into the new database:

=C2=A0 =C2=A0pg_restore -d B --section=3Ddata dumpa

5. restore the original index definitions and constraints:

=C2=A0 =C2=A0pg_restore -d B --section=3Dpost-data dumpb

Yours,
Laurenz Albe
--0000000000007aefea0633abcaa5--