4

I create a database, some tables and stored procedures on my local postgres server. Now I want to automatically migrate these things to my production server without creating everything from scratch again. This should be something quite straight-forward, however I did not find any books trying to explain this. So I wonder how could it be achieved? Can someone please provide some link of tutorials? Thanks!

5
  • You mean to create tables and procedure in your local DB to the production DB and no need to copy data in tables, right? and Juts to confirm both DBs are PostgreSQL,isn't it? Commented Jan 5, 2016 at 6:07
  • @wingedpanther yeah, just schemas. Commented Jan 5, 2016 at 6:08
  • You are using the wrong process. Put each change that you make in a (SQL) script, then store those scripts in a version control system. When you deploy to production, run those migration scripts in production. Anything else will get you in a lot of trouble in the long run. You might want to check out tools like Liquibase or Flyway that help (a lot) to manage schema migration steps Commented Jan 5, 2016 at 9:20
  • @a_horse_with_no_name: I thought of using VCS to manage all the scripts. But will it be troublesome to track the changes and make the changes manually? It is especially so when when there are several commits, each with several changes, before I pull on server side. Commented Jan 5, 2016 at 9:53
  • That's why I recommend using Liquibase (or Flyway). Once you are past the initial release in production your current solution is going to fail at some point. Commented Jan 5, 2016 at 10:06

1 Answer 1

6

Use pg_dump for this purpose, Postgres has great tutorial. For single schema instruction may be the following:

pg_dump -o -h hostname -U db_username -d db_name -n schema_name > your_schema.dump

Sample restore command:

psql -h hostname -U db_username db_name < your_schema.dump
Sign up to request clarification or add additional context in comments.

1 Comment

I would add -s in the first command, since the question was asking to migrate only the schema, not the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.