LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-17-2008, 11:01 AM   #1
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Change Postgresql data directory


Hello all,

The default data directory for postgres is /var/lib/pgsql/data

How can I change it? There is not config file in /etc (like mysql has /etc/my.cnf)

How can I change this? I want the data dir to "live" in another directory

I am running CentOS 5.0

-C
 
Old 06-17-2008, 11:42 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
http://www.postgresql.org/docs/8.3/s...locations.html
 
Old 06-17-2008, 11:48 AM   #3
houdelou
Member
 
Registered: Nov 2004
Location: Canada
Distribution: Ubuntu
Posts: 44

Rep: Reputation: 15
You have to create another database cluster. To do this :

>mkdir your_new_directory
>chown postgres_user your_new_directory

login as postgres user

>initdb -D your_new_directory

You have to specify this new cluster when you start postmaster with the -D option too or you can change it directly in the startup script like /etc/rc.d/rc.pgsql if you have one.
 
Old 06-17-2008, 12:59 PM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979

Original Poster
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Solved

Quote:
Originally Posted by houdelou View Post
You have to create another database cluster. To do this :

>mkdir your_new_directory
>chown postgres_user your_new_directory

login as postgres user

>initdb -D your_new_directory

You have to specify this new cluster when you start postmaster with the -D option too or you can change it directly in the startup script like /etc/rc.d/rc.pgsql if you have one.
Thanks houdelou

This is what I did to get it to work (This was on CentOS 5.0)...

Shutdown postgres (if it's running)
Code:
root@host# service postgresql stop
Edit the start-up script
Code:
root@host# vi /etc/rc.d/init.d/postgresql
Change the PGDATA and PGLOG variable to wherever you want (changes in red)...
Code:
# Set defaults for configuration variables
PGENGINE=/usr/bin
PGPORT=5432
PGDATA=/path/to/pgdata
if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base/template1" ]
then
        echo "Using old-style directory structure"
else
        PGDATA=/d2/pgdata
fi
PGLOG=/path/to/pgdata/pgstartup.log

# Override defaults from /etc/sysconfig/pgsql if file is present 
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}

export PGDATA
export PGPORT
Create the directory...and set the permissions
Code:
root@host# mkdir -p /path/to/pgdata
root@host# chown postgres:postgres /path/to/pgdata
Initialize the database...
Code:
root@host# su - postgres -c "initdb -D /path/to/pgdata"
Now you can start postgres
Code:
root@host# service postgresql start
Now you can check this with the ps and you'll notice (in red) that the pgdata dir is where the database is

Code:
root@host# ps aux | grep post
postgres 11140  0.0  0.1 122556  3372 ?        S    10:41   0:00 /usr/bin/postmaster -p 5432 -D /path/to/pgdata
postgres 11142  0.0  0.0 111736   672 ?        S    10:41   0:00 postgres: logger process                 
postgres 11144  0.0  0.0 122692  1168 ?        S    10:41   0:00 postgres: writer process                 
postgres 11145  0.0  0.0 112736   672 ?        S    10:41   0:00 postgres: stats buffer process           
postgres 11146  0.0  0.0 111864   848 ?        S    10:41   0:00 postgres: stats collector process        
root     11186  0.0  0.0  61120   724 pts/1    S+   10:58   0:00 grep post

Last edited by custangro; 06-17-2008 at 01:02 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
change default vsftp anonymous accout directory /var/ftp to other directory? hocheetiong Linux - Newbie 2 01-24-2010 06:33 PM
The postgresql data directory content in the pgsql directory is lost (empty data dir) kisembo Linux - Software 1 02-13-2006 01:11 PM
LXer: Store this Data: PostgreSQL 8.1 Bootcamp May 1-5, 2006 LXer Syndicated Linux News 0 01-20-2006 06:46 PM
migrating data from mdb file to postgresql in linux neerajchaudhari Linux - General 8 10-12-2005 12:05 PM
Transfering data from MS Access to PostgreSQL dmg2206 Linux - General 0 03-27-2002 01:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration