Skip to content

Instantly share code, notes, and snippets.

@blackawa
Created November 8, 2016 09:14
Show Gist options
  • Save blackawa/aeb54968033f1f52727d1571bb1a4dfd to your computer and use it in GitHub Desktop.
Save blackawa/aeb54968033f1f52727d1571bb1a4dfd to your computer and use it in GitHub Desktop.
postgresql事始め

How to install

Install and run postgres:

brew install postgresql
initdb /usr/local/var/postgres -E utf8
postgres -D /usr/local/var/postgres
# keep this console open

Show database list:

psql -l # show database list

Add below line to .bashrc to configure default cluster:

export PGDATA=/usr/local/var/postgres

Create user

Show user list:

psql -q -c'select * from pg_user' postgres

Create user:

createuser ${user_name_you_want} -P
Enter password for new role: # type password
Enter it again: # again

Create database

Create database:

createdb ${database_name_you_want} -O ${user_name_you_want}
psql -l # check that you got a new database

Change privileges:

psql -q -c'select * from pg_user' rails_dev # check privilege
psql ${database_name_you_want} # login
alter role ${user_name_you_want} with superuser;
psql -q -c'select * from pg_user' rails_dev # check privilege again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment