Last active
January 6, 2017 15:11
-
-
Save hrishimittal/7336829 to your computer and use it in GitHub Desktop.
Postgres
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
#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