X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C3C7FD1B373 for ; Fri, 2 Jul 2004 12:35:49 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 12700-06 for ; Fri, 2 Jul 2004 15:35:47 +0000 (GMT) Received: from mallaury.noc.nerim.net (smtp-105-friday.noc.nerim.net [62.4.17.105]) by svr1.postgresql.org (Postfix) with ESMTP id 593C0D1B2D9 for ; Fri, 2 Jul 2004 12:35:46 -0300 (ADT) Received: from max.my.domain (mey.net1.nerim.net [213.41.158.149]) by mallaury.noc.nerim.net (Postfix) with ESMTP id 37A2062DF8 for ; Fri, 2 Jul 2004 17:35:43 +0200 (CEST) Received: from jc by max.my.domain with local (Exim 3.35 #1 (Debian)) id 1BgQ2m-0000TP-00 for ; Fri, 02 Jul 2004 17:33:40 +0200 Date: Fri, 2 Jul 2004 17:33:40 +0200 To: pgsql-admin@postgresql.org Subject: Re: unable to pass variable PGDATA2 into server environment Message-ID: <20040702153340.GA1068@max.my.domain> Mail-Followup-To: pgsql-admin@postgresql.org References: <20040701162349.GA1241@max.my.domain> <29053.1088704519@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <29053.1088704519@sss.pgh.pa.us> User-Agent: Mutt/1.3.28i From: Jean-Christophe Weis X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/38 X-Sequence-Number: 14106 Hello list, On Thu, Jul 01, 2004 at 01:55:19PM -0400, Tom Lane wrote: > Jean-Christophe Weis writes: > > The variable PGDATA2 is set and marked for export in the root shell where I > > start the server, but it is not passed into the server's environment. > > No, because the start script is going to su to the postgres account, > and su is going to reset the environment. The usual advice for doing > this sort of thing is to set the environment variable in the postgres > user's .profile file. That way the postmaster has it, and you also > have it if you manually su to postgres. > > (This whole benighted environment-variable scheme is gone in CVS tip, > thank goodness.) > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) I did not think that su might reset the environment as Tom says, because I had seen: | root# PGDATA2=/home/jc/postgres/data | root# export PGDATA2 | root# su postgres | postgres$ echo $PGDATA2 | /home/jc/postgres/data and also because '/path/to/initlocation PGDATA2' worked in the 'postgres' shell. But after Tom's remark, I wanted to have a closer look at my '/etc/init.d/postgresql' script, and this is what I saw: | startup () { | ... | su - postgres -c /usr/lib/postgresql/bin/postgresql-startup | ... | } There is a dash after 'su'. And this what 'man su' says: | The optional argument - may be used to provide an environment similar to | what the user would expect had the user logged in directly. That is to say, my problem was that the variable PGDATA2 was set and marked for export in the root shell where I started the server, but it was not passed into the server's environment _because_the_init_script_does_a_'su dash'_. When I delete the dash in the init script, I can create a database in the new data storage area as described in the documentation: | jc$ createdb testdb -D PGDATA2 | CREATE DATABASE And if I let the dash in, and follow Tom's advice of setting (and marking for export) the PGDATA2 environment variable in the postgres user's '.profile', it works fine too. (I had a hard time finding that the home directory for the postgres user was '/var/lib/postgres'...) So, thanks to the list, thanks to Tom and thanks to Guido Barosio too, who answered me directly. So long, -- JC Weis