pg_Ctl -data directory has wrong ownership

1.5k Views Asked by At

I am unable to start the Postgres server and whenever I use pg_ctl I am getting the following error - can some one help me to fix this. I changed the folder permissions using CHmod and tried running with Sudo -s also but still the problem exists.

one error I did was, I deleted the Postmaster.pid when the server was running- post this I am getting this issue when ever I try to start the server through pg_ctl and another error when I use the pgadmin.

Any suggestions here will be really helpful- thanks.

Using Macos Shell command :

'pg_ctl start -D /Library/PostgreSQL/12/data waiting for server to start....2020-05-05 11:40:04.838 IST [1216] FATAL: data directory "/Library/PostgreSQL/12/data" has wrong ownership 2020-05-05 11:40:04.838 IST [1216] HINT: The server must be started by the user that owns the data directory. stopped waiting pg_ctl: could not start server Examine the log output.'

Using pgadmin the error is as follows :

'could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5434? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5434?'

p.s. : I modified the hba.conf and also the postgres.conf files to allow connection from the local ip

Error received on 5May

waiting for server to start....2020-05-05 19:54:13.029 IST [7274] LOG: starting PostgreSQL 12.2 on x86_64-apple-darwin, compiled by Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn), 64-bit 2020-05-05 19:54:13.030 IST [7274] LOG: listening on IPv6 address "::", port 5433 2020-05-05 19:54:13.030 IST [7274] LOG: listening on IPv4 address "0.0.0.0", port 5433 2020-05-05 19:54:13.030 IST [7274] LOG: listening on Unix socket "/tmp/.s.PGSQL.5433" 2020-05-05 19:54:13.039 IST [7274] LOG: redirecting log output to logging collector process... 2020-05-05 19:54:13.039 IST [7274] HINT: Future log output will appear in directory "log" stopped waiting .. pg_ctl: could not start server

Examine the log output.

Log file details

2020-05-05 21:29:30.748 IST [8853] LOG:  invalid authentication method "0.0.0.0/0"
2020-05-05 21:29:30.748 IST [8853] CONTEXT:  line 80 of configuration file "/Library/PostgreSQL/12/data/pg_hba.conf"
2020-05-05 21:29:30.748 IST [8853] FATAL:  could not load pg_hba.conf
2020-05-05 21:29:30.749 IST [8853] LOG:  database system is shut down

Details of my pg_HBA conf 

# "local" is for Unix domain socket connections only
local   all             all            0.0.0.0/0                md5
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.

local   replication     all                                     md5
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all             all             0.0.0.0/0               md5

host all all ::/0 md5

latest log file

bash-3.2$ cat postgresql-2020-05-05_221328.log 2020-05-05 22:13:28.794 IST [9834] LOG: database system was interrupted; last known up at 2020-05-05 22:13:09 IST 2020-05-05 22:13:28.872 IST [9834] LOG: database system was not properly shut down; automatic recovery in progress 2020-05-05 22:13:28.874 IST [9834] LOG: redo starts at 0/17742C8 2020-05-05 22:13:28.874 IST [9834] LOG: invalid record length at 0/1774300: wanted 24, got 0 2020-05-05 22:13:28.874 IST [9834] LOG: redo done at 0/17742C8 2020-05-05 22:13:28.881 IST [9832] LOG: database system is ready to accept connections ...... also I found this error while staring the server and the PID is chaning everytime..

pg_ctl: another server might be running; trying to start server anyway waiting for server to start....2020-05-05 22:09:21.941 IST [9746] FATAL: lock file "postmaster.pid" already exists 2020-05-05 22:09:21.941 IST [9746] HINT: Is another postmaster (PID 9735) running in data directory "/Library/PostgreSQL/12/data"? stopped waiting pg_ctl: could not start server Examine the log output. bash-3.2$ kill -9 9735 bash-3.2$ pg_ctl start -D /Library/PostgreSQL/12/data pg_ctl: another server might be running; trying to start server anyway waiting for server to start....2020-05-05 22:09:35.829 IST [9758] FATAL: lock file "postmaster.pid" already exists 2020-05-05 22:09:35.829 IST [9758] HINT: Is another postmaster (PID 9747) running in data directory "/Library/PostgreSQL/12/data"? stopped waiting pg_ctl: could not start server

Examine the log output.

502 9833 9832 0 10:13PM ?? 0:00.00 postgres: logger
502 9835 9832 0 10:13PM ?? 0:00.00 postgres: checkpointer
502 9836 9832 0 10:13PM ?? 0:00.04 postgres: background writer
502 9837 9832 0 10:13PM ?? 0:00.01 postgres: walwriter
502 9838 9832 0 10:13PM ?? 0:00.01 postgres: autovacuum launcher
502 9839 9832 0 10:13PM ?? 0:00.01 postgres: stats collector
502 9840 9832 0 10:13PM ?? 0:00.00 postgres: logical replication launcher
0 9641 9504 0 10:03PM ttys000 0:00.02 sudo -u postgres -s /bin/bash 502 9904 9642 0 10:37PM ttys000 0:00.00 grep postgres

2

There are 2 best solutions below

17
On BEST ANSWER

The data directory should be owned by the postgres user and have user-only access (700 or u+rwx)

Does this match what you have set up?

Thom Brown

Disclosure: I am an EnterpriseDB employee.

0
On

Try running this code

pg_ctl -D /usr/local/var/postgres start