This shows you the differences between two versions of the page.
— |
wiki:postgres:pg_tune_kurs_exportimport [2017/09/28 12:21] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Export und Import von Datensätzen ====== | ||
+ | ===== Export einer Abfrage nach Excel ===== | ||
+ | copy (SELECT *, rank ... FROM t_test) TO '/home/schild/file.csv' CSV; | ||
+ | ===== Import von Datensätzen ===== | ||
+ | |||
+ | * Das folgende Beispiel erzeugt 10.000 Transaktionen und ist dementsprechend langsam (d.h. 10.000 mal insert; commit; fsync; ...) | ||
+ | vim file.sql | ||
+ | insert into ... values ... 1; | ||
+ | ... | ||
+ | insert into ... values ... 1; | ||
+ | ... 10.000 Insert Statements | ||
+ | |||
+ | time psql test < /home/kurs/file.sql > /dev/null | ||
+ | |||
+ | * Das folgende Beispiel erzeugt nur 1 Transaktion und ist dementsprechend schneller (hier ca. 6x so schnell) | ||
+ | vim file.sql | ||
+ | begin; | ||
+ | insert into ... values ... 1; | ||
+ | ... 10.000x | ||
+ | commit; | ||
+ | |||
+ | * Das folgende Beispiel spart sich mittels truncate das x_log und ist daher die **schnellste** Import-Möglichkeit | ||
+ | vim file.sql | ||
+ | begin; | ||
+ | truncate t_test /* löscht das Storagefile -> schreiben des x_log's erspart | ||
+ | copy t_test from stdin; | ||
+ | 1 | ||
+ | 1 | ||
+ | 1 | ||
+ | 1 | ||
+ | commit; |