crude way to restore postgresql database dump to table with a different name

i needed to restore specific table, backed up via pg_dump, to the same database / schema but under different name. that’s what i’ve done


pv dump.zstd|pzstd -dc - |sed 's/name_of_original_table/name_of_renamed_table/g'|su - postgres -c 'psql dbname'

this only works if all constrains / indices have in their name name of the original table.

Leave a Reply

Your email address will not be published. Required fields are marked *

(Spamcheck Enabled)