You are not logged in.

#1 2016-03-07 11:12:21

quite
Member
Registered: 2013-02-15
Posts: 24

[SOLVED] postgresql, changing default data directory just fails

I'm following the instructions to change default data dir here: https://wiki.archlinux.org/index.php/Po … _directory

But I just can't get postgresql started after doing so. I've tried both methods of overriding the whole postgresql.service, and using a postgresql.service.d/override.conf snippet. Both setting Environment=PGROOT=/home/postgres and as well PIDFile down in that dir.

I keep getting this from systemd:

-- Unit postgresql.service has begun starting up.
Mar 07 12:01:52 ot postgres[12196]: "/home/postgres/data" is missing or empty. Use a command like
Mar 07 12:01:52 ot postgres[12196]:   su - postgres -c "initdb --locale en_US.UTF-8 -D '/home/postgres/data'"
Mar 07 12:01:52 ot postgres[12196]: with relevant options, to initialize the database cluster.
Mar 07 12:01:52 ot systemd[1]: postgresql.service: Control process exited, code=exited status=1
Mar 07 12:01:52 ot systemd[1]: Failed to start PostgreSQL database server.

That is the postgresql-check-db-dir failing, but no, /home/postgres/data is not empty. Doing it manually works fine and gives no error:

# su - postgres -c "/usr/bin/postgresql-check-db-dir /home/postgres/data"
#

I have of course also tried doing the initdb again -- it doesn't help. Also, I adjust $HOME of the postgres user in /etc/passwd, but it doesn't do anything (and maybe should not be necessary anyway). Permissions on /home/postgres and down are postgres:postgres, sure.

I try rolling back everything to use /var/lib/postgres/ and it just works. Perhaps it would be relevant to see exactly how systemd calls postgresql-check-db-dir. Can I do that somehow? Not that there are many ways to call it eh...

Last edited by quite (2016-04-05 18:43:39)

Offline

#2 2016-03-07 11:30:32

quite
Member
Registered: 2013-02-15
Posts: 24

Re: [SOLVED] postgresql, changing default data directory just fails

Also, I was able to start up manually from my moved data dir, after first creating the run dir:

mkdir /run/postgresql
chown postgres:postgres /run/postgresql
su - postgres -c "pg_ctl -D /home/postgres/data -l logfile start"

Offline

#3 2016-04-05 18:34:40

quite
Member
Registered: 2013-02-15
Posts: 24

Re: [SOLVED] postgresql, changing default data directory just fails

I'm back at this...  I have managed to get the actual output from postgresql-check-db-dir (/var/log/daemon.log !)

    Apr  5 20:26:35 ot postgres[4332]: "/home/postgres/data" is missing or empty. Use a command like
    Apr  5 20:26:35 ot postgres[4332]:   su - postgres -c "initdb --locale en_US.UTF-8 -D '/home/postgres/data'"
    Apr  5 20:26:35 ot postgres[4332]: with relevant options, to initialize the database cluster.

This is kinda mad, because /home/postgres/data does exist and is readable by postgres user. If I remove the ExecStartPre=/usr/bin/postgresql-check-db... from the unit file, I instead get the following error output:

    Apr  5 20:29:57 ot postgres[4543]: pg_ctl: could not access directory "/home/postgres/data": Permission denied

So, there is something fishy with how systemd i starting the service. How can /home/postgres/data not be accessible?
I wish I could somehow run strace inside the unitfile, ExecStart=/usr/bin/strace >/tmp/foobar /usr/bin/pg_ctl -s ... or so. But I don't get any foobar file...

Again, if I manually become the postgres user on the command-line, I am able to start postgres using pg_ctl (and run postgresql-check-db-dir).

Last edited by quite (2016-04-05 18:35:12)

Offline

#4 2016-04-05 18:42:29

quite
Member
Registered: 2013-02-15
Posts: 24

Re: [SOLVED] postgresql, changing default data directory just fails

OK. Now I know how /home/postgres/data can be inaccessible... ProtectHome=false solved all this.

Offline

#5 2016-05-24 17:54:58

viraj
Member
Registered: 2016-05-24
Posts: 1

Re: [SOLVED] postgresql, changing default data directory just fails

Thank you, this was helpful for me too.

Offline

#6 2016-07-11 16:17:06

dpriedel
Member
Registered: 2010-12-16
Posts: 19

Re: [SOLVED] postgresql, changing default data directory just fails

Thanks for this !!

I have been puzzling over this for a few months.  I also have my Postgres data directory under /home. I had been running postgres with systemd for a couple of years under Arch with no problems.  But I recently switched to Manjaro (I like their XFCE setup) and when I tried to run postgres as I had under Arch it would not start event though I could run the startup steps manually.

This solves my problem.

Thanks again

Offline

#7 2016-08-24 13:34:29

robert.next
Member
Registered: 2016-08-24
Posts: 3

Re: [SOLVED] postgresql, changing default data directory just fails

Thanks a lot! I've been going crazy with this issue smile

Offline

#8 2017-08-24 08:12:36

groonya
Member
Registered: 2017-08-24
Posts: 1

Re: [SOLVED] postgresql, changing default data directory just fails

Thank you a lot!

Offline

#9 2017-08-24 08:38:18

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: [SOLVED] postgresql, changing default data directory just fails

@groonya, please don't necrobump.

https://wiki.archlinux.org/index.php/Co … bumping.22

Closing thread.

Offline

Board footer

Powered by FluxBB