문제

I want to create a 'development' database for my web application.

I'm using Postgres 9.3, and I would like 'devdb' to have the exact table structure as my production 'appdb'. I do not want them to share data, but I want devdb to receive any changes made to table structures, if this is possible. (ie. if i add a new table in appdb, I want devdb to also have the new table, same thing if I remove a column)

Do I need to use schemas for this, and if so, how? My appdb currently has a schema of public.

Thanks!

도움이 되었습니까?

해결책

I think your best bet is to use:

pg_dump --schema-only prod | psql dev

To keep the schemas in sync, either drop and reload the dev db, or script your schema changes so you can apply the change to both DBs. You should be doing that anyway, testing changes in dev before applying them to production.

(Tools like Liquibase can be interesting for this).

Attempts to link DDL definitions directly are unsafe. They create a dependency from production to dev. That's risky.

For example, if you were to use a table inheritance based approach then a long-running transaction holding a lock on the dev tables might cause delays on production.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top