File:  [NetBSD Developer Wiki] / wikisrc / pkgsrc / how_to_install_a_postgresql_server.mdwn
Revision 1.1: download - view: text, annotated - select for diffs
Sun Nov 20 20:28:27 2011 UTC (12 years ago) by mspo
Branches: MAIN
CVS tags: HEAD
import a bunch of pkgsrc articles from the old wiki

Installing a PostgreSQL Server under NetBSD is pretty easy. The recommended way is to install the prebuilt postgresql binaries. The PostgreSQL Server depends on the postgreSQL Client. 


[[!toc levels=3]]

#   Setting PKG_PATH 

Setting PKG_PATH enables us to easily download and install packages and it's dependencies. 
    # export PKG_PATH=

or if you are using csh: 
    # setenv PKG_PATH

You should keep this in your .profile, .bash_profile, if you mainly using binaries. 

#   Installing the PostgreSQL Server 
    # pkg_add -v postgresql80-server-8.0.4.tgz

This will install the postgresql client and the server and any missing dependency (readline, perl) and will add the user **pgsql** to your user database. 

That's it. Almost. 

#   Configuring the Server 

Please copy the pgsql example script to /etc/rc.d/ 
    # cp /usr/pkg/share/examples/rc.d/pgsql /etc/rc.d

If you want to keep the databse cluster other place than the default location, just change the user **pgsql'**s home directory, before proceeding to the initialisation: 
    # usermode -d /var/db/pgsql pgsql

This directory must be owned by pgsql:pgsql. 

and then 

#   Starting the Server 

If you want to initialise the database with a local other than "C", for example with unicode, invoke this before starting postgresql for the first time: 
    # /etc/rc.d/pgsql initdb -E unicode

please start the server entering: 
    # /etc/rc.d/pgsql start

This will create all necessary initial databases on the first start. 

#   Start on every boot 

To start the server on every boot add 

to your /etc/rc.conf 

#   Creating an example Database 

To create a database switch to the user pgsql 
    # su pgsql

and create the database 
    $ createdb testdb
    $ exit

#   Using the Database 

Postgres provides a Tool to manage the Database called **psql**. 
    # psql -U pgsql testdb
    Welcome to psql 8.0.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

#   PHP and PostgreSQL 

You may wish to install the postgres Module for PHP 
    # pkg_add -v php-pgsql-4.4.1.tgz

Have fun. 

#   Additional Information 

  * [pkg_add(1)]( Manpage 
  * [su(1)]( Manpage 

CVSweb for NetBSD wikisrc <> software: FreeBSD-CVSweb