Installing PostgreSQL 7 on GNU/Linux and FreeBSD, Page 3
InstallAfter a good build we are now ready to install pgsql on your system. Up to this point we have been working under your account on the machine, since we didn't need any special rights to unpack and build pgsql. From this point on you will need to su to root to perform the installation.
So su to root, and read on.
Pgsql is just another task running on your machine and needs to run under a non-privileged ID in order to operate safely. You will not want to run pgsql as the root user because this creates a security risk that opens your system up to attack.
Create a new user on your box named postgres. This ID will be used to run pgsql on your machine. Consult the man pages on your system to determine how to create this user ID. There is nothing sacred about naming this user postgreit's just a convention I follow. You should also assign a password to this account, as the postgres user will have special rights when running the pgsql command line tools.
While still in the SRC directory, type make install. You will see messages scroll across the screen as the install process creates directories and moves the pgsql binaries to /usr/local/pgsql (or whatever directory you specified as the PREFIX during the configure script).
Once pgsql has been moved, change to /usr/local/pgsql and take a look around a bit. You will find directories named bin, data, doc, include, lib, etc. At this point in the install process the binaries are in place as is the directory structure. We now need to create the base templates used by pgsql when creating new databases. Unless they're elsewhere, assume that we are still in the /usr/local/pgsql directory when executing the following commands.
Before creating the templates, we need to take care of a few shared libraries created during the compile. These libraries now reside in /usr/local/pgsql/lib and the system needs to be configured to recognize them. Under RedHat Linux you would edit a file named /etc/ld.so.conf, go to the end of the file, and add an entry denoting the full path to the pgsql lib directory (which is /usr/local/pgsql/lib). Save the file and run ldconfig to have the system reparse the ld.so.conf file.
Under FreeBSD, I edited the file /etc/defaults/rc.conf and added /usr/local/pgsql/lib to the ldconfig_paths variable. While I had to reboot the FreeBSD machine, I'm sure there is a ldconfig variant that would have done the job without a reboot (this should not be considered a weakness of FreeBSD by any stretch of the imagination I'm just new to how FreeBSD does its thing).
At this point we have the libraries registered and binaries in place.
Now we need to create the base template used by pgsql. The command to create the this is called initdb. We will need to specify two parameters to initdb so the process can locate the pgsql lib and data directory. Assuming you used defaults during the configure process, the full initdb command will look like this (it's executed from /usr/local/pgsql):
bin/initdb D /usr/loca/pgsql/data L /usr/local/pgsql/lib
The above command will create the template databases in /usr/local/pgsql/data.
At this point, assuming everything went well, we now have pgsql completely installed. But we aren't ready to roll just yet. We need to take care of assigning ownership and starting pgsql on boot.
You should still be in /usr/local/pgsql. Change to /usr/local and type the following command:
chown R postgres.postgres /usr/local/pgsql
NOTE: With FreeBSD 4.1 you will want to specify postgres:postgres.
This command will change the ownership of all files under the /usr/local/pgsql directory to the postgres user we created a few moments ago.
We have reached the last step of the installation process: getting pgsql to load at boot time. There are two different ways of accomplishing this, and which one you use depends on if you are running FreeBSD or GNU/Linux.
If you are running GNU/Linux there is a startup script already created for you. Perform the following commands:
cp postgresql-7.0.2/contrib/linux/postgres.init.sh /etc/rc.d/init.d/postgres
ln -s /etc/rc.d/init.d/postgres /etc/rc.d/rc3.d/S98postgres
To start pgsql type the following command:
Now, whenever the GNU/Linux machine boots into runlevel 3 it will start pgsql automatically. Repeat the ln command for rc5.d if the machine boots straight into X.
For FreeBSD the process is a bit different. As documented in postgresql-7.0.2/INSTALL, you will have to create a script manually.
Create a file named /usr/local/etc/rc.d/pgsql.sh with the following contents:
su l postgres c exec /usr/local/pgsql/bin/postmaster-D /usr/local/pgsql/data-S o F > /usr/local/pgsql/errlog' & echo n pgsql'
TestingTo test pgsql, su to the postgres user we created earlier and enter /usr/local/pgsql/bin/psql t template1. Once psql loads you will be presented with a prompt. Enter the following statement:
You should see a message like the following appear on the console:
PostgreSQL 7.0.2 on i386-unknown-freebsdelf4.1, compiled by gcc 2.95.2
If you run this on a GNU/Linux machine the message will be a bit different, but if you do see a message like the above, then congratulations! You have installed pgsql!
Other Things to DoWe now have a copy of pgsql running on the machine. The only user who can access pgsql is the postgres user we created earlier in the process. On top of this we only have one database in the system (template), and we don't want to access this while we are learning about pgsql.
To remedy this, we will quickly create an account for you to use. You can su to the postgres user again, type /usr/local/pgsql/bin/createuse,r and follow the prompts. The first thing you will be asked is to name this user: Enter your login name. You will be asked if this new user you are creating is a super user. Answer no to this. When asked if this new user is allowed to create databases answer yes.
Finally, we will need to create a new database for the user you just created. Do this with the /usr/local/pgsql/bin/createdb command. Run this command using the username you entered above as a command line parameter.
To make sure the above two commands worked, type /usr/local/pgsql/bin/psql and you should be presented with the PostgreSQL Interactive Terminal. From here on out you can do whatever you'd like to the database we just created as well as create new databases.
- www.postgresql.org -- the home of PostgreSQL. Online documentation, mailing list archives, and links to other informational sites--. All kinds of good stuff.
- Postgresql-7.0.2/INSTALL very good file discussing how to get pgsql running. Refer back to this file if you get lost during the build process.
Page 3 of 3