Re: PGDump question/issue - Mailing list pgsql-novice

From Laurenz Albe
Subject Re: PGDump question/issue
Date
Msg-id 9b32b21c0b85692f99213a5adb4cf07dd43d3ad3.camel@cybertec.at
Whole thread Raw
In response to PGDump question/issue  (Ayden Gera <aydengera@gmail.com>)
Responses Re: PGDump question/issue
List pgsql-novice
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 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 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 copy
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 the
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=pre-data dumpb

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

   pg_restore -d B --section=data dumpa

5. restore the original index definitions and constraints:

   pg_restore -d B --section=post-data dumpb

Yours,
Laurenz Albe



pgsql-novice by date:

Previous
From: Ayden Gera
Date:
Subject: PGDump question/issue
Next
From: Ayden Gera
Date:
Subject: Re: PGDump question/issue