How to migrate your PostgreSQL database from the development environment to the production environment

Source: Internet
Author: User
Tags psql

Sometimes we need to migrate the database from the development environment to the production environment. Now we only need to migrate an empty database (including the table structure, the data (usually the test data during development) is not required.

You can use the tools provided by PostgreSQL. The procedure is simple:

1) Pilot Database Export
The command is as follows:
Pg_dump-s-h server name or IP database name> file name. SQL

For example:
$ Pg_dump-s-h localhost mydatabase> mydb_export. SQL

2) create a blank database manually in the production environment. The database name must be consistent with that in the development environment. (For example, mydatabase)

3) import to the production environment
Copy the previously exported file mydb_export. SQL to the production environment and run the following command:
Psql-F file name. SQL database name

For example:
$ Psql-F mydb_export. SQL mydatabase

Success!

PS:

If it is running on Windows, because the current user is not necessarily a PostgreSQL user, you need to add a parameter '-u Username' when using these commands'

For example:

C:/> Psql-u Postgres-F mydb_export. SQL mydatabase

Then the system prompts you to enter the password.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.