📄 installation.sgml
字号:
repeat this test at any later time by issuing the same command. </para> </step> <step id="install"> <title>Installing The Files</title> <note> <para> If you are upgrading an existing system and are going to install the new files over the old ones, be sure to back up your data and shut down the old server before proceeding, as explained in <xref linkend="install-upgrading"> above. </para> </note> <para> To install <productname>PostgreSQL</> enter<screen><userinput>gmake install</userinput></screen> This will install files into the directories that were specified in <xref linkend="configure">. Make sure that you have appropriate permissions to write into that area. Normally you need to do this step as root. Alternatively, you could create the target directories in advance and arrange for appropriate permissions to be granted. </para> <para> You can use <literal>gmake install-strip</literal> instead of <literal>gmake install</literal> to strip the executable files and libraries as they are installed. This will save some space. If you built with debugging support, stripping will effectively remove the debugging support, so it should only be done if debugging is no longer needed. <literal>install-strip</literal> tries to do a reasonable job saving space, but it does not have perfect knowledge of how to strip every unneeded byte from an executable file, so if you want to save all the disk space you possibly can, you will have to do manual work. </para> <para> The standard installation provides all the header files needed for client application development as well as for server-side program development, such as custom functions or data types written in C. (Prior to <productname>PostgreSQL</> 8.0, a separate <literal>gmake install-all-headers</> command was needed for the latter, but this step has been folded into the standard install.) </para> <formalpara> <title>Client-only installation:</title> <para> If you want to install only the client applications and interface libraries, then you can use these commands:<screen><userinput>gmake -C src/bin install</><userinput>gmake -C src/include install</><userinput>gmake -C src/interfaces install</><userinput>gmake -C doc install</></screen> </para> </formalpara> </step> </procedure> <formalpara> <title>Registering <application>eventlog</> on <systemitem class="osname">Windows</>:</title> <para> To register a <systemitem class="osname">Windows</> <application>eventlog</> library with the operating system, issue this command after installation:<screen><userinput>regsvr32 <replaceable>pgsql_library_directory</>/pgevent.dll</></screen> This creates registry entries used by the event viewer. </para> </formalpara> <formalpara> <title>Uninstallation:</title> <para> To undo the installation use the command <command>gmake uninstall</>. However, this will not remove any created directories. </para> </formalpara> <formalpara> <title>Cleaning:</title> <para> After the installation you can make room by removing the built files from the source tree with the command <command>gmake clean</>. This will preserve the files made by the <command>configure</command> program, so that you can rebuild everything with <command>gmake</> later on. To reset the source tree to the state in which it was distributed, use <command>gmake distclean</>. If you are going to build for several platforms within the same source tree you must do this and re-configure for each build. (Alternatively, use a separate build tree for each platform, so that the source tree remains unmodified.) </para> </formalpara> <para> If you perform a build and then discover that your <command>configure</> options were wrong, or if you change anything that <command>configure</> investigates (for example, software upgrades), then it's a good idea to do <command>gmake distclean</> before reconfiguring and rebuilding. Without this, your changes in configuration choices may not propagate everywhere they need to. </para> </sect1> <sect1 id="install-post"> <title>Post-Installation Setup</title> <sect2> <title>Shared Libraries</title> <indexterm> <primary>shared library</primary> </indexterm> <para> On some systems that have shared libraries (which most systems do) you need to tell your system how to find the newly installed shared libraries. The systems on which this is <emphasis>not</emphasis> necessary include <systemitem class="osname">BSD/OS</>, <systemitem class="osname">FreeBSD</>, <systemitem class="osname">HP-UX</>, <systemitem class="osname">IRIX</>, <systemitem class="osname">Linux</>, <systemitem class="osname">NetBSD</>, <systemitem class="osname">OpenBSD</>, <systemitem class="osname">Tru64 UNIX</> (formerly <systemitem class="osname">Digital UNIX</>), and <systemitem class="osname">Solaris</>. </para> <para> The method to set the shared library search path varies between platforms, but the most widely usable method is to set the environment variable <envar>LD_LIBRARY_PATH</> like so: In Bourne shells (<command>sh</>, <command>ksh</>, <command>bash</>, <command>zsh</>)<programlisting>LD_LIBRARY_PATH=/usr/local/pgsql/libexport LD_LIBRARY_PATH</programlisting> or in <command>csh</> or <command>tcsh</><programlisting>setenv LD_LIBRARY_PATH /usr/local/pgsql/lib</programlisting> Replace <literal>/usr/local/pgsql/lib</> with whatever you set <option><literal>--libdir</></> to in <xref linkend="configure">. You should put these commands into a shell start-up file such as <filename>/etc/profile</> or <filename>~/.bash_profile</>. Some good information about the caveats associated with this method can be found at <ulink url="http://www.visi.com/~barr/ldpath.html"></ulink>. </para> <para> On some systems it might be preferable to set the environment variable <envar>LD_RUN_PATH</envar> <emphasis>before</emphasis> building. </para> <para> On <systemitem class="osname">Cygwin</systemitem>, put the library directory in the <envar>PATH</envar> or move the <filename>.dll</filename> files into the <filename>bin</filename> directory. </para> <para> If in doubt, refer to the manual pages of your system (perhaps <command>ld.so</command> or <command>rld</command>). If you later on get a message like<screen>psql: error in loading shared librarieslibpq.so.2.1: cannot open shared object file: No such file or directory</screen> then this step was necessary. Simply take care of it then. </para> <para> <indexterm> <primary>ldconfig</primary> </indexterm> If you are on <systemitem class="osname">BSD/OS</>, <systemitem class="osname">Linux</>, or <systemitem class="osname">SunOS 4</> and you have root access you can run<programlisting>/sbin/ldconfig /usr/local/pgsql/lib</programlisting> (or equivalent directory) after installation to enable the run-time linker to find the shared libraries faster. Refer to the manual page of <command>ldconfig</> for more information. On <systemitem class="osname">FreeBSD</>, <systemitem class="osname">NetBSD</>, and <systemitem class="osname">OpenBSD</> the command is<programlisting>/sbin/ldconfig -m /usr/local/pgsql/lib</programlisting> instead. Other systems are not known to have an equivalent command. </para> </sect2> <sect2> <title>Environment Variables</title> <indexterm> <primary><envar>PATH</envar></primary> </indexterm> <para> If you installed into <filename>/usr/local/pgsql</> or some other location that is not searched for programs by default, you should add <filename>/usr/local/pgsql/bin</> (or whatever you set <option><literal>--bindir</></> to in <xref linkend="configure">) into your <envar>PATH</>. Strictly speaking, this is not necessary, but it will make the use of <productname>PostgreSQL</> much more convenient. </para> <para> To do this, add the following to your shell start-up file, such as <filename>~/.bash_profile</> (or <filename>/etc/profile</>, if you want it to affect every user):<programlisting>PATH=/usr/local/pgsql/bin:$PATHexport PATH</programlisting> If you are using <command>csh</> or <command>tcsh</>, then use this command:<programlisting>set path = ( /usr/local/pgsql/bin $path )</programlisting> </para> <para> <indexterm> <primary><envar>MANPATH</envar></primary> </indexterm> To enable your system to find the <application>man</> documentation, you need to add lines like the following to a shell start-up file unless you installed into a location that is searched by default.<programlisting>MANPATH=/usr/local/pgsql/man:$MANPATHexport MANPATH</programlisting> </para> <para> The environment variables <envar>PGHOST</> and <envar>PGPORT</> specify to client applications the host and port of the database server, overriding the compiled-in defaults. If you are going to run client applications remotely then it is convenient if every user that plans to use the database sets <envar>PGHOST</>. This is not required, however: the settings can be communicated via command line options to most client programs. </para> </sect2> </sect1><![%standalone-include;[ <sect1 id="install-getting-started"> <title>Getting Started</title> <para> The following is a quick summary of how to get <productname>PostgreSQL</> up and running once installed. The main documentation contains more information. </para> <procedure> <step> <para> Create a user account for the <productname>PostgreSQL</> server. This is the user the server will run as. For production use you should create a separate, unprivileged account (<quote>postgres</> is commonly used). If you do not have root access or just want to play around, your own user account is enough, but running the server as root is a security risk and will not work.<screen><userinput>adduser postgres</></screen> </para> </step> <step> <para> Create a database installation with the <command>initdb</> command. To run <command>initdb</> you must be logged in to your <productname>PostgreSQL</> server account. It will not work as root.<screen>root# <userinput>mkdir /usr/local/pgsql/data</>root# <userinput>chown postgres /usr/local/pgsql/data</>root# <userinput>su - postgres</>postgres$ <userinput>/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data</></screen> </para> <para> The <option>-D</> option specifies the location where the data will be stored. You can use any path you want, it does not have to be under the installation directory. Just make sure that the server account can write to the directory (or create it, if it doesn't already exist) before starting <command>initdb</>, as illustrated here. </para> </step> <step> <para> The previous step should have told you how to start up the database server. Do so now. The command should look something like<programlisting>/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data</programlisting> This will start the server in the foreground. To put the server in the background use something like<programlisting>nohup /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data \ </dev/null >>server.log 2>&1 </dev/null &</programlisting> </para> <para> To stop a server running in the background you can type<programlisting>kill `cat /usr/local/pgsql/data/postmaster.pid`</programlisting> </para> <para> In order to allow TCP/IP connections (rather than only Unix domain socket ones) you need to pass the <option>-i</> option to <filename>postmaster</>. </para> </step> <step> <para> Create a database:<screen><userinput>createdb testdb</>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -