MAC 和 Postgresql 第二篇

非常有用的相关资料

UPDATE(05/06/2013):
still works fine for MAC

modify
/usr/local/var/postgres/postgresql.conf
get localhost works

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log restart

还是说brew安装,之前之后的事

1. 用brew安装postgresql,很忌讳rvm的gcc,要用xcode的command line

2. brew装完要设置路径,就是local那个不然,就会莫名其妙的错误,总用系统的postgresql

PATH=/usr/local/bin:$PATH:$HOME/.rvm/bin # Add Brew and RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm"  ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM  Kens-MacBook-Pro:reptile_nai


重新安装攻略

brew rm postgresql --force

sudo /sbin/SystemStarter stop postgresql-8.4
sudo rm -rf /Applications/PostgreSQL\ 8.4
sudo rm -rf /etc/postgres-reg.ini
sudo rm -rf /Library/StartupItems/postgresql-8.4
sudo rm -rf /Library/PostgreSQL/8.4
sudo dscl . delete /users/postgres

nano /etc/profile

brew update
brew install postgresql

initdb /usr/local/var/postgres
cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

gem install pg



psql -U postgres -h localhost#9.2有一个默认的数据库用户就是,当前系统用户。不注意的话就会很讨厌
grant all privileges on database postgres to postgres;
alter user livegamer with superuser;
\du
alter user livegamer with encrypted password 'livegamer';


brew install postres
initdb /usr/local/var/postgres
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
If you need a gem for posgres do:
env ARCHFLAGS="-arch x86_64" gem install pg
Install Instrumentation, in my case (postgres version 9.0.4):
psql -d postgres < /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql
At this moment, you installed postgress (it’s only a note). Ok, let’s create a new role:
psql -d postgres
With this command, you’ll see all roles created:
postgres-# \du
We create a new user called postgres like this way:
postgres=# CREATE ROLE postgres SUPERUSER CREATEDB CREATEROLE LOGIN;
And that’s all. If you list all users again you’ll see that a new user has been created.



参考:
http://raulbarroso.com/post/8656188824/installing-postgres-with-brew-in-macosx
http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

猜你喜欢

转载自hlee.iteye.com/blog/1699119