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.