Friday, August 17, 2007

PostgreSQL on Mac OS

MySQL suddenly stopped working and I was not able to run it. I got frustrated with MySQL error messages like no /tmp/mysql.sock found and -bash: /usr/local/mysql/bin/mysql: Bad CPU type in executable

22:04:59:/usr/local/src > mkdir postgres
22:05:24:/usr/local/src > cd postgres/
22:05:27:/usr/local/src/postgres > ls -l
22:05:29:/usr/local/src/postgres > curl -O ftp://ftp5.us.postgresql.org/pub/PostgreSQL/source/v8.2.4/postgresql-8.2.4.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14.8M 100 14.8M 0 0 48521 0 0:05:21 0:05:21 --:--:-- 77126
22:12:19:/usr/local/src/postgres > tar -xzvf postgresql-8.2.4.tar.gz
postgresql-8.2.4

22:31:26:/usr/local/src/postgres > cd postgresql-8.2.4
22:31:30:/usr/local/src/postgres/postgresql-8.2.4 > ./configure --with-includes=/sw/include/ --with-libraries=/sw/lib
checking build system type... powerpc-apple-darwin8.10.0

22:33:12:/usr/local/src/postgres/postgresql-8.2.4 > make
22:41:07:/usr/local/src/postgres/postgresql-8.2.4 > sudo make install
23:25:46:/usr/local/src/postgres/postgresql-8.2.4 > /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

23:29:07:/usr/local/src/postgres/postgresql-8.2.4 > /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
LOG: database system was shut down at 2007-08-16 23:26:25 PDT
LOG: checkpoint record is at 0/42BEB8
LOG: redo record is at 0/42BEB8; undo record is at 0/0; shutdown TRUE
LOG: next transaction ID: 0/593; next OID: 10820
LOG: next MultiXactId: 1; next MultiXactOffset: 0
LOG: database system is ready

23:35:06:~ > /usr/local/pgsql/bin/createdb
CREATE DATABASE
23:35:33:~ > /usr/local/pgsql/bin/createdb mytestdb
CREATE DATABASE
23:35:45:~ > /usr/local/pgsql/bin/psql mytestdb
Welcome to psql 8.2.4, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

mytestdb=# create table foo(name varchar primary key, foo_id serial);
NOTICE: CREATE TABLE will create implicit sequence "foo_foo_id_seq" for serial column "foo.foo_id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
CREATE TABLE
mytestdb=# insert into foo(name) values ('Liz');
INSERT 0 1
mytestdb=# insert into foo(name) values ('Bunny');
INSERT 0 1
mytestdb=# select * from foo;
name | foo_id
-------+--------
Liz | 1
Bunny | 2
(2 rows)

No comments:

Post a Comment