[greg:local] brew install postgresql
==> Downloading ftp://ftp.ossp.org/pkg/lib/uuid/uuid-1.6.2.tar.gz
######################################################################## 100.0%
. . . <<many lines logged from the install process>>
Success. You can now start the database server using:
postgres -D /usr/local/var/pg_data
or
pg_ctl -D /usr/local/var/pg_data -l logfile start
[greg:local] pg_ctl -D /usr/local/var/pg_data -l /tmp/logfile start
[greg:local] createdb test
[greg:local] psql test
psql (9.0.3)
Type "help" for help.
test=# CREATE TABLE authors (id INT PRIMARY KEY, name VARCHAR);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "authors_pkey" for table "authors"
CREATE TABLE
test=# CREATE TABLE books (id INT PRIMARY KEY, title VARCHAR, pages INT);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "book_pkey" for table "book"
CREATE TABLE
test=# CREATE TABLE booksauthors (book_id INT, author_id INT);
CREATE TABLE
test=# INSERT INTO authors VALUES (1, 'Craig Walls');
INSERT 0 1
test=# INSERT INTO authors VALUES (2, 'Ryan Breidenbach');
INSERT 0 1
test=# CREATE TABLE booksauthors (book_id INT REFERENCES books(id), author_id INT REFERENCES authors(id));
CREATE TABLE
test=# INSERT INTO booksauthors VALUES (1,1), (1,2);
INSERT 0 2
test=# SELECT books.title, authors.name FROM books JOIN booksauthors ON books.id = booksauthors.book_id
JOIN authors ON authors.id = booksauthors.author_id;
title | name
------------------+------------------
Spring in Action | Craig Walls
Spring in Action | Ryan Breidenbach
(2 rows)
test=#
\q
[greg:rails] rails new rails_and_pg --database postgresql
[greg:rails] cd rails_and_pg
[greg:rails_and_pg] mate .
[greg:rails_and_pg] bundle install
[greg:rails_and_pg] rake db:create:all
Starting and stopping Postgresql can be accomplished with these scripts:
[greg:rails_and_pg] sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist Password: org.postgresql.postgres: Already loaded [greg:rails_and_pg] sudo launchctl unload /Library/LaunchDaemons/org.postgresql.postgres.plist
Then, to start PostGIS:
psql -d postgres -U postgres