]> granicus.if.org Git - postgresql/blob - INSTALL
Fix typo.
[postgresql] / INSTALL
1      Installation instructions for PostgreSQL 7.0.2.
2
3 If you haven't gotten the PostgreSQL distribution, get it from
4 ftp.postgresql.org, then unpack it:
5
6 > gunzip postgresql-7.0.2.tar.gz
7 > tar -xf postgresql-7.0.2.tar
8 > mv postgresql-7.0.2 /usr/src
9
10
11 Before you start
12
13 Building PostgreSQL requires GNU make. It will not work with other make
14 programs. On GNU/Linux systems GNU make is the default tool, on other
15 systems you may find that GNU make is installed under the name gmake. We
16 will use that name from now on to indicate GNU make, no matter what name it
17 has on your system. To test for GNU make enter
18
19 > gmake --version
20
21
22 If you need to get GNU make, you can find it at ftp://ftp.gnu.org.
23
24 Up to date information on supported platforms is at
25 http://www.postgresql.org/docs/admin/ports.htm. In general, most
26 Unix-compatible platforms with modern libraries should be able to run
27 PostgreSQL. In the doc subdirectory of the distribution are several
28 platform-specific FAQ and README documents you might wish to consult if you
29 are having trouble.
30
31 Although the minimum required memory for running PostgreSQL can be as little
32 as 8MB, there are noticeable speed improvements when expanding memory up to
33 96MB or beyond. The rule is you can never have too much memory.
34
35 Check that you have sufficient disk space. You will need about 30 Mbytes for
36 the source tree during compilation and about 5 Mbytes for the installation
37 directory. An empty database takes about 1 Mbyte, otherwise they take about
38 five times the amount of space that a flat text file with the same data
39 would take. If you run the regression tests you will temporarily need an
40 extra 20MB.
41
42 To check for disk space, use
43
44 > df -k
45
46 Considering today's prices for hard disks, getting a large and fast hard
47 disk should probably be in your plans before putting a database into
48 production use.
49
50
51 Installation Procedure
52
53 PostgreSQL Installation
54
55 For a fresh install or upgrading from previous releases of PostgreSQL:
56
57   1. Create the PostgreSQL superuser account. This is the user the server
58      will run as. For production use you should create a separate,
59      unprivileged account (postgres is commonly used). If you do not have
60      root access or just want to play around, your own user account is
61      enough.
62
63      Running PostgreSQL as root, bin, or any other account with special
64      access rights is a security risk; don't do it. The postmaster will in
65      fact refuse to start as root.
66
67      You need not do the building and installation itself under this account
68      (although you can). You will be told when you need to login as the
69      database superuser.
70
71   2. Configure the source code for your system. It is this step at which you
72      can specify your actual installation path for the build process and
73      make choices about what gets installed. Change into the src
74      subdirectory and type:
75
76      > ./configure
77
78
79      followed by any options you might want to give it. For a first
80      installation you should be able to do fine without any. For a complete
81      list of options, type:
82
83      > ./configure --help
84
85
86      Some of the more commonly used ones are:
87
88      --prefix=BASEDIR
89
90           Selects a different base directory for the installation of
91           PostgreSQL. The default is /usr/local/pgsql.
92
93      --enable-locale
94
95           If you want to use locales.
96
97      --enable-multibyte
98
99           Allows the use of multibyte character encodings. This is primarily
100           for languages like Japanese, Korean, or Chinese.
101
102      --with-perl
103
104           Builds the Perl interface and plperl extension language. Please
105           note that the Perl interface needs to be installed into the usual
106           place for Perl modules (typically under /usr/lib/perl), so you
107           must have root access to perform the installation step. (It is
108           often easiest to leave out --with-perl initially, and then build
109           and install the Perl interface after completing the installation
110           of PostgreSQL itself.)
111
112      --with-odbc
113
114           Builds the ODBC driver package.
115
116      --with-tcl
117
118           Builds interface libraries and programs requiring Tcl/Tk,
119           including libpgtcl, pgtclsh, and pgtksh.
120
121   3. Compile the program. Type
122
123      > gmake
124
125
126      The compilation process can take anywhere from 10 minutes to an hour.
127      Your mileage will most certainly vary. Remember to use GNU make.
128
129      The last line displayed will hopefully be
130
131      All of PostgreSQL is successfully made. Ready to install.
132
133
134   4. If you want to test the newly built server before you install it, you
135      can run the regression tests at this point. The regression tests are a
136      test suite to verify that PostgreSQL runs on your machine in the way
137      the developers expected it to. For detailed instructions see Regression
138      Test. (Be sure to use the "parallel regress test" method, since the
139      sequential method only works with an already-installed server.)
140
141   5. If you are not upgrading an existing system, skip to step 7.
142      If you are running 7.*, skip to step 6.
143
144      You now need to back up your existing database. To dump your 
145      database installation, type:
146
147      > pg_dumpall > db.out
148
149
150      If you wish to preserve object id's (oids), then use the -o option when
151      running pg_dumpall. However, unless you have a special reason for doing
152      this (such as using OIDs as keys in tables), don't do it.
153
154      Make sure to use the pg_dumpall command from the version you are
155      currently running. 7.0.2's pg_dumpall should not be used on older
156      databases.
157
158                                         Caution
159       You must make sure that your database is not updated in the middle of your
160       backup. If necessary, bring down postmaster, edit the permissions in file
161       /usr/local/pgsql/data/pg_hba.conf to allow only you on, then bring
162       postmaster back up.
163
164       Rather than using pg_dumpall, pg_upgrade can often be used.
165
166   6. If you are upgrading an existing system, kill the database server
167      now. Type
168
169      > ps ax | grep postmaster
170
171
172      or
173
174      > ps -e | grep postmaster
175
176
177      (It depends on your system which one of these two works. No harm can be
178      done by typing the wrong one.) This should list the process numbers for
179      a number of processes, similar to this:
180
181        263  ?  SW   0:00 (postmaster)
182        777  p1 S    0:00 grep postmaster
183
184
185      Type the following line, with pid replaced by the process id for
186      process postmaster (263 in the above case). (Do not use the id for the
187      process "grep postmaster".)
188
189      > kill pid
190
191
192           Tip: On systems which have PostgreSQL started at boot time,
193           there is probably a startup file that will accomplish the
194           same thing. For example, on a Redhat Linux system one might
195           find that
196
197           > /etc/rc.d/init.d/postgres.init stop
198
199
200           works.
201
202      If you used pg_dumpall, move the old directory out of the
203      way.  Type the following:
204
205      > mv /usr/local/pgsql /usr/local/pgsql.old
206
207
208      (substitute your particular paths).
209
210   7. Install the PostgreSQL executable files and libraries. Type
211
212      > gmake install
213
214
215      You should do this step as the user that you want the installed
216      executables to be owned by. This does not have to be the same as the
217      database superuser; some people prefer to have the installed files be
218      owned by root.
219
220   8. If necessary, tell your system how to find the new shared libraries.
221      How to do this varies between platforms. The most widely usable method
222      is to set the environment variable LD_LIBRARY_PATH:
223
224      > LD_LIBRARY_PATH=/usr/local/pgsql/lib
225      > export LD_LIBRARY_PATH
226
227
228      on sh, ksh, bash, zsh or
229
230      > setenv LD_LIBRARY_PATH /usr/local/pgsql/lib
231
232
233      on csh or tcsh. You might want to put this into a shell startup file
234      such as /etc/profile.
235
236      On some systems the following is the preferred method, but you must
237      have root access. Edit file /etc/ld.so.conf to add a line
238
239      /usr/local/pgsql/lib
240
241
242      Then run command /sbin/ldconfig.
243
244      If in doubt, refer to the manual pages of your system. If you later on
245      get a message like
246
247      psql: error in loading shared libraries
248      libpq.so.2.1: cannot open shared object file: No such file or directory
249
250
251      then the above was necessary. Simply do this step then.
252
253   9. If you moved the old directory out of the way, 
254      create the database installation (the working data files). To do this
255      you must log in to your PostgreSQL superuser account. It will not work
256      as root.
257
258      > mkdir /usr/local/pgsql/data
259      > chown postgres /usr/local/pgsql/data
260      > su - postgres
261      > /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
262
263
264      The -D option specifies the location where the data will be stored. You
265      can use any path you want, it does not have to be under the
266      installation directory. Just make sure that the superuser account can
267      write to the directory (or create it, if it doesn't already exist)
268      before starting initdb. (If you have already been doing the
269      installation up to now as the PostgreSQL superuser, you may have to log
270      in as root temporarily to create the data directory underneath a
271      root-owned directory.)
272
273  10. The previous step should have told you how to start up the database
274      server. Do so now. The command should look something like
275
276      > /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
277
278
279      This will start the server in the foreground. To make it detach to the
280      background, you can use the -S option, but then you won't see any log
281      messages the server produces. A better way to put the server in the
282      background is
283
284      > nohup /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data \
285          </dev/null >>server.log 2>>1 &
286
287
288  11. If you did a pg_dumpall, reload your data back in:
289
290      > /usr/local/pgsql/bin/psql -d template1 -f db.out
291
292
293      You also might want to copy over the old pg_hba.conf file and any other
294      files you might have had set up for authentication, such as password
295      files.
296
297 This concludes the installation proper. To make your life more productive
298 and enjoyable you should look at the following optional steps and
299 suggestions:
300
301    * Life will be more convenient if you set up some environment variables.
302      First of all you probably want to include /usr/local/pgsql/bin (or
303      equivalent) into your PATH. To do this, add the following to your shell
304      startup file, such as ~/.bash_profile (or /etc/profile, if you want it
305      to affect every user):
306
307      > PATH=$PATH:/usr/local/pgsql/bin
308
309
310      Furthermore, if you set PGDATA in the environment of the PostgreSQL
311      superuser, you can omit the -D for postmaster and initdb.
312
313    * You probably want to install the man and HTML documentation. Type
314
315      > cd /usr/src/pgsql/postgresql-7.0.2/doc
316      > gmake install
317
318
319      This will install files under /usr/local/pgsql/doc and
320      /usr/local/pgsql/man. To enable your system to find the man
321      documentation, you need to add a line like the following to a shell
322      startup file:
323
324      > MANPATH=$MANPATH:/usr/local/pgsql/man
325
326
327      The documentation is also available in Postscript format. If you have a
328      Postscript printer, or have your machine already set up to accept
329      Postscript files using a print filter, then to print the User's Guide
330      simply type
331
332      > cd /usr/local/pgsql/doc
333      > gunzip -c user.ps.tz | lpr
334
335
336      Here is how you might do it if you have Ghostscript on your system and
337      are writing to a laserjet printer.
338
339      > gunzip -c user.ps.gz \
340          | gs -sDEVICE=laserjet -r300 -q -dNOPAUSE -sOutputFile=- \
341          | lpr
342
343
344      Printer setups can vary wildly from system to system. If in doubt,
345      consult your manuals or your local expert.
346
347      The Adminstrator's Guide should probably be your first reading if you
348      are completely new to PostgreSQL, as it contains information about how
349      to set up database users and authentication.
350
351    * Usually, you will want to modify your computer so that it will
352      automatically start the database server whenever it boots. This is not
353      required; the PostgreSQL server can be run successfully from
354      non-privileged accounts without root intervention.
355
356      Different systems have different conventions for starting up daemons at
357      boot time, so you are advised to familiarize yourself with them. Most
358      systems have a file /etc/rc.local or /etc/rc.d/rc.local which is almost
359      certainly no bad place to put such a command. Whatever you do,
360      postmaster must be run by the PostgreSQL superuser (postgres) and not
361      by root or any other user. Therefore you probably always want to form
362      your command lines along the lines of su -c '...' postgres.
363
364      It might be advisable to keep a log of the server output. To start the
365      server that way try:
366
367      > nohup su -c 'postmaster -D /usr/local/pgsql/data > server.log 2>&1' postgres &
368
369
370      Here are a few more operating system specific suggestions.
371
372         o Edit file rc.local on NetBSD or file rc2.d on SPARC Solaris 2.5.1
373           to contain the following single line:
374
375           > su postgres -c "/usr/local/pgsql/bin/postmaster -S -D /usr/local/pgsql/data"
376
377
378         o In FreeBSD 2.2-RELEASE edit /usr/local/etc/rc.d/pgsql.sh to
379           contain the following lines and make it chmod 755 and chown
380           root:bin.
381
382           #!/bin/sh
383           [ -x /usr/local/pgsql/bin/postmaster ] && {
384               su -l pgsql -c 'exec /usr/local/pgsql/bin/postmaster
385                   -D/usr/local/pgsql/data
386                   -S -o -F > /usr/local/pgsql/errlog' &
387               echo -n ' pgsql'
388           }
389
390
391           You may put the line breaks as shown above. The shell is smart
392           enough to keep parsing beyond end-of-line if there is an
393           expression unfinished. The exec saves one layer of shell under the
394           postmaster process so the parent is init.
395
396         o In RedHat Linux add a file /etc/rc.d/init.d/postgres.init which is
397           based on the example in contrib/linux/. Then make a softlink to
398           this file from /etc/rc.d/rc5.d/S98postgres.init.
399
400    * Run the regression tests against the installed server (using the
401      sequential test method). If you didn't run the tests before
402      installation, you should definitely do it now. For detailed
403      instructions see Regression Test.
404
405 To start experimenting with Postgres, set up the paths as explained above
406 and start the server. To create a database, type
407
408 > createdb testdb
409
410
411 Then enter
412
413 > psql testdb
414
415
416 to connect to that database. At the prompt you can enter SQL commands and
417 start experimenting.