Exporting a Table
Tags: opengauss
Published: 2023-04-10 06:46:41

You can use gs_dump to export data and definition of a table-level object from openGauss. Views, sequences, and foreign tables are special tables. You can export one or more specified tables as needed. You can specify the information to export 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**
1. Log in as the OS user omm to the primary node of the database.

2. Run gs_dump to export the hr.staffs and hr.employments tables.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a17v48vzfzw2nzovlnuc.png)

Table 1 Common parameters

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zcixhxp7nt4ql5d536v6.png)

For details about other parameters, see “Server Tools > gs_dump” in the Tool Reference.

Examples
Example 1: Run **gs_dump** to export definitions and data of the **hr.staffs** table. The exported files are in text format.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g4bmg5u6sx30plmux66u.png)

Example 2: Run **gs_dump** to export data of the **hr.staffs** table. The exported files are in .tar format.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vcze82jg7m0n69ra4b3u.png)

Example 3: Run **gs_dump** to export the definition of the **hr.staffs** table. The exported files are stored in a directory.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/klovbh2haprhulsnaeef.png)

Example 4: Run **gs_dump** to export the **human_resource** database excluding the **hr.staffs** table. The exported files are in a custom format.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fr327arp5vc373lgknwt.png)

Example 5: Run **gs_dump** to export the **hr.staffs** and **hr.employments** tables. The exported files are in text format.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ireaal1w0oxz846qalpc.png)

Example 6: Run **gs_dump** to export the **human_resource** database excluding the **hr.staffs** and **hr.employments** tables. The exported files are in text format.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dxf17ugkj91q3ry98vc.png)

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1t0nncdtnygmajdcyydp.png)

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbdt8trwggl84e6s42dm.png)

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pjckujwown7rf0ncha13.png)

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7det9ef8rs7x713a50l.png)