Obsah

Import & Export

Export

to .psql je ve skutecnosti csv soubor

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 flags where id in (2,6)) to '/tmp/cr_flags.psql';

Import

Reset autoincrementu

SELECT setval('distributors_id_seq',(SELECT GREATEST(MAX(id)+1,nextval('distributors_id_seq'))-1 FROM distributors));

Dump struktury

pg_dump -d core --clean --create --schema-only > /tmp/core-schema.psql

Import + Export

vytvoříme dump z aktuální databáze

pg_dump -U USERNAME DBNAME > dbexport.pgsql
přihlásíme se do postgresu
psql template1
vytvoříme uživatele a databázi s právy
CREATE USER tom WITH PASSWORD 'myPassword';
CREATE DATABASE jerry;
GRANT ALL PRIVILEGES ON DATABASE jerry to tom;
nalejeme data do nové databáze
psql -U USERNAME DBNAME < dbexport.pgsql