Last active
June 6, 2019 06:08
-
-
Save superchell/eb3693b29b493e951f61ebd3dde9da99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Восстановление из дампа ## | |
psql -U <username> -d <dbname> -1 -f <filename>.sql | |
или c помощью pg_restore | |
pg_restore -U <username> -d <dbname> -1 <filename>.dump | |
## Создание дампа ## | |
*из удаденной БД | |
pg_dump --dbname=<remote_db> --file=/path_to_save/dump.sql --username=<remote_user> --host=<remote IP> --port=5432 | |
*из Dokku | |
ssh root@<remote>.com "dokku postgres:export <db_name>" | pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d "<local_db_name>" | |
## psql # | |
\l - вывести все БД | |
\c <db_name> - подключиться к таблице | |
\dn - все схемы | |
\dt - таблицы текущая схема | |
\dt *.* - таблицы все схемы | |
\dt .<schema_name> - таблицы определенная схема | |
## Создать юзера ## | |
createuser -<option> <user_name> | |
--interactive - с мастером создания юзера | |
-s - назначить суперюзером | |
## Создать тестовую базу ## | |
pg_dump -Fc h24_dev_local --clean > db.dump - создаем чистый дамп | |
или | |
pg_dump -Fc -v -s --dbname=<remote db name> --file=db.dump --username=<remote_user> --host=<remote host> --port=5432 - стянуть базу с удаленного хоста и записать в локальный дамп | |
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d p24_test db.dump - разворачиваем дамп в тестовую БД | |
# стянуть удаленную базу и развернуть | |
pg_dump -C -h remotehost -U remoteuser dbname | psql -h localhost -U localuser dbname | |
## Имя сервиса версии 9.6 в Fedora ## | |
postgresql-9.6.service | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment