OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / doc / postgresql / html / creating-cluster.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Creating a Database Cluster</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
9 REV="MADE"
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
11 REL="HOME"
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
14 REL="UP"
15 TITLE="Server Run-time Environment"
16 HREF="runtime.html"><LINK
17 REL="PREVIOUS"
18 TITLE="Server Run-time Environment"
19 HREF="runtime.html"><LINK
20 REL="NEXT"
21 TITLE="Starting the Database Server"
22 HREF="postmaster-start.html"><LINK
23 REL="STYLESHEET"
24 TYPE="text/css"
25 HREF="stylesheet.css"><META
26 NAME="creation"
27 CONTENT="2003-12-22T03:48:47"></HEAD
28 ><BODY
29 CLASS="SECT1"
30 ><DIV
31 CLASS="NAVHEADER"
32 ><TABLE
33 SUMMARY="Header navigation table"
34 WIDTH="100%"
35 BORDER="0"
36 CELLPADDING="0"
37 CELLSPACING="0"
38 ><TR
39 ><TH
40 COLSPAN="5"
41 ALIGN="center"
42 VALIGN="bottom"
43 >PostgreSQL 7.4.1 Documentation</TH
44 ></TR
45 ><TR
46 ><TD
47 WIDTH="10%"
48 ALIGN="left"
49 VALIGN="top"
50 ><A
51 HREF="runtime.html"
52 ACCESSKEY="P"
53 >Prev</A
54 ></TD
55 ><TD
56 WIDTH="10%"
57 ALIGN="left"
58 VALIGN="top"
59 ><A
60 HREF="runtime.html"
61 >Fast Backward</A
62 ></TD
63 ><TD
64 WIDTH="60%"
65 ALIGN="center"
66 VALIGN="bottom"
67 >Chapter 16. Server Run-time Environment</TD
68 ><TD
69 WIDTH="10%"
70 ALIGN="right"
71 VALIGN="top"
72 ><A
73 HREF="runtime.html"
74 >Fast Forward</A
75 ></TD
76 ><TD
77 WIDTH="10%"
78 ALIGN="right"
79 VALIGN="top"
80 ><A
81 HREF="postmaster-start.html"
82 ACCESSKEY="N"
83 >Next</A
84 ></TD
85 ></TR
86 ></TABLE
87 ><HR
88 ALIGN="LEFT"
89 WIDTH="100%"></DIV
90 ><DIV
91 CLASS="SECT1"
92 ><H1
93 CLASS="SECT1"
94 ><A
95 NAME="CREATING-CLUSTER"
96 >16.2. Creating a Database Cluster</A
97 ></H1
98 ><A
99 NAME="AEN15177"
100 ></A
101 ><A
102 NAME="AEN15179"
103 ></A
104 ><P
105 >   Before you can do anything, you must initialize a database storage
106    area on disk. We call this a <I
107 CLASS="FIRSTTERM"
108 >database cluster</I
109 >.
110    (<ACRONYM
111 CLASS="ACRONYM"
112 >SQL</ACRONYM
113 > uses the term catalog cluster instead.) A
114    database cluster is a collection of databases is accessible by a
115    single instance of a running database server. After initialization, a
116    database cluster will contain a database named
117    <TT
118 CLASS="LITERAL"
119 >template1</TT
120 >. As the name suggests, this will be used
121    as a template for subsequently created databases; it should not be
122    used for actual work.  (See <A
123 HREF="managing-databases.html"
124 >Chapter 18</A
125 > for information
126    about creating databases.)
127   </P
128 ><P
129 >   In file system terms, a database cluster will be a single directory
130    under which all data will be stored. We call this the <I
131 CLASS="FIRSTTERM"
132 >data
133    directory</I
134 > or <I
135 CLASS="FIRSTTERM"
136 >data area</I
137 >. It is
138    completely up to you where you choose to store your data.  There is no
139    default, although locations such as
140    <TT
141 CLASS="FILENAME"
142 >/usr/local/pgsql/data</TT
143 > or
144    <TT
145 CLASS="FILENAME"
146 >/var/lib/pgsql/data</TT
147 > are popular. To initialize a
148    database cluster, use the command <TT
149 CLASS="COMMAND"
150 >initdb</TT
151 >,<A
152 NAME="AEN15193"
153 ></A
154 > which is
155    installed with <SPAN
156 CLASS="PRODUCTNAME"
157 >PostgreSQL</SPAN
158 >. The desired
159    file system location of your database system is indicated by the
160    <VAR
161 CLASS="OPTION"
162 >-D</VAR
163 > option, for example
164 </P><PRE
165 CLASS="SCREEN"
166 ><SAMP
167 CLASS="PROMPT"
168 >$</SAMP
169 > <KBD
170 CLASS="USERINPUT"
171 >initdb -D /usr/local/pgsql/data</KBD
172 ></PRE
173 ><P>
174    Note that you must execute this command while logged into the
175    <SPAN
176 CLASS="PRODUCTNAME"
177 >PostgreSQL</SPAN
178 > user account, which is
179    described in the previous section.
180   </P
181 ><DIV
182 CLASS="TIP"
183 ><BLOCKQUOTE
184 CLASS="TIP"
185 ><P
186 ><B
187 >Tip: </B
188 >    As an alternative to the <VAR
189 CLASS="OPTION"
190 >-D</VAR
191 > option, you can set
192     the environment variable <TT
193 CLASS="ENVAR"
194 >PGDATA</TT
195 >.
196     <A
197 NAME="AEN15205"
198 ></A
199 >
200    </P
201 ></BLOCKQUOTE
202 ></DIV
203 ><P
204 >   <TT
205 CLASS="COMMAND"
206 >initdb</TT
207 > will attempt to create the directory you
208    specify if it does not already exist. It is likely that it will not
209    have the permission to do so (if you followed our advice and created
210    an unprivileged account). In that case you should create the
211    directory yourself (as root) and change the owner to be the
212    <SPAN
213 CLASS="PRODUCTNAME"
214 >PostgreSQL</SPAN
215 > user. Here is how this might
216    be done:
217 </P><PRE
218 CLASS="SCREEN"
219 >root# <KBD
220 CLASS="USERINPUT"
221 >mkdir /usr/local/pgsql/data</KBD
222 >
223 root# <KBD
224 CLASS="USERINPUT"
225 >chown postgres /usr/local/pgsql/data</KBD
226 >
227 root# <KBD
228 CLASS="USERINPUT"
229 >su postgres</KBD
230 >
231 postgres$ <KBD
232 CLASS="USERINPUT"
233 >initdb -D /usr/local/pgsql/data</KBD
234 ></PRE
235 ><P>
236   </P
237 ><P
238 >   <TT
239 CLASS="COMMAND"
240 >initdb</TT
241 > will refuse to run if the data directory
242    looks like it it has already been initialized.</P
243 ><P
244 >   Because the data directory contains all the data stored in the
245    database, it is essential that it be secured from unauthorized
246    access. <TT
247 CLASS="COMMAND"
248 >initdb</TT
249 > therefore revokes access
250    permissions from everyone but the
251    <SPAN
252 CLASS="PRODUCTNAME"
253 >PostgreSQL</SPAN
254 > user.
255   </P
256 ><P
257 >   However, while the directory contents are secure, the default
258    client authentication setup allows any local user to connect to the
259    database and even become the database superuser. If you do not
260    trust other local users, we recommend you use
261    <TT
262 CLASS="COMMAND"
263 >initdb</TT
264 >'s <VAR
265 CLASS="OPTION"
266 >-W</VAR
267 > or
268    <VAR
269 CLASS="OPTION"
270 >--pwprompt</VAR
271 > option to assign a password to the
272    database superuser.<A
273 NAME="AEN15225"
274 ></A
275 > After <TT
276 CLASS="COMMAND"
277 >initdb</TT
278 >, modify
279    the <TT
280 CLASS="FILENAME"
281 >pg_hba.conf</TT
282 > file to use <TT
283 CLASS="LITERAL"
284 >md5</TT
285 > or
286    <TT
287 CLASS="LITERAL"
288 >password</TT
289 > instead of <TT
290 CLASS="LITERAL"
291 >trust</TT
292 > authentication
293    <SPAN
294 CLASS="emphasis"
295 ><I
296 CLASS="EMPHASIS"
297 >before</I
298 ></SPAN
299 > you start the server for the first time. (Other
300    approaches include using <TT
301 CLASS="LITERAL"
302 >ident</TT
303 > authentication or
304    file system permissions to restrict connections. See <A
305 HREF="client-authentication.html"
306 >Chapter 19</A
307 > for more information.)
308   </P
309 ><P
310 >   <TT
311 CLASS="COMMAND"
312 >initdb</TT
313 > also initializes the default
314    locale<A
315 NAME="AEN15238"
316 ></A
317 > for the database cluster.
318    Normally, it will just take the locale settings in the environment
319    and apply them to the initialized database.  It is possible to
320    specify a different locale for the database; more information about
321    that can be found in <A
322 HREF="charset.html#LOCALE"
323 >Section 20.1</A
324 >.  The sort order used
325    within a particular database cluster is set by
326    <TT
327 CLASS="COMMAND"
328 >initdb</TT
329 > and cannot be changed later, short of
330    dumping all data, rerunning <TT
331 CLASS="COMMAND"
332 >initdb</TT
333 >, and
334    reloading the data. So it's important to make this choice correctly
335    the first time.
336   </P
337 ></DIV
338 ><DIV
339 CLASS="NAVFOOTER"
340 ><HR
341 ALIGN="LEFT"
342 WIDTH="100%"><TABLE
343 SUMMARY="Footer navigation table"
344 WIDTH="100%"
345 BORDER="0"
346 CELLPADDING="0"
347 CELLSPACING="0"
348 ><TR
349 ><TD
350 WIDTH="33%"
351 ALIGN="left"
352 VALIGN="top"
353 ><A
354 HREF="runtime.html"
355 ACCESSKEY="P"
356 >Prev</A
357 ></TD
358 ><TD
359 WIDTH="34%"
360 ALIGN="center"
361 VALIGN="top"
362 ><A
363 HREF="index.html"
364 ACCESSKEY="H"
365 >Home</A
366 ></TD
367 ><TD
368 WIDTH="33%"
369 ALIGN="right"
370 VALIGN="top"
371 ><A
372 HREF="postmaster-start.html"
373 ACCESSKEY="N"
374 >Next</A
375 ></TD
376 ></TR
377 ><TR
378 ><TD
379 WIDTH="33%"
380 ALIGN="left"
381 VALIGN="top"
382 >Server Run-time Environment</TD
383 ><TD
384 WIDTH="34%"
385 ALIGN="center"
386 VALIGN="top"
387 ><A
388 HREF="runtime.html"
389 ACCESSKEY="U"
390 >Up</A
391 ></TD
392 ><TD
393 WIDTH="33%"
394 ALIGN="right"
395 VALIGN="top"
396 >Starting the Database Server</TD
397 ></TR
398 ></TABLE
399 ></DIV
400 ></BODY
401 ></HTML
402 >