1: 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.
2: [4]:
3:
4: **Contents**
5:
6: [[!toc levels=3]]
7:
8: # Setting PKG_PATH
9:
10: Setting PKG_PATH enables us to easily download and install packages and it's dependencies.
11:
12: # export PKG_PATH=https://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/$(uname -m)/$(uname -r)/All/
13:
14:
15: or if you are using csh:
16:
17: # setenv PKG_PATH https://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/$(uname -m)/$(uname -r)/All/
18:
19:
20: You should keep this in your .profile, .bash_profile, if you mainly using binaries.
21:
22: # Installing the PostgreSQL Server
23:
24: # pkg_add -v postgresql92-server
25:
26:
27: 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.
28:
29: That's it. Almost.
30:
31: # Configuring the Server
32:
33: Please copy the pgsql example script to /etc/rc.d/
34:
35: # cp /usr/pkg/share/examples/rc.d/pgsql /etc/rc.d
36:
37:
38: 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:
39:
40: # usermod -d /var/db/pgsql pgsql
41:
42:
43: This directory must be owned by pgsql:pgsql.
44:
45: and then
46:
47: # Starting the Server
48:
49: 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:
50:
51: # /etc/rc.d/pgsql initdb -E unicode
52:
53:
54: please start the server entering:
55:
56: # /etc/rc.d/pgsql start
57:
58:
59: This will create all necessary initial databases on the first start.
60:
61: # Start on every boot
62:
63: To start the server on every boot add
64:
65: pgsql=yes
66:
67:
68: to your /etc/rc.conf
69:
70: # Creating an example Database
71:
72: To create a database switch to the user pgsql
73:
74: # createdb -e -h 127.0.0.1 -U pgsql newdbname
75:
76:
77: and create the database
78:
79: $ createdb testdb
80: $ exit
81:
82:
83: # Using the Database
84:
85: Postgres provides a Tool to manage the Database called **psql**.
86:
87:
88: # psql -U pgsql testdb
89: Welcome to psql 8.0.4, the PostgreSQL interactive terminal.
90:
91: Type: \copyright for distribution terms
92: \h for help with SQL commands
93: \? for help with psql commands
94: \g or terminate with semicolon to execute query
95: \q to quit
96:
97: testdb=#
98:
99:
100: # PHP and PostgreSQL
101:
102: You may wish to install the postgres Module for PHP, e.g. for PHP 7.0 use:
103:
104: # pkg_add -v php70-pgsql
105:
106:
107: Have fun.
108:
109: # Additional Information
110:
111: * [[!template id=man name="pkg_add" section="1"]] Manpage
112: * [[!template id=man name="su" section="1"]] Manpage
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb