Skip to content

Instantly share code, notes, and snippets.

@mrTimofey
Last active March 9, 2018 04:38
Show Gist options
  • Save mrTimofey/1aaee9155f46fdb9db7d451919ee9ddf to your computer and use it in GitHub Desktop.
Save mrTimofey/1aaee9155f46fdb9db7d451919ee9ddf to your computer and use it in GitHub Desktop.
PostgreSQL snippets (create database, create user, dump, restore)

Go to PostgreSQL CLI:

su - postgres
psql

Create user SQL

create user USER with password PASSWORD;

Create database with Russian locale SQL

create database DATABASE with owner USER encoding 'UTF-8' lc_collate = 'ru_RU.utf8' lc_ctype = 'ru_RU.utf8' template = template0;

Dump

su - postgres -c '/usr/bin/pg_dump -Fc $(DATABASE) > $(DATABASE)-$(date +"%Y-%m-%d-%H-%M").dump'

Restore

su - postgres -c '/usr/bin/pg_restore -d $(DATABASE) --role=$(OWNER) --no-owner DUMP_FILE_NAME'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment