File:  [NetBSD Developer Wiki] / wikisrc / pkgsrc / how_to_install_a_postgresql_server.mdwn
Revision 1.4: download - view: text, annotated - select for diffs
Mon Jul 4 05:35:17 2016 UTC (7 years, 5 months ago) by maya
Branches: MAIN
CVS tags: HEAD
Point to an active mirror, suggest a newer version.

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=$(uname -m)/$(uname -r)/All/ 

or if you are using csh: 
    # setenv PKG_PATH$(uname -m)/$(uname -r)/All/ 

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

#   Installing the PostgreSQL Server 
    # pkg_add -v postgresql92-server

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, e.g. for PHP 7.0 use:
    # pkg_add -v php70-pgsql

Have fun. 

#   Additional Information 

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

CVSweb for NetBSD wikisrc <> software: FreeBSD-CVSweb