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 1u8CLf-00Fg0E-T3 for pgsql-novice@arkaria.postgresql.org; Fri, 25 Apr 2025 06:15:44 +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 1u8CLd-007Mq9-TA for pgsql-novice@arkaria.postgresql.org; Fri, 25 Apr 2025 06:15:42 +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 1u8CLd-007Mpl-JM for pgsql-novice@lists.postgresql.org; Fri, 25 Apr 2025 06:15:42 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u8CLb-001qGA-2u for pgsql-novice@lists.postgresql.org; Fri, 25 Apr 2025 06:15:41 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-43ce70f9afbso14880955e9.0 for ; Thu, 24 Apr 2025 23:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1745561739; x=1746166539; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=vRuEk3jcJ7ORqEP3gZYxKygAaO7H7fp4al+dmebLuKk=; b=NRfONSOVxZafo8Zit7DZ1qA2c9i/oGm7nvrylIGdQiMYI2QzAjZu2glYtFA0mYqybf jbG8gZIakVJsx2FZipGBxh5li5irHAadF4Nfu+DGUhusL0YbAwZAjXz4kvhxRLKH4iv8 djgNriy2zBcZ/PdSwq+DN4AYUHgw9SwE19ieJBfk6+tCjAfSq5t2rQLjxkN1piMOqgML MUBlUwR8l2zhf3CDYqcuy1W/QMg1ev06kmzsuT4iGsfPQEa/F7Ij9EXzEZp+xhCVJv6k 00peWkvEdBs3xCpS1481ss0swM9ykCRPlpL+ZCuFJZkj177YmRdCylOmVDadCXT5DUsl Ti6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745561739; x=1746166539; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vRuEk3jcJ7ORqEP3gZYxKygAaO7H7fp4al+dmebLuKk=; b=fsorY2vmxBAd/EaPiodVfvK7SYk4EftIbxOyz+a9UpSYapLfjPNeRiMtnnoHs86qSI 8D121/ZxoLM+/v+9e1aUghTByOAc8WbMOIlmBO3I+e8k+5IWS/XQL+vFNdR7pEr7L/+g PxJKQP9CSf6cuAS80ZRYzSf5uOI/aWBz3X9RnTeWJS3N00dp/PhWvVULaPFmYjJ1NIuq aTmWsr0gU4U5xJTHiH6KtOuVhyIRY+ifBev1Lf5xhb1nKAl0lExjf+wNPk+cpBnTX9uD rS5SFez/HX7lFFmdrrvB3PAFSF+kkDPrtGSxd1aZ6pNfSDROyd4YyT+umWGHvvxJQQ7c zFKQ== X-Forwarded-Encrypted: i=1; AJvYcCXcMV91GbXO2JNNSjKlkyaft9S+waj1uWX2B+5sNhQa6r4j/h4vWNaszYIvF8Lk7rH4O3JSKj1A3d2IZnQ=@lists.postgresql.org X-Gm-Message-State: AOJu0YwFOkhSuiGt+O7CU8/bzxHFjpZg2KQLzNbGYBpvDGN6ObusM00p EPPQD7BbHNMp856rRCwGd+W2+E76dnoxT/Hd46E8sJijqjaH8xsXTV38MRa/DK3e8vuf6/FiEGL GNmI= X-Gm-Gg: ASbGncuVPm3MpD4YvTGOYxUTakVrfeWH+DdoXSv5sXcJNS19MpskNxw90vK60A33t5Y SDCAf9tyAgLAdETGwBY+1gI24qipKTwCfCS2Jjvus37HSnXCsgcW0OG6g5dp7Wvna+nF1NPN/zW Zpn6cCo+uyZpzdZy5fkumtcT3ZUuhI2+Bbph7J1O00zjT4OsXZ35751vwqf2OI+yGs1KiOQphwQ 36kgxGc+dTygd+fmJm6ZLB/iRn9t8PbosnBwkzf+MTxgkAupXJ+JdppP2ihD6j4CebtgVdkSWEi X703De59sOCkAkF/pbbVeK2va1MC6ZYHNg0kIXXQ45UDLHRbpunj1vy3519K X-Google-Smtp-Source: AGHT+IH1hnZrW0Xpd8IUSSdsVRw5t/8FiepsyBFo7a02AEBnsqsShuOcnSRtEeoNawBNtBI9dN2l9A== X-Received: by 2002:a05:600c:154f:b0:43d:b51:46fb with SMTP id 5b1f17b1804b1-440a65ba6camr7287145e9.2.1745561738910; Thu, 24 Apr 2025 23:15:38 -0700 (PDT) Received: from localhost.localdomain ([2001:871:260:e754:5e12:787:a896:2a2e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-440a530a6e9sm13031755e9.16.2025.04.24.23.15.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 23:15:38 -0700 (PDT) Message-ID: <9b32b21c0b85692f99213a5adb4cf07dd43d3ad3.camel@cybertec.at> Subject: Re: PGDump question/issue From: Laurenz Albe To: Ayden Gera , pgsql-novice@lists.postgresql.org Date: Fri, 25 Apr 2025 08:15:37 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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=C2=A0 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. >=20 > We have an inhouse Postgresql we can also use to potentially load and the= n > do its own PGDump with data only.. >=20 > 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 ris= k.. > we prefer to delete the entire tables data before inserting.. >=20 > Does anyone have any suggestions on how to best automate the daily updati= ng > of data into the supabase tables without losing any RLS we might configur= e > on those tables? > Or what commands should we run on our own PG to get our own data only/ins= ert > + commands to drop all data in all tables before running it. >=20 > I was also wondering if we could send PGDump from SaaS to Supabase Db1 an= d > 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 befo= re > 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=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