Get Up and Running Quickly with PostgreSQL
I like PostgreSQL, it is everything a relational database should be -- light, very capable, and easy to setup and configure. MySQL has been the darling of open source relational databases and I think PostgreSQL has been left undeservingly in its shadow. And I'm saying undeservingly because Postgres is simply a more capable database than MySQL. Well, I guess that is yet another proof that better technology doesn't always win. Anyway, I'm a fan of Postgres and I'm quite glad that Sun has started bundling PostgreSQL with Solaris and even started providing commercial support for this great database product. So if you've got Solaris 10 U2 or later, getting your feet wet with Postgres has never been easier - all of the required binaries and libraries has already been installed for you. All you have to do to start using the database are just a few simple steps:
1. Well, PostgreSQL will not run as a root user, so you will have to create a dedicated group and a user:
# groupadd postgres2. Having created the Postgres user you can initialize the database. The default directory for the database files is /var/lib/pgsql/data, but you can set it to any other directory by providing the appropriate value to the -D parameter:
# useradd -g postgres -d /export/home/postgres -m postgres
# chown -R postgres:postgres /var/lib/pgsql
# chmod -R 700 /var/lib/pgsql
# su - postgres3. That's it, you're ready to start the database and dive directly into using the neat features of PostgreSQL:
$ initdb -D /var/lib/pgsql/data
$ pg_ctl -D /var/lib/pgsql/data -l /var/lib/pgsql/postgres.log startDone!
As the postgres user and therefore the owner of the database you can create additional users, which in turn can create databases of their own:
$ createuser -U pgsql joeNow the new database user joe can create a database of his own and start using it:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE
$
$ createdb -U joe mydbNow login and use the shiny new database:
CREATE DATABASE
$
$ psql -U joe mydb
Welcome to psql 8.1.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
mydb=>
