I have three PostgreSQL servers:
The Production server has all the data of interest and is in hea
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.
./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.
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).