Last active
December 19, 2015 04:28
-
-
Save sseletskyy/5897110 to your computer and use it in GitHub Desktop.
Install postgresql on Mountain Lion
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
Install postgresql on Mountain Lion | |
https://gist.github.com/demimismo/3359506 | |
> brew install postgresql | |
> initdb /usr/local/var/postgres -E utf8 | |
> mkdir -p ~/Library/LaunchAgents | |
> cp /usr/local/Cellar/postgresql/9.2.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/ | |
> launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist | |
To start postgres manually | |
> pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start | |
Stop manually: | |
> pg_ctl -D /usr/local/var/postgres stop -s -m fast | |
Check whether postgres is working | |
> ps -ef | grep postgres | |
To check db log | |
> tail -f /usr/local/var/postgres/server.log | |
Create aliases | |
alias pg-start='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start' | |
alias pg-stop='pg_ctl -D /usr/local/var/postgres stop -s -m fast' | |
To fix Mountain Lion’s genius behaviour to have postgres open a socket in /var/pgsql_socket_alt, which nobody looks at. | |
> sudo mkdir /var/pgsql_socket | |
> sudo chown $USER /var/pgsql_socket | |
Edit /usr/local/var/postgres/postgresql.conf and uncomment + edit the unix_socket_directory key to: | |
unix_socket_directory = '/var/pgsql_socket' | |
> sudo vim /usr/local/var/postgres/postgresql.conf | |
As alternative use http://postgresapp.com/ | |
This article helped to configure access from Rails | |
http://whatcodecraves.com/articles/2008/02/05/setup-rails-with-postgresql | |
Execute postgres console | |
> psql template1 | |
In psql console template1=# | |
> create role trackonrails with createdb login password 'trackonrails'; | |
Make existed role a superuser | |
> ALTER USER trackonrails WITH SUPERUSER; | |
Change password | |
> ALTER USER trackonrails WITH password ''; | |
Grant user to create db | |
> alter user trackonrails CREATEDB; | |
> select * from pg_user; | |
usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valuntil | useconfig | |
--------------+----------+-------------+----------+-----------+---------+----------+----------+----------- | |
gustotune | 10 | t | t | t | t | ******** | | | |
trackonrails | 16385 | t | f | f | f | ******** | | | |
(2 rows) | |
> select * from pg_shadow; | |
usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valuntil | useconfig | |
--------------+----------+-------------+----------+-----------+---------+-------------------------------------+----------+----------- | |
gustotune | 10 | t | t | t | t | | | | |
trackonrails | 16385 | t | f | f | f | md5462c28c2212478cab8934909cc0645b4 | | | |
(2 rows) | |
> create database trackonrails_development owner trackonrails; | |
CREATE DATABASE | |
> create database trackonrails_test owner trackonrails; | |
CREATE DATABASE | |
> create database trackonrails_production owner trackonrails; | |
CREATE DATABASE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment