Home > Articles > Data

  • Print
  • + Share This

Allocating Space and Creating the Superuser

Now, on with the show. The first thing that you should do with any install is to check for necessary disk space and for the proper dependencies. PostgreSQL has some initial requirements, most of which can be cleaned up after installation is complete:

During installation you'll need:

  • ~30 Mb—/usr/src/pgsql (/usr/local/src may also be used)
  • ~30 Mb—/usr/local/pgsql

After installation (with 1 blank database), you'll need ~5 Mb in /usr/local/pgsql

For actual database storage, allow yourself 5 times the space required to store the data as a flat file. If you were to look into /usr/local/pgsql/data/base you would see many more files than just your tables. PostgreSQL builds many files to handle indexes, sequences, and so on.

To check for disk space, use df -k. You'll see the following:

euphoria:~$/ df -k
Filesystem                      1K-blocks     Used    Avail Capacity  Mounted on
/dev/wd0s1a                         63503    20922    37501    36%    /
/dev/wd0s1f                         63503     1161    57262     2%    /tmp
/dev/wd0s1g                       1293167  1033407   156307    87%    /usr
/dev/wd0s1e                         63503    12304    46119    21%    /var
procfs                                  4        4        0   100%    /proc

Next check to see if you have the proper version of flex (fast lexical analyzer)—flex 2.5.2, 2.5.4, or higher, is required. If you do not have this installed, please do so, or ask your system administrator to do so. The installation of flex is outside the scope of this article, but it can be downloaded here. Documentation for flex can be found in the flex tarball, in the INSTALL file.

To check the version of flex:

euphoria:~/$ flex --version
flex version 2.5.4

You will also need the gmake package. This is usually included with most distributions of Unix, but if you are missing this package information about it can be found here.

Now a few steps must be done as root. We'll complete as many of these steps as possible so we don't have to switch back and forth between postgres and root.

First, login as root, or su to root.

euphoria:~$ su -

Note that PostgreSQL does not run as root, so we must make the PostgreSQL user. This is commonly called the PostgreSQL Super-user, but despite its name, this user has no special permissions. It is commonly called pgsql or postgres, but you could call it norm if you want to.

It is important to make sure this user does not do much else, which means do not make it the same user as apache. This will save headaches later with maximum open files and other limits that are imposed on users by the system. For this example we will use the user postgres.

Here's an example in FreeBSD:

euphoria:~# adduser -silent
Enter username [a-z0-9_-]: postgres
Enter full name []: PostgreSQL Postmaster
Enter shell bash csh date no sh [bash]:
Enter home directory (full path) [/home/postgres]:
..
..
..
Add another user? (y/n) [y]: n
euphoria:~#

Now we have to create the directories for the source, the binaries, and the actual database to reside in. (Please make sure that you've used the previous instructions to make sure you have enough space.)

/usr/src/pgsql is where you will uncompress the source and do the compiling. /usr/local/pgsql is where the binaries and the data will reside. There are some more advanced options if you want different databases on different file systems; for example, if you would like to store some of your databases on a different file system you can set the PGDATA variable to point to somewhere else. Finally we will give ownership of these files to the postgres user. The syntax is: chown username.groupname [directory|file].

euphoria:~# mkdir /usr/src/pgsql
euphoria:~# mkdir /usr/local/pgsql
euphoria:~# chown postgres.postgres /usr/local/pgsql/
euphoria:~# chown postgres.postgres /usr/src/pgsql

As far as being root, we're done until the end of the install—so logout:

euphoria:~# logout
euphoria:~$

Then login or su to the postgres user:

euphoria:~$ su - postgres

We've done a lot of preparation, but now it's time to get to the good stuff. The rest is relatively straightforward if you have ever installed from source.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.