Some refactoring of postgresql page. If you don't like it, please revert.

- avoid testing the installation in the "install" section
- move user creation at the beginning, as we do for other packages
- make jhalfs happier

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@19759 af4574ff-66df-0310-9fd7-8a98e5e911e0
This commit is contained in:
Pierre Labastie 2018-02-13 09:34:53 +00:00
parent 8b28cb4abb
commit 8753831ea3

View File

@ -87,6 +87,16 @@
<sect2 role="installation">
<title>Installation of PostgreSQL</title>
<para>
For enhanced security, it is better to have a dedicated group and user
for running the PostgreSQL server. First, issue as the
<systemitem class="username">root</systemitem> user:
</para>
<screen role="root"><userinput>groupadd -g 41 postgres &amp;&amp;
useradd -c "PostgreSQL Server" -g postgres -d /srv/pgsql/data \
-u 41 postgres</userinput></screen>
<para>Install <application>PostgreSQL</application> with the
following commands: </para>
@ -108,9 +118,9 @@ make</userinput></screen>
temporary server and this is prevented as the root user. For the same reason,
you need to stop all PostgreSQL servers if any are running. If a previous
version of PostgreSQL is installed, it may be necessary to use
<emphasis>--disable-rpath</emphasis> with <emphasis>configure</emphasis> to
avoid failures, but <command>installing the binaries created using this
switch is not recommended</command>. To test the results, issue:
<command>--disable-rpath</command> with <command>configure</command> to
avoid failures, but <emphasis>installing the binaries created using this
switch is not recommended</emphasis>. To test the results, issue:
<command>make check</command>.</para>
<para>Now, as the <systemitem class="username">root</systemitem> user:</para>
@ -142,11 +152,6 @@ make install-docs</userinput></screen>
<screen role="root"><userinput>install -v -dm700 /srv/pgsql/data &amp;&amp;
install -v -dm755 /run/postgresql &amp;&amp;
groupadd -g 41 postgres &amp;&amp;
useradd -c "PostgreSQL Server" -g postgres -d /srv/pgsql/data \
-u 41 postgres &amp;&amp;
chown -Rv postgres:postgres /srv/pgsql /run/postgresql</userinput></screen>
<para>Now, initialize the database as the <systemitem
@ -154,31 +159,6 @@ chown -Rv postgres:postgres /srv/pgsql /run/postgresql</userinput></screen>
<screen role="root"><userinput>su - postgres -c '/usr/bin/initdb -D /srv/pgsql/data'</userinput></screen>
<para>Again as the <systemitem class="username">root</systemitem> user,
start the database server with the following command:</para>
<screen role="root"><userinput>su - postgres -c '/usr/bin/postgres -D /srv/pgsql/data > \
/srv/pgsql/data/logfile 2&gt;&amp;1 &amp;'</userinput></screen>
<para>Still as user <systemitem class="username">root</systemitem>, create
a database and verify the installation:</para>
<screen role="root"><userinput>su - postgres -c '/usr/bin/createdb test' &amp;&amp;
echo "create table t1 ( name varchar(20), state_province varchar(20) );" \
| (su - postgres -c '/usr/bin/psql test ') &amp;&amp;
echo "insert into t1 values ('Billy', 'NewYork');" \
| (su - postgres -c '/usr/bin/psql test ') &amp;&amp;
echo "insert into t1 values ('Evanidus', 'Quebec');" \
| (su - postgres -c '/usr/bin/psql test ') &amp;&amp;
echo "insert into t1 values ('Jesse', 'Ontario');" \
| (su - postgres -c '/usr/bin/psql test ') &amp;&amp;
echo "select * from t1;" | (su - postgres -c '/usr/bin/psql test')</userinput></screen>
<para>To shut down the server, as <systemitem
class="username">root</systemitem>:</para>
<screen role="root"><userinput>su - postgres -c "/usr/bin/pg_ctl stop -D /srv/pgsql/data"</userinput></screen>
</sect2>
<sect2 role="commands">
@ -211,15 +191,6 @@ echo "select * from t1;" | (su - postgres -c '/usr/bin/psql test')</userinput></
<para><option>--with-tcl</option>: builds the PL/Tcl server-side language.</para>
<para><command>groupadd ...</command>; <command>useradd ...</command>:
These commands add an unprivileged user and group to run the database
server.</para>
<para><command>createdb test; create table t1; insert into t1 values...;
select * from t1</command>: Create a database, add a table to it, insert
some rows into the table and select them to verify that the installation
is working properly.</para>
</sect2>
<sect2 role="configuration">
@ -275,6 +246,51 @@ echo "select * from t1;" | (su - postgres -c '/usr/bin/psql test')</userinput></
</sect3>
<sect3>
<title>Starting the PostgreSQL Server and Creating a Sample Database</title>
<para>
The database server can be manually started with the following command
(as the <systemitem class="username">root</systemitem> user):
</para>
<screen role="root"><userinput>su - postgres -c '/usr/bin/postgres -D /srv/pgsql/data > \
/srv/pgsql/data/logfile 2&gt;&amp;1 &amp;'</userinput></screen>
<note>
<para>
If you are scripting this part, you should wait for the server to
start before going on, by adding for example
<command>sleep 2</command> after the above command.
</para>
</note>
<para>
The instructions below show how to create a database, add a table to
it, insert some rows into the table and select them, to verify that the
installation is working properly. Still as user <systemitem
class="username">root</systemitem>, issue:
</para>
<screen role="root"><userinput>su - postgres -c '/usr/bin/createdb test' &amp;&amp;
echo "create table t1 ( name varchar(20), state_province varchar(20) );" \
| (su - postgres -c '/usr/bin/psql test ') &amp;&amp;
echo "insert into t1 values ('Billy', 'NewYork');" \
| (su - postgres -c '/usr/bin/psql test ') &amp;&amp;
echo "insert into t1 values ('Evanidus', 'Quebec');" \
| (su - postgres -c '/usr/bin/psql test ') &amp;&amp;
echo "insert into t1 values ('Jesse', 'Ontario');" \
| (su - postgres -c '/usr/bin/psql test ') &amp;&amp;
echo "select * from t1;" | (su - postgres -c '/usr/bin/psql test')</userinput></screen>
<para>
When you are done with testing, you can shut down the server, by issuing
as <systemitem class="username">root</systemitem>:
</para>
<screen role="root"><userinput>su - postgres -c "/usr/bin/pg_ctl stop -D /srv/pgsql/data"</userinput></screen>
</sect3>
</sect2>
<sect2 role="content">