Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
| Následující verze | Předchozí verze | ||
|
it:postgresql:import_export [2015/09/30 15:15] kourim vytvořeno |
it:postgresql:import_export [2017/06/14 10:55] (aktuální) kourim |
||
|---|---|---|---|
| Řádek 1: | Řádek 1: | ||
| ===== Import & Export ===== | ===== Import & Export ===== | ||
| - | ==== export ==== | + | ==== Export ==== |
| to .psql je ve skutecnosti csv soubor | to .psql je ve skutecnosti csv soubor | ||
| + | <sxh> | ||
| copy(select * from author_roles where attributes->>'activity_Id' != '') to '/tmp/cr_author_roles.psql'; | copy(select * from author_roles where attributes->>'activity_Id' != '') to '/tmp/cr_author_roles.psql'; | ||
| copy(select * from distributors where id = 6) to '/tmp/cr_distributors.psql'; | copy(select * from distributors where id = 6) to '/tmp/cr_distributors.psql'; | ||
| copy(select * from flags where id in (2,6)) to '/tmp/cr_flags.psql'; | copy(select * from flags where id in (2,6)) to '/tmp/cr_flags.psql'; | ||
| + | </sxh> | ||
| - | ==== import ==== | + | ==== Import ==== |
| * musim byt jako su postgres | * musim byt jako su postgres | ||
| * pokud to nejde tak je v .bashrc spatnej alias ze su sudo | * pokud to nejde tak je v .bashrc spatnej alias ze su sudo | ||
| Řádek 14: | Řádek 16: | ||
| ==== Reset autoincrementu ==== | ==== Reset autoincrementu ==== | ||
| - | <sxh mysql> | + | <sxh sql> |
| SELECT setval('distributors_id_seq',(SELECT GREATEST(MAX(id)+1,nextval('distributors_id_seq'))-1 FROM distributors)); | SELECT setval('distributors_id_seq',(SELECT GREATEST(MAX(id)+1,nextval('distributors_id_seq'))-1 FROM distributors)); | ||
| </sxh> | </sxh> | ||
| Řádek 23: | Řádek 25: | ||
| </sxh> | </sxh> | ||
| + | ==== Import + Export ==== | ||
| + | vytvoříme dump z aktuální databáze | ||
| + | <sxh bash>pg_dump -U USERNAME DBNAME > dbexport.pgsql</sxh> | ||
| + | přihlásíme se do postgresu | ||
| + | <sxh bash>psql template1</sxh> | ||
| + | vytvoříme uživatele a databázi s právy | ||
| + | <sxh sql> | ||
| + | CREATE USER tom WITH PASSWORD 'myPassword'; | ||
| + | CREATE DATABASE jerry; | ||
| + | GRANT ALL PRIVILEGES ON DATABASE jerry to tom; | ||
| + | </sxh> | ||
| + | nalejeme data do nové databáze | ||
| + | <sxh bash>psql -U USERNAME DBNAME < dbexport.pgsql</sxh> | ||