Exporting a Schema
You can use gs_dump to export data and all object definitions of a schema from GaussDB(DWS). You can export one or more specified schemas as needed. You can specify the information to be exported 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
- Connect to the default database postgres as a database administrator through the database client tool provided by GaussDB(DWS).
For example, use the gsql client to connect to the database by running the following command:
1
gsql -d postgres -h 192.168.2.30 -U dbadmin -p 8000 -r
Enter your password as prompted.
- Run gs_dump to export the hr and public schemas.
gs_dump -W Bigdata@123 -U jack -f /home/dbadmin/backup/MPPDB_schema_backup -p 8000 human_resource -n hr -F d
Table 1 Common parameters Parameter
Description
Example Value
-U
User name for database connection.
-U jack
-W
User password for database connection.
- This parameter is not required for database administrators if the trust policy is used for authentication.
- If you connect to the database without specifying this parameter and you are not a database administrator, you will be prompted to enter the password.
-W Bigdata@123
-f
Folder to store exported files. If this parameter is not specified, the exported files are stored in the standard output.
-f /home/dbadmin/backup/MPPDB_schema_backup
-p
TCP port or the local Unix-domain socket file extension on which the server is listening for connections.
-p 8000
dbname
Name of the database to be exported.
human_resource
-n
Names of schemas to be exported. Data of the specified schemas will also be exported.
- Single schema: Enter -n schemaname.
- Multiple schemas: Enter -n schemaname for each schema.
- Single schemas: -n hr
- Multiple schemas: -n hr -n public
-F
Format of exported files. The values of -F are as follows:
- p: plain text
- c: custom
- d: directory
- t: .tar
-F d
For details about other parameters, see gs_dump.
Examples
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_schema_backup.sql -p 8000 human_resource -n hr -Z 6 -F p 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
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_schema_data_backup.tar -p 8000 human_resource -n hr -a -F t 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
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_schema_def_backup -p 8000 human_resource -n hr -s -F d 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
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_schema_backup.dmp -p 8000 human_resource -N hr -F c 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
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_schema_backup1.tar -p 8000 human_resource -n hr -n public -s --with-encryption AES128 --with-key 1234567812345678 -F t 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
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_schema_backup2.dmp -p 8000 human_resource -N hr -N public -F c 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 -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_backup3.dmp -p 8000 human_resource -t public.* -t hr.staffs -F c 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
Last Article: Exporting a Database
Next Article: Exporting a Table
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.