File:  [NetBSD Developer Wiki] / wikisrc / pkgsrc / how_to_install_a_postgresql_server.mdwn
Revision 1.3: download - view: text, annotated - select for diffs
Fri Oct 25 17:37:20 2013 UTC (23 months, 1 week ago) by wiki
Branches: MAIN
CVS tags: HEAD
web commit by mspo: typo fixes from Terho Uotila

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 database cluster other place than the default location, just change the user **pgsql'**s home directory, before proceeding to the initialisation: 
    # usermod -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 
    # createdb -e -h -U pgsql newdbname

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