3

I am trying to install and run postgresql@14 on my Ventura 13.2.1 macbook. But, the service is always at error 256 or 512 status. I have tried every single solution in this post, but without any success. Here more details about it:

➜ ~ brew services list

Name Status User File

mongodb-community started adrien ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist postgresql@14 error 512 root ~/Library/LaunchAgents/[email protected] unbound none

➜ ~ tail -f /opt/homebrew/var/log/[email protected]

postgres: could not access the server configuration file "/opt/homebrew/var/postgresql@14/postgresql.conf": No such file or directory "root" execution of the PostgreSQL server is not permitted. The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server.

➜ ~ initdb -D /var/lib/postgres/data/

The files belonging to this database system will be owned by user "adrien". This user must also own the server process.

The database cluster will be initialized with locale "fr_FR.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "french".

Data page checksums are disabled.

creating directory /var/lib/postgres/data ... initdb: error: could not create directory "/var/lib/postgres": Permission denied

2
  • "Permission denied" is a problem about basic operating system management, bot about software development. Commented Apr 6, 2023 at 5:58
  • 1) Where did you install from here Homebrew default or Homebrew petere? 2) Did you follow the instructions here Homebrew Wiki? Commented Apr 6, 2023 at 15:05

3 Answers 3

2

I've had the same issue. What worked for me was to brew uninstall postgresql and then brew install postgresql@14

Sign up to request clarification or add additional context in comments.

Comments

2

For my case, the error log was

➜  ~ tail -f /opt/homebrew/var/log/[email protected]
postgres: could not access directory “/opt/homebrew/var/postgresql@14”: No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
postgres: could not access directory “/opt/homebrew/var/postgresql@14": No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
postgres: could not access directory “/opt/homebrew/var/postgresql@14”: No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
postgres: could not access directory “/opt/homebrew/var/postgresql@14": No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
postgres: could not access directory “/opt/homebrew/var/postgresql@14”: No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.

The error message indicates that PostgreSQL is trying to access a data directory that does not exist. This usually means that PostgreSQL has not been properly initialized.

So, had to initialize the PostgreSQL data directory. This can be done using the initdb command after reinstalling with homebrew.

/opt/homebrew/opt/postgresql@14/bin/initdb -D /opt/homebrew/var/postgresql@14

And it worked ..

Comments

1

I had the same problem (MacOS M4). And I tried many times to uninstall and install postgresql (i.e. postgresql@14) and still got the same error after brew services list:

postgresql@14 error 2 tami ~/Library/LaunchAgents/[email protected]

I tried to delete postmaster.pid as well as checked many threads on Stack Overflow say but still nothing worked. So I stopped the psql service: brew services stop postgresql@14.

I don't know why I wasn't able to fix this same problem the same way as many guys here. I went step by step and tried to solve it without deleting the whole DB but... didn't work for me.. so make sure you have a backup because after removing whole folder below, it will remove the whole DB.

And what worked for me, it was remove whole postgresql@14 directory: rm -rf /opt/homebrew/var/postgresql@14.

After removing the folder, initialize the db: initdb /opt/homebrew/var/postgresql@14 (run initdb --help before if you want set option parameters).

The files belonging to this database system will be owned by user "tami".
This user must also own the server process.

The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /opt/homebrew/var/postgresql@14 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Prague
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D '/opt/homebrew/var/postgresql@14' -l logfile start

After brew services start postgresql@14:

postgresql@14 started tami ~/Library/LaunchAgents/[email protected]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.