What are the steps to move an existing data directory in Postgres9?


            I have an existing database located on /loc/data. I want to move the data directory to it's own partition. What are the steps to accomplish this task? I have tried numerous configurations such as stopping the db, moving the db to /data then exporting PGDATA to /data. The server will not connect thorugh PGADMIN.
How do I get PGADMIN to see the PGDATA files? What are all of the config files if any that need to  be changed? Do I need to run initdb? I did try this and recieved an error that there was data in the directory. Do I need to initdb then move the data over?

Please advise, Missymadi
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lcohanDatabase AnalystCommented:
You could add new tablespace by using CREATE TABLESPACE new_tablespace

Then ALTER TABLE table_name SET TABLESPACE TABLESPACE new_tablespace to move it to the new tablespace:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
missymadiAuthor Commented:
That's not quite what I'm asking for....I need to move my /loc/data postgres directory to a partioned /data drive. I have tried several suggestions (i.e. moveing data to partioned drive, using export  PGDATA=/data/DATA restart server.....not working
That should be enough. Are you overriding it in postgresql.conf data_directory parameter? What exactly does it say when it fails to start? Does it write to the pg_log at all?
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

missymadiAuthor Commented:
Here is what I tried to do:

su abc
pg_ctl stop
su (to root)
mv /opt/co/DATA/* /data
su abc
pg_ctl start

PGADMIN connection refused. There is nothing in the log!!
I don't know where else to look to solve this.
Thanks, Missymadi
- Does PGDATA env variable refer to /data
- have you tried pg_ctl start -D /data
missymadiAuthor Commented:
I decided to use a symbolic link. The problem was that we had custom scripts that were running and pointing to the old directory. So I did the following:

ln -s /data //opt/co/DATA

working now!
Thanks for your help!
missymadiAuthor Commented:
i gave the experts credit for helping me. I think initially the problem was a permissions issue. Then I found that I could do a symlink that was less complicated. The database restarted after many tests.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.