I have recently installed pg 8.4 on Ubuntu 10.0.4 using apt-get install.
It installed pg as a service which starts ehenever the machine starts. However I have created a db cluster in a specific location that I want postgres to use.
This is the command line output of how I created the cluster:
username@jupiter:~$ sudo /usr/lib/postgresql/8.4/bin/initdb --encoding=UTF8 --pgdata=/mydata/pgdbdata/
initdb: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.
username@jupiter:~$ /usr/lib/postgresql/8.4/bin/initdb --encoding=UTF8 --pgdata=/mydata/pgdbdata/
The files belonging to this database system will be owned by user "username".
This user must also own the server process.
The database cluster will be initialized with locale en_US.utf8.
The default text search configuration will be set to "english".
fixing permissions on existing directory /mydata/pgdbdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 24MB
creating configuration files ... ok
creating template1 database in /mydata/pgdbdata/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
Success. You can now start the database server using:
/usr/lib/postgresql/8.4/bin/postgres -D /mydata/pgdbdata
or
/usr/lib/postgresql/8.4/bin/pg_ctl -D /mydata/pgdbdata -l logfile start
username@jupiter:~$
Now, I try to start the postgresql service:
Here is the command line output:
username@jupiter:~$ /usr/lib/postgresql/8.4/bin/pg_ctl start -D /mydata/pgdbdata/
server starting
username@jupiter:~$ FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
So I have two questions:
How can I start the service and specify a data location (what am I doing wrong?)
I want the service started when the machine starts/reboots, to use the new data directory. Which file do I need to edit to ensure that I always have the service using the correct data folder?
PGDATA
environment variable for the user account running the service?