Forum OpenACS Q&A: Use /etc/profile-postgres.sh

Collapse
Posted by Andrew Piskorski on
Putting some of those environment variables in the postgres's users login scripts is just plain wrong anyway. As I've mentioned before, these are system-wide settings that you probably want be default in some system-wide place. See my Oracle install notes - the issue should be the same for PostgreSQL.

What you really want is a file called /etc/profile-postgres.sh or something like that. It should be something like this:

#
# $Id: profile-postgres.sh,v 1.2 2002/12/24 07:03:13 atp Exp $
#
# Single central place for setting all PostgreSQL environment variables.
# Source this from /etc/profile.
#
# --atp@piskorski.com, 2002/12/06 14:03 EST

# For Debian PostgreSQL package:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/postgresql/lib/
PATH=$PATH:/usr/lib/postgresql/bin/
PG_HEADERS=/usr/include/postgresql

## For locally installed from source PostgreSQL:
#LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib
#PATH=$PATH:/usr/local/pgsql/bin

export PATH LD_LIBRARY_PATH PG_HEADERS
. /etc/postgresql/postgresql.env

Then do this in an appropriate spot in your system-wide /etc/profile:

for script in  /etc/profile-oracle.sh  /etc/profile-postgres.sh
do
  if [ -e "$script" ]
  then
    . "$script"
  fi
done

Collapse
Posted by Malte Sussdorff on
Amen to that. For the record, SuSE uses /etc/profile.d/ for storing these kind of files and it is fairly usefull (as all files get sourced at system start AFAIK). Who is going to add this to the documentation ?
Collapse
Posted by Andrew Piskorski on
Oh, Red Hat seems to have /etc/profile.d/ as well, I didn't know about that. Debian does not though. Ah, it is used via a little loop at the end of /etc/profile:
for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        . $i
    fi
done
unset i
So that's good, there's no magic going on behind the scenes, it is just good old /etc/profile doing the work. Very simple.

(I guess nobody in the Linux world worries about /bin/sh vs. /bin/bash differences anymore, since most Linux distributions use bash for everything. That "; then" syntax won't work in sh, like you sometimes find on Solaris...)