Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 87926 - The init script that starts posgresql does not care about changes in PGDATA
Summary: The init script that starts posgresql does not care about changes in PGDATA
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: PgSQL Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-04 09:52 UTC by Helge Thorbjørnsen
Modified: 2006-11-11 15:46 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Helge Thorbjørnsen 2005-04-04 09:52:20 UTC
example :
-----------

bash-2.05b# /etc/init.d/postgresql start
 * directory not found: /var/lib/postgresql/data
 * You should create PGDATA directory first.

but look at what PGDATA is.
----------------------------
bash-2.05b# echo $PGDATA
/usr/share/postgresql/data
bash-2.05b#

In /etc/env.d/99local
----------------------
PGDATA=/usr/share/postgresql/data

The command initdb has been used to create the cluster  on /usr/share/postgresql/data and everything was initialized ok.

It seems to me that the environment variables change when I run the script
Here is a look at the script, the procedure checkconfig() seems to return the error msg.


opts="${opts} reload"

depend() {
        use net
}

checkconfig() {
        if [ ! -d $PGDATA ]; then
                eerror "directory not found: $PGDATA"
                eerror "You should create PGDATA directory first."
                return 1
        fi
}

start() {
        checkconfig || return 1



Reproducible: Always
Steps to Reproduce:
1. Create the file /etc/env.d/99local and insert a line PGDATA=<your choice of directory> #This directory must exist and owner should be postgres
2. Commit the changes by using the command env-update && source /etc/profile 
3. Check that changes have been made by doing an echo $PGDATA
4. Change to the postgres user: su postgres
5. Check PGDATA again: echo $PGDATA
6. Give the command to make the cluster: initdb
7. Check that everything is initialized ok at <your choice of directory>
8. exit to root
9. /etc/init.d/posgresql start
 

Actual Results:  
 * directory not found: /var/lib/postgresql/data
 * You should create PGDATA directory first.


Expected Results:  
Started postgresql using <your choice of directory> as the servers cluster.

       ebegin "Starting PostgreSQL"
        if [ -f $PGDATA/postmaster.pid ]; then
                rm $PGDATA/postmaster.pid
        fi
        su - $PGUSER -c "/usr/bin/pg_ctl start -D '$PGDATA' -s -l '$PGLOG' -o
'$PGOPTS'"
Comment 1 Masatomo Nakano (RETIRED) gentoo-dev 2005-04-04 10:22:49 UTC
Hi,

/etc/conf.d/postgresql might overwrite PGDATA variable.
Can you show me 'grep PGDATA /etc/conf.d/postgresql'?
Comment 2 Helge Thorbjørnsen 2005-04-04 14:31:57 UTC
Hi, 
Here is the result:
bash-2.05b# grep PGDATA /etc/conf.d/postgresql
PGDATA=/var/lib/postgresql/data
Comment 3 Helge Thorbjørnsen 2005-04-07 15:01:51 UTC
Hi,

I have been poking around and found out the following.

If you upgrade from an earlier version you may also get into trouble because of the postgres user that exists on the system, in other words the root of the problem is that an upgrade does not handle the situation as well as it could.

If you install the package on a pc that has not got any previous ver. installed everything seems to work perfectly, except for all the places where /var/lib/postgress/data is hardcoded.

Possible remedy, (just a suggestion)

Instead of hardcoding /var/lib/postgre.... in several conf. files why not use $PGDATA instead in these files and put the value PGDATA=/var/lib/post... in say
/etc/env.d/99local or some other file (which I don't know about). Then at first time install it would create this PGDATA line and when an updated ver. wanted to install it would check for this line and if it existed just use it. That way if a user has modified the location for PGDATA an upgrade would use the same location as the user wants.
Comment 4 Masatomo Nakano (RETIRED) gentoo-dev 2005-04-08 10:46:55 UTC
hmartin,

if you comment the line in etc/conf.d/postgresql out as workaround, it would work.

And I'll modify /etc/conf.d/postgresql not to overwrite the value in the next ebuild version.
Comment 5 Ole Tange 2005-07-21 10:08:37 UTC
Why not have Postgresql create $PGDATA and set the correct permissions when 
Postgresql is installed for the first time? 
 
Comment 6 Tiziano Müller (RETIRED) gentoo-dev 2006-11-11 15:46:58 UTC
Well, if you have to change the default path, do it in /etc/conf.d/postgresql. We won't introduce a global env var (which would interfere with the upcoming slotting of postgresql)