How to duplicate schemas in PostgreSQL

前端 未结 5 1640
日久生厌
日久生厌 2021-02-01 04:09

I have a database with schema public and schema_A. I need to create a new schema schema_b with the same structure than schema_a

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 04:39

    You can probably do it from the command line without using files:

    pg_dump -U user --schema='fromschema' database | sed 's/fromschmea/toschema/g' | psql -U user -d database

    Note that this searches and replaces all occurrences of the string that is your schema name, so it may affect your data.

提交回复
热议问题