Unsafe Migrate postgresql from a to b

Run on db a:



pg_dump --file "db-a.tar" --host "11.153.1.3" --port "5432" --username "supabase_admin" --no-password --format=t --blobs --encoding "UTF8" --inserts --rows-per-insert "1" --on-conflict-do-nothing --verbose --schema "public" --create --clean "postgres"


Drop all table on database b with schema public:


DO $$
DECLARE
    r RECORD;
BEGIN
    FOR r IN (
        SELECT tablename
        FROM pg_tables
        WHERE schemaname = 'public'
        AND tablename NOT IN ('spatial_ref_sys', 'y', 'z') -- List of tables to keep
    )
    LOOP
        EXECUTE format('DROP TABLE IF EXISTS public.%I CASCADE', r.tablename);
    END LOOP;
END $$;

Run on db b: Copy file db-a.tar from a to b

pg_restore -h 172.17.0.1 -U supabase_admin -d postgres db-a.tar


Comments