How to update table structures and stored procedures from Development to Production server in PostgreSQL?

前端 未结 1 602
萌比男神i
萌比男神i 2021-01-26 03:40

I have three PostgreSQL servers:

  1. Development,
  2. Practice
  3. Production

The Production server has all the data of interest and is in hea

相关标签:
1条回答
  • 2021-01-26 04:27

    Here is short step by step tutorial for using liquibase with postgresql to generate database diff in sql format.

    I assume you have java installed.

    • download liquibase itself
    • download latest version of postgresql jdbc driver from http://jdbc.postgresql.org and put it into liquibase home's lib directory
    • run

    ./liquibase --driver=org.postgresql.Driver --url=jdbc:postgresql://host1:port1/dbname1 --username=user1 \ --password=pass1 \ diffChangelog \ --referenceUrl=jdbc:postgresql://host2:port2/dbname2 \ --referenceUsername=user2 \ --referencePassword=pass2 > db-changelog.xml

    Here reference database is your where your changes are made.

    • finally last step to get sql script run (against db at host1:port1):

    ./liquibase --driver=org.postgresql.Driver \ --url=jdbc:postgresql://host1:port1/dbname1 \ --username=user1 \ --password=pass1 \ --changeLogFile=db-changelog.xml \ updateSql > changes.sql

    Before you apply genereated sql script onto production database you should clean it up - liquibase is introducing some metadata tables (databasechangelog and databasechangeloglock) - but thats simple search and delete.

    That's it.

    Final note is as @a_horse_with_no_name said: spend some time to learn how to put your db changes in VCS and avoid executing them manually (in favor of liquibase or flyway).

    0 讨论(0)
提交回复
热议问题