Skip to content

Commit

Permalink
update dump document
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejiazhi committed Jun 9, 2023
1 parent 32c081a commit b337260
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 6 deletions.
190 changes: 190 additions & 0 deletions dump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# pgii Backup export and import functions

pgii can be used as a PostgreSql import and export tool, which can import and export large tables with millions of data

## Generate test data in postgreSql
**Table structure and statements for inserting data,5000000pcs**
~~~C
CREATE TABLE t_test(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);

insert
into
t_test
select
generate_series(1, 5000000) as key,
repeat( chr(int4(random()* 26)+ 65), 4),
(random()*(6 ^2))::integer,
null,
(random()*(10 ^4))::integer;
~~~
## View the generated data
~~~C
pgi~[yc/pgii]# show tb;
+--------+-----------+------------+------------+-----------+-----------+
| SCHEMA | TABLENAME | TABLEOWNER | TABLESPACE | TABLESIZE | INDEXSIZE |
+--------+-----------+------------+------------+-----------+-----------+
| pgii | t_test | postgres | <nil> | 356 MB | 107 MB |
+--------+-----------+------------+------------+-----------+-----------+
pgi~[yc/pgii]# select count(*) from t_test;
+---------+
| COUNT |
+---------+
| 5000000 |
+---------+
[Total: 1 Rows] [RunTimes 0.20s]
~~~

## DUMP Order
- **dump table**: Export the structure and data of the table. If more than 50000 data pieces have been added to the table, a batch import file is generated based on 50000 data pieces✅;
- **dump schema**:You can export the creation statement of the selected mode, select the structure and data of the table in the mode, and segment the table with more than 50,000 data in a single table to generate a batch import file according to 50,000 data✅;
- **dump database**:todo(developing)

### dump <tb|table> <tableName>
***Instructions:***<br/>
> Export the specified table to the corresponding pgi compressed file
***Usage:***<br/>
~~~C
pgi~[yc/pgii]# dump tb t_test;
Dump Table Success [t_test].....
~~~
In the following figure, a folder dump_table_pgii_1686301979 is generated under the folder where the command is located, and the exported backup files generated by t_test table are displayed under the folder
![image](https://github.com/xuejiazhi/pgii/assets/16795993/2a2a6490-19fe-4fb1-ad36-6a8042f38e63)

### dump <sc|schema>
***Instructions:***<br/>
> Export the table and table data in the specified mode to the corresponding pgi compressed file. When using this command, you need to select the corresponding mode; otherwise, it cannot be completed;
***Usage:***<br/>
~~~C
pgi~[yc/pgii]# show tb;
+--------+-----------+------------+------------+-----------+-----------+
| SCHEMA | TABLENAME | TABLEOWNER | TABLESPACE | TABLESIZE | INDEXSIZE |
+--------+-----------+------------+------------+-----------+-----------+
| pgii | t_test | postgres | <nil> | 356 MB | 107 MB |
+--------+-----------+------------+------------+-----------+-----------+
| pgii | t_user | postgres | <nil> | 128 kB | 40 kB |
+--------+-----------+------------+------------+-----------+-----------+

pgi~[yc/pgii]# dump sc;
Dump Schema Success [pgii]
Dump Table Success [t_test].....
Dump Table Success [t_user].....
~~~
In the following figure, a folder dump_schema_pgii_1686302845 is generated under the folder where the command resides. Under the folder is the pgi export abbreviated file generated by the related tables in the pgii schema
![image](https://github.com/xuejiazhi/pgii/assets/16795993/0160ecb9-dd7c-4764-b151-a490d6c292c8)


## Load Order
- **Load table**: Export the structure and data of the table. If more than 50000 data pieces have been added to the table, a batch import file is generated based on 50000 data pieces✅;
- **Load schema**:You can export the creation statement of the selected mode, select the structure and data of the table in the mode, and segment the table with more than 50,000 data in a single table to generate a batch import file according to 50,000 data✅;
- **Load database**:todo(developing)

### load <tb|table> <table backup filepath>
***Instructions:***<br/>
> To import the table structure and table data under the specified table backup file path into a new schema or under the schema of its database, the schema must be selected。
**Usage:**<br/>
- **Select another database xc and schema pgii**
~~~C
pgi~[yc/]# use db xc;
Use Database Success!
pgi~[xc/]# use sc pgii;
Use Schema Success!
~~~
- **Start load The name of the backup folder dump_table_pgii_1686301979 by "dump tb"**
~~~C
pgi~[xc/pgii]# load tb dump_table_pgii_1686301979;
Load Table Success [dump_table_pgii_1686301979/tb_t_test.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_1.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_2.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_3.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_4.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_5.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_6.pgi] Affect Nums:50000
.
.
.
Load Table Success [dump_table_pgii_1686301979/tb_t_test_99.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_100.pgi] Affect Nums:0
~~~

- **The query table is as follows. The table has been successfully imported**
~~~C
pgi~[xc/pgii]# show tb;
+--------+-----------+------------+------------+-----------+-----------+
| SCHEMA | TABLENAME | TABLEOWNER | TABLESPACE | TABLESIZE | INDEXSIZE |
+--------+-----------+------------+------------+-----------+-----------+
| pgii | t_test | postgres | <nil> | 356 MB | 107 MB |
+--------+-----------+------------+------------+-----------+-----------+
pgi~[xc/pgii]# select count(*) from t_test;
+---------+
| COUNT |
+---------+
| 5000000 |
+---------+
[Total: 1 Rows] [RunTimes 0.20s]
~~~
### load <sc|schema> <schema backup filepath>
***Instructions:***<br/>
> Import the schema and all table structure and table data in the file path of the specified schema backup to another database;
**Usage:**<br/>
- **Select another database xc**
~~~C
pgi~[yc/]# use db xc;
Use Database Success!
~~~
- **Start load The backup folder name dump_schema_pgii_1686302845**
~~~C
pgi~[xc/pgii]# load sc dump_schema_pgii_1686302845;
Load Table Success [dump_table_pgii_1686301979/tb_t_test.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_1.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_2.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_3.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_4.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_5.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_6.pgi] Affect Nums:50000
.
.
.
Load Table Success [dump_table_pgii_1686301979/tb_t_test_99.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_100.pgi] Affect Nums:0
Load Table Success [dump_schema_pgii_1686302845/tb_t_user.pgi] Affect Nums:1000
~~~

- **The query table is as follows. The table has been successfully imported**
~~~C
pgi~[xc/pgii]# show tb;
+--------+-----------+------------+------------+-----------+-----------+
| SCHEMA | TABLENAME | TABLEOWNER | TABLESPACE | TABLESIZE | INDEXSIZE |
+--------+-----------+------------+------------+-----------+-----------+
| pgii | t_test | postgres | <nil> | 356 MB | 107 MB |
+--------+-----------+------------+------------+-----------+-----------+

pgi~[xc/pgii]# select count(*) from t_test;
+---------+
| COUNT |
+---------+
| 5000000 |
+---------+
[Total: 1 Rows] [RunTimes 0.20s]

pgi~[xc/pgii]# select count(*) from t_user;
+-------+
| COUNT |
+-------+
| 1000 |
+-------+
[Total: 1 Rows] [RunTimes 0.10s]
~~~
115 changes: 112 additions & 3 deletions dump_cn.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pgii 备份导出与导入功能
pgii 可以做为是一个PostgreSql的一个导入导出工具,可以对千万数据的大表进行备份导入导出;
pgii 可以做为是一个PostgreSql的一个导入导出工具,可以对百万级,千万数据的大表进行备份导入导出;

## postgreSql下生成测试数据
**表结构和插入数据的语句,5000000条**
Expand Down Expand Up @@ -47,7 +47,7 @@ pgi~[yc/pgii]# select count(*) from t_test;
- **dump database**:todo(开发中)

### dump <tb|table> <tableName>
***FUNCTION***<br/>
***说明***<br/>
> 将指定的表导出对应的pgi压缩文件
***用法:***<br/>
Expand All @@ -59,7 +59,7 @@ pgi~[yc/pgii]# dump tb t_test;
![image](https://github.com/xuejiazhi/pgii/assets/16795993/2a2a6490-19fe-4fb1-ad36-6a8042f38e63)

### dump <sc|schema>
***FUNCTION***<br/>
***说明***<br/>
> 将指定模式下的表和表数据等导出对应的pgi压缩文件,在使用这个指令时需要选中对应的模式,否则无法完成;
***用法:***<br/>
Expand All @@ -80,3 +80,112 @@ pgi~[yc/pgii]# dump sc;
~~~
如下图,在命令所在的文件夹下面生成了一个 dump_schema_pgii_1686302845 的文件夹,文件夹下面是pgii这个模式下面相关的表生成的pgi导出缩文件
![image](https://github.com/xuejiazhi/pgii/assets/16795993/0160ecb9-dd7c-4764-b151-a490d6c292c8)


## Load 指令
- **Load table**: 导出表的结构和数据,对大于50000条数据已上的表会进行分段处理,按50000条数据生成一个批量导入的文件✅;
- **Load schema**:可以导出选中模式的创建语句,选中模式下的表的结构与数据,对于单表大于50000条数据的表会进行分段处理,按50000条数据生成一个批量导入的文件✅;
- **Load database**:todo(开发中)

### load <tb|table> <table backup filepath>
***说明:***<br/>
> 将指定的表备份的文件路径下的表的结构与表数据导入到一个新的模式下面或者其数据库的模式下面,必须选中模式。
**用法:**<br/>
- **选中另外一个数据xc和模式pgii**
~~~C
pgi~[yc/]# use db xc;
Use Database Success!
pgi~[xc/]# use sc pgii;
Use Schema Success!
~~~
- **开始load先前dump tb出来的备份文件夹名称 dump_table_pgii_1686301979**
~~~C
pgi~[xc/pgii]# load tb dump_table_pgii_1686301979;
Load Table Success [dump_table_pgii_1686301979/tb_t_test.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_1.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_2.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_3.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_4.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_5.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_6.pgi] Affect Nums:50000
.
.
.
Load Table Success [dump_table_pgii_1686301979/tb_t_test_99.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_100.pgi] Affect Nums:0
~~~

- **查询表如下,表已经成功的导入过来了**
~~~C
pgi~[xc/pgii]# show tb;
+--------+-----------+------------+------------+-----------+-----------+
| SCHEMA | TABLENAME | TABLEOWNER | TABLESPACE | TABLESIZE | INDEXSIZE |
+--------+-----------+------------+------------+-----------+-----------+
| pgii | t_test | postgres | <nil> | 356 MB | 107 MB |
+--------+-----------+------------+------------+-----------+-----------+
pgi~[xc/pgii]# select count(*) from t_test;
+---------+
| COUNT |
+---------+
| 5000000 |
+---------+
[Total: 1 Rows] [RunTimes 0.20s]
~~~
### load <sc|schema> <schema backup filepath>
***说明:***<br/>
> 将指定的模式备份的文件路径下的模式和所有表的结构与表数据导入到其它数据库下面,。
**用法:**<br/>
- **选中另外一个数据xc**
~~~C
pgi~[yc/]# use db xc;
Use Database Success!
~~~
- **开始load先前dump sc出来的备份文件夹名称 dump_schema_pgii_1686302845**
~~~C
pgi~[xc/pgii]# load sc dump_schema_pgii_1686302845;
Load Table Success [dump_table_pgii_1686301979/tb_t_test.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_1.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_2.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_3.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_4.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_5.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_6.pgi] Affect Nums:50000
.
.
.
Load Table Success [dump_table_pgii_1686301979/tb_t_test_99.pgi] Affect Nums:50000
Load Table Success [dump_table_pgii_1686301979/tb_t_test_100.pgi] Affect Nums:0
Load Table Success [dump_schema_pgii_1686302845/tb_t_user.pgi] Affect Nums:1000
~~~

- **查询表如下,表已经成功的导入过来了**
~~~C
pgi~[xc/pgii]# show tb;
+--------+-----------+------------+------------+-----------+-----------+
| SCHEMA | TABLENAME | TABLEOWNER | TABLESPACE | TABLESIZE | INDEXSIZE |
+--------+-----------+------------+------------+-----------+-----------+
| pgii | t_test | postgres | <nil> | 356 MB | 107 MB |
+--------+-----------+------------+------------+-----------+-----------+
| pgii | t_user | postgres | <nil> | 128 kB | 40 kB |
+--------+-----------+------------+------------+-----------+-----------+

pgi~[xc/pgii]# select count(*) from t_test;
+---------+
| COUNT |
+---------+
| 5000000 |
+---------+
[Total: 1 Rows] [RunTimes 0.20s]

pgi~[xc/pgii]# select count(*) from t_user;
+-------+
| COUNT |
+-------+
| 1000 |
+-------+
[Total: 1 Rows] [RunTimes 0.10s]
~~~
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

# A postgreSql Cli tool
[![imi License](https://img.shields.io/badge/license-MIT-green)](https://github.com/xuejiazhi/pgii/blob/main/LICENSE)
English | [简体中文](./readme_cn.md)| [Help Document](https://github.com/xuejiazhi/pgii/wiki/pgii--postgreSql-Cli--Help-document)
English |[Import/Export Help](./dump.md)|[简体中文](./readme_cn.md)| [Help Document](https://github.com/xuejiazhi/pgii/wiki/pgii--postgreSql-Cli--Help-document)

pgii is a PostgreSql cli tool. PostgreSql is developed in CMD or Golang and can be compiled for multiple platforms:

- **cross-platform**: Can be compiled under multiple platforms, cross-platform use;
- **Zero-cost learning**:Similar to the MySQL Cli command, familiar with the mysql operation of the people on the hand;
- **Interactive Console**: Through the console command line。
- **Interactive Console**: Through the console command line。[[Import/export help]](./dump.md)

**Welcome to join us to develop**

Expand Down
3 changes: 2 additions & 1 deletion readme_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

# 一个postgreSql的Cli工具
[![imi License](https://img.shields.io/badge/license-MIT-green)](https://github.com/xuejiazhi/pgii/blob/main/LICENSE)
简体中文 | [English](./readme.md) | [帮助文档](https://github.com/xuejiazhi/pgii/wiki/pgii-%E4%B8%AD%E6%96%87%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3)<br/>
简体中文 |[导入导出帮助](./dump_cn.md) |[English](./readme.md) | [帮助文档](https://github.com/xuejiazhi/pgii/wiki/pgii-%E4%B8%AD%E6%96%87%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3)<br/>
pgii 是一个PostgreSql cli的工具,对PostgreSql 在CMD或者,采用Golang进行开发,可以多平台下面编译使用:

- **跨平台**: 可以在多平台下编译,跨平台使用;
- **零学习成本**:类似于MySQL Cli的指令,对熟悉mysql操作的人上手快;
- **互动 Console**: 通过命令行 console。
- **大数据的导出与导入**:通过dump与load指令可以对数据进行导入导出,非常的方便,可以对千万级的大表进行操作,[[导入导出帮助]](./dump_cn.md)


# 登录
Expand Down

0 comments on commit b337260

Please sign in to comment.