From FreeBSDwiki
Revision as of 03:10, 3 August 2005 by Smortex (Talk | contribs)
Jump to: navigation, search

PostgreSQL is an open source object-relationnal database management system released under the terms of the BSD licence. It is based on postgres, developped at the University of California at Berkeley Computer Science Department (Juste like BSD). It features many stuff MySQL lacks, such as transactional integrity or complex queries.



You can choose to install PostgreSQL from the port tree...


... or the packages ...

pkg_add -r postgresql80-client postgresql80-server

Additionnaly, you may want to install postgresql support to PHP. Depending on your PHP version, install :

# or

(You can also install it from packages)

Configuring PostgreSQL

Creating a cluster

What is called cluster in PostgreSQL is the database disk area. The first step is to enable PostgreSQL, witch is done in /etc/rc.conf : add the following line at the end :


Then, run :

/usr/local/etc/rc.d/ initdb

If everything is good, you can now start PostgreSQL :

/usr/local/etc/rc.d/ start

Creating databases

There are two ways to create databases :

  • The createdb command (in a shell).
  • The CREATE DATABASE query.

For example, let's create the foo database :

shell> psql template1 pgsql
Welcome to psql 8.0.3, 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

template1=# CREATE DATABASE foo ;

Note that the connection is done into the template1 database: This first database is created by the initdb command and is used to log-in a database for the creation of a new one (Problem of the first database creation).

Creating users

There are two ways to create users :

  • The createuser command (in a shell).
  • The CREATE USER query.

I will explain this latter .... --Smortex 02:16, 18 Jul 2005 (EDT)

PostgreSQL Website

Personal tools