Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

python - Postgresql failed to start

I am trying to use PostgreSQL on Ubuntu. I installed it and everything was working fine. However, I needed to change the location of my database due to space constraints so I tried an online guide to do it.

I proceeded to stop postgresql, create a new empty directory and give it permissions by using

chown postgres:postgres /my/dir/path

That worked fine too. Then I used

initdb -D /my/dir/path

to enable my database. I also changed the path_data in the postgresql.conf file to my new directory.

When I now try to start the database, it says: The postgresql server failed to start, please check the log file. However, there is no log file! Something got screwed up when I changed the default directory. How do I fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First: You may find it easier to manage your Pg installs on Ubuntu using the custom tools Ubuntu provides as part of pg_wrapper: pg_createcluster, pg_dropcluster, pg_ctlcluster etc. These integrate with the Ubuntu startup scripts and move the configuration to /etc/postgresql/ where Ubuntu likes to keep it, instead of the PostgreSQL default of in the datadir. To move where the actual files are stored, use a symbolic link (see below).

When you have a problem, how are you starting PostgreSQL?

If you're starting it via pg_ctl it should work fine because you have to specify the data directory location. If you're using your distro package scripts, though, they don't know you've moved the data directory.

On Ubuntu, you will need to change configuration in /etc/postgresql to tell the scripts where the data dir is, probably pg_ctl.conf or start.conf for the appropriate version. I'm not sure of the specifics as I've never needed to do it. This is why:

There's a better way, though. Use a symbolic link from your old datadir location to the new one. PostgreSQL and the setup scripts will happily follow it and you won't have to change any configuration.

cd /var/lib/postgresql/9.1/main
mv main main.old
ln -s /new/datadir/location main

I'm guessing "9.1" because you didn't give your Ubuntu version or your PostgreSQL version.

An alternative is to use mount -o bind to map your new datadir location into the old place, so nothing notices the difference. Then add the bind mount to /etc/fstab to make it persistent across reboots. You only need to do that if one of the tools doesn't like the symbolic link approach. I don't think that'll be an issue with pg_wrapper etc.

You should also note that since you've used initdb manually, your new datadir will have its configuration directly inside the datadir, not in /etc/postgresql/.

It's way easier if you just use the Ubuntu cluster management scripts instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...