pavement

PostgreSQL

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (categorized)
m (Extrain database creation)
Line 38: Line 38:
 
* The '''CREATE DATABASE''' query.
 
* The '''CREATE DATABASE''' query.
  
I will explain this latter .... --[[User:Smortex|Smortex]] 02:16, 18 Jul 2005 (EDT)
+
For example, let's create the ''foo'' database :
 +
 
 +
shell> '''psql template1 pgsql'''
 +
Password:
 +
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 ;'''
 +
CREATE DATABASE
 +
template1=#
 +
 
 +
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===
 
===Creating users===

Revision as of 03:10, 3 August 2005

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.

Contents

Installation

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

/usr/ports/databases/postgresql80-client
/usr/ports/databases/postgresql80-server

... 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 :

/usr/ports/databases/php4-pgsql
# or
/usr/ports/databases/php5-pgsql

(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 :

postgresql_enable="YES"

Then, run :

/usr/local/etc/rc.d/010.pgsql.sh initdb

If everything is good, you can now start PostgreSQL :

/usr/local/etc/rc.d/010.pgsql.sh 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
Password: 
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 ;
CREATE DATABASE
template1=#

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

http://www.postgresql.org

Personal tools