Skip to content

Instantly share code, notes, and snippets.

@hrishimittal
Last active January 6, 2017 15:11
Show Gist options
  • Save hrishimittal/7336829 to your computer and use it in GitHub Desktop.
Save hrishimittal/7336829 to your computer and use it in GitHub Desktop.
Postgres
#Dump database
pg_dump -Fc -f filename.pgdump database_name
#Restore db from dump
dropdb database_name && createdb database_name
pg_restore -n public -x -d database_name -j 2 -Fc filename.pgdump > /dev/null
psql:
#create role
CREATE ROLE rolename;
#create new datatbase with owner - best way to make a db for a new Rails app
CREATE DATABASE dbname OWNER rolename;
#does what it says on the tin:
GRANT ALL PRIVILEGES on DATABASE dbname to username;
#If you get an error saying role "username" is not permitted to log in, fix by running this:
ALTER ROLE "username" WITH LOGIN;
#use databasename:
\c databasename
#list users
\du
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment