Exporting a Schema
You can use gs_dump to export data and all object definitions of a schema from openGauss. You can export one or more specified schemas as needed. You can specify the information to export as follows:
- Export full information of a schema, including its data and object definitions.
- Export data of a schema, excluding its object definitions.
- Export the object definitions of a schema, including the definitions of tables, stored procedures, and indexes.
Procedure
Log in as the OS user omm to the primary node of the database.
Run gs_dump to export the hr and public schemas.
gs_dump -U jack -f /home/omm/backup/MPPDB_schema_backup -p 8000 human_resource -n hr -n public -F d Password:
Table 1 Common parameters
For details about other parameters, see “Server Tools > gs_dump” in Tool Reference.
Examples
Example 1: Run gs_dump to export full information of the hr schema. The exported file is in text format.
gs_dump -f /home/omm/backup/MPPDB_schema_backup.sql -p 8000 human_resource -n hr -F p
Password:
gs_dump[port='8000'][human_resource][2017-07-21 16:05:55]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 16:05:55]: total time: 2425 ms
Example 2: Run gs_dump to export data of the hr schema. The exported files are in .tar format.
gs_dump -f /home/omm/backup/MPPDB_schema_data_backup.tar -p 8000 human_resource -n hr -a -F t
Password:
gs_dump[port='8000'][human_resource][2018-11-14 15:07:16]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2018-11-14 15:07:16]: total time: 1865 ms
Example 3: Run gs_dump to export the object definitions of the hr schema. The exported files are stored in a directory.
gs_dump -f /home/omm/backup/MPPDB_schema_def_backup -p 8000 human_resource -n hr -s -F d
Password:
gs_dump[port='8000'][human_resource][2018-11-14 15:11:34]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2018-11-14 15:11:34]: total time: 1652 ms
Example 4: Run gs_dump to export the human_resource database excluding the hr schema. The exported files are in a custom format.
gs_dump -f /home/omm/backup/MPPDB_schema_backup.dmp -p 8000 human_resource -N hr -F c
Password:
gs_dump[port='8000'][human_resource][2017-07-21 16:06:31]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 16:06:31]: total time: 2522 ms
Example 5: Run gs_dump to export the definitions of both the hr and public schemas. The exported file is in .tar format.
gs_dump -f /home/omm/backup/MPPDB_schema_backup1.tar -p 8000 human_resource -n hr -n public -s -F t
Password:
gs_dump[port='8000'][human_resource][2017-07-21 16:07:16]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 16:07:16]: total time: 2132 ms
Example 6: Run gs_dump to export the human_resource database excluding the hr and public schemas. The exported files are in a custom format.
gs_dump -f /home/omm/backup/MPPDB_schema_backup2.dmp -p 8000 human_resource -N hr -N public -F c
Password:
gs_dump[port='8000'][human_resource][2017-07-21 16:07:55]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2017-07-21 16:07:55]: total time: 2296 ms
Example 7: Run gs_dump to export all tables (views, sequences, and foreign tables are also included) in the public schema and the staffs table in the hr schema, including data and table definition. The exported files are in a custom format.
gs_dump -f /home/omm/backup/MPPDB_backup3.dmp -p 8000 human_resource -t public.* -t hr.staffs -F c
Password:
gs_dump[port='8000'][human_resource][2018-12-13 09:40:24]: dump database human_resource successfully
gs_dump[port='8000'][human_resource][2018-12-13 09:40:24]: total time: 896 ms