Opened 15 months ago
Closed 14 months ago
#68119 closed defect (fixed)
postgresql15: Initialize database cluster fails
Reported by: | Klogic1 | Owned by: | dgilman (David Gilman) |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | 2.8.1 |
Keywords: | Cc: | jyrkiwahlstedt, dgilman (David Gilman) | |
Port: | postgresql15, postgresql15-server, postgresql_select |
Description (last modified by ryandesign (Ryan Carsten Schmidt))
MacBook Pro (Retina, 15-inch, Mid 2015) Intel
macOS Monterey 12.6.8
Clean install prior to installing Macports
MacPorts; 2.8.1
Xcode: 14.2 (14C18)
Xcode command line tools: 14.2.0.0.1.1668646533
The PostgreSQL ports download and install without a problem. When following the directions provided I can not Initialize database cluster.
Error message:
Error: shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied chdir: error retrieving current directory: getcwd: cannot access parent directories: Permission denied initdb: option requires an argument -- D initdb: hint: Try "initdb --help" for more information. sh: line 1: /opt/local/var/db/postgresql15/defaultdb: is a directory
I used these commands.
sudo port select postgresql postgresql15 sudo port load postgresql15-server sudo mkdir -p /opt/local/var/db/postgresql15/defaultdb sudo chown postgres:postgres /opt/local/var/db/postgresql15/defaultdb sudo su postgres -c 'cd /opt/local/var/db/postgresql15 && /opt/local/lib/postgresql15/bin/initdb -D /opt/local/var/db/postgresql15/defaultdb'
How should PostgreSQL be installed using MacPorts?
Change History (5)
comment:1 Changed 14 months ago by ryandesign (Ryan Carsten Schmidt)
Cc: | jyrkiwahlstedt dgilman added; jwa@… removed |
---|---|
Description: | modified (diff) |
Keywords: | PostgreSQL 15 removed |
comment:2 follow-up: 3 Changed 14 months ago by dgilman (David Gilman)
comment:3 Changed 14 months ago by ryandesign (Ryan Carsten Schmidt)
Replying to dgilman:
I believe the
getcwd
/chdir
errors have to do with the postgres user's home directory, that is a bug, I will investigate a fix.
Klogic1, what is the postgres user's home directory on your system? You can find out by running:
dscl . -read /Users/postgres NFSHomeDirectory
On my system, it says:
NFSHomeDirectory: /opt/local/var/db/postgresql15
However, as I recall, the first postgresql*-server port you install creates the postgres user and sets its home directory, and if you later want to use a different postgres*-server port, you have to edit the postgres user's NFSHomeDirectory
attribute manually with dscl
. Also, if you used Apple's Migration Assistant to move another computer's data to this computer, and you migrated the postgres user or any other users created by MacPorts or the macports user itself, Migration Assistant will move all of their home directories and they will have to be moved back where they belong manually in addition to editing the records with dscl
.
comment:4 Changed 14 months ago by Klogic1
dgilman, to answer your question about postgres user's home directory.
I have the same postgres home directory as you:
NFSHomeDirectory: /opt/local/var/db/postgresql15
I am using a MacBook Pro with macOS Monterey to test MacPorts and PostgreSQL before I install them on an iMac.
Prior to installing MacPorts and PostgreSQL I erased the SSD and reinstalled macOS Monterey. So, Apple's Migration Assistant was not used.
Now to the postgresql15: Initialize database cluster fails problem.
I have been able to resolve the problem. Apparently copying and pasting the below command at the terminal prompt was causing a problem for some reason.
sudo su postgres -c '/opt/local/lib/postgresql15/bin/initdb -D /opt/local/var/db/postgresql15/defaultdb’
When I typed the command at the terminal prompt it executed as expected and created a database cluster.
The PostgreSQL server is now running.
Please close the ticket since the problem is resolved.
Thanks for your assistance with this problem and providing the PostgreSQL 15 updates.
comment:5 Changed 14 months ago by dgilman (David Gilman)
Owner: | set to dgilman |
---|---|
Resolution: | → fixed |
Status: | new → closed |
I believe the
getcwd
/chdir
errors have to do with the postgres user's home directory, that is a bug, I will investigate a fix.However, I don't think those are impacting what you're trying to do here. First, the directions from the postgresql15-server note are to run the three sudo commands, then you
port load postgresql15-server
. If you try toport load
first it will error out for lack of a database cluster. Next, did you copy the final sudo command correctly into the terminal, including the single quotes? Theinitdb requires an option
suggests some issue with shell escaping / getting the correct shell command through sudo su. The full command as you've pasted above is correctly formatted and should pass the correct-D
flag to initdb.Other than the
getcwd
errors I am not able to reproduce this. If you don't want to use PostgreSQL as a startup service you can also just use initdb as your own user, in an arbitrary directory in your home dir, and make a one-off server you start and stop manuall withpg_ctl
. It's more docker-like (one database cluster per project) and personally I prefer using postgres that way.