Exporting a Table
You can use gs_dump to export data and definition of a table-level object from GaussDB(DWS). Views, sequences, and foreign tables are special tables. You can export one or more specified tables as needed. You can specify the information to be exported as follows:
- Export full information of a table, including its data and definition.
- Export data of a table.
- Export the definition of a table.
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.staffs and hr.employments tables.
gs_dump -W Bigdata@123 -U jack -f /home/dbadmin/backup/MPPDB_table_backup -p 8000 human_resource -t hr.staffs -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_table_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
-t
Table (or view, sequence, foreign table) to be exported. You can specify multiple tables by listing them or using wildcard characters. When you use wildcard characters, quote wildcard patterns with single quotation marks ('') to prevent the shell from expanding the wildcard characters.
- Single table: Enter -t schema.table.
- Multiple tables: Enter -t schema.table for each table.
- Single table: -t hr.staffs
- Multiple tables: -t hr.staffs -t hr.employments
-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_table_backup.sql -p 8000 human_resource -t hr.staffs -Z 6 -F p gs_dump[port='8000'][human_resource][2017-07-21 17:05:10]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2017-07-21 17:05:10]: total time: 3116 ms
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_table_data_backup.tar -p 8000 human_resource -t hr.staffs -a -F t gs_dump[port='8000'][human_resource][2017-07-21 17:04:26]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2017-07-21 17:04:26]: total time: 2570 ms
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_table_def_backup -p 8000 human_resource -t hr.staffs -s -F d gs_dump[port='8000'][human_resource][2017-07-21 17:03:09]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2017-07-21 17:03:09]: total time: 2297 ms
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_table_backup4.dmp -p 8000 human_resource -T hr.staffs -F c gs_dump[port='8000'][human_resource][2017-07-21 17:14:11]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2017-07-21 17:14:11]: total time: 2450 ms
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_table_backup1.sql -p 8000 human_resource -t hr.staffs -t hr.employments -F p gs_dump[port='8000'][human_resource][2017-07-21 17:19:42]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2017-07-21 17:19:42]: total time: 2414 ms
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_table_backup2.sql -p 8000 human_resource -T hr.staffs -T hr.employments -F p gs_dump[port='8000'][human_resource][2017-07-21 17:21:02]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2017-07-21 17:21:02]: total time: 3165 ms
Example 7: Run gs_dump to export data and definition of the hr.staffs table, and the definition of the hr.employments table. The exported files are in .tar format.
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_table_backup3.tar -p 8000 human_resource -t hr.staffs -t hr.employments --exclude-table-data hr.employments -F t gs_dump[port='8000'][human_resource][2018-11-14 11:32:02]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2018-11-14 11:32:02]: total time: 1645 ms
Example 8: Run gs_dump to export data and definition of the hr.staffs table, encrypt the exported files, and store them in text format.
gs_dump -W Bigdata@123 -f /home/dbadmin/backup/MPPDB_table_backup4.sql -p 8000 human_resource -t hr.staffs --with-encryption AES128 --with-key 1212121212121212 -F p gs_dump[port='8000'][human_resource][2018-11-14 11:35:30]: dump database human_resource successfully gs_dump[port='8000'][human_resource][2018-11-14 11:35:30]: total time: 6708 ms
Example 9: 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_table_backup5.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
Example 10: Run gs_dump to export the definition of the view referencing to the test1 table in the t1 schema. The exported files are in a custom format.
gs_dump -W Bigdata@123 -U jack -f /home/dbadmin/backup/MPPDB_view_backup6 -p 8000 human_resource -t t1.test1 --include-depend-objs --exclude-self -F d gs_dump[port='8000'][jack][2018-11-14 17:21:18]: dump database human_resource successfully gs_dump[port='8000'][jack][2018-11-14 17:21:23]: total time: 4239 ms
Last Article: Exporting a Schema
Next Article: Exporting All Databases
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.