/usr/pgsql-14/bin/postgresql-14-setup initdb -D /pg_data/ariel/ sur redhat 8 systemctl:…
- User
/usr/pgsql-14/bin/postgresql-14-setup initdb -D /pg_data/ariel/ sur redhat 8 systemctl: invalid option -- 'D' failed to find PGDATA setting in -D.service
- Assistant
It seems like there's a misunderstanding in the usage of the command you have attempted. The
postgresql-14-setupscript is used to initialize a PostgreSQL database cluster with theinitdboption. The-Dflag specifies the directory where the database should be initialized, which is correct. However, the error you're encountering does not stem directly from this command, but rather from the misuse ofsystemctl, indicated by the error message regarding an invalid option-D.The correct sequence of steps to initialize a PostgreSQL database and start the service on Red Hat Enterprise Linux 8 (or similar systems like CentOS 8) should look something like this:
-
Initialize the Database:
You correctly used the
postgresql-14-setupscript to initialize the database. If/pg_data/ariel/is the desired location for your database cluster, the command should indeed be:/usr/pgsql-14/bin/postgresql-14-setup initdb -D /pg_data/ariel/Ensure that
/pg_data/ariel/exists and the PostgreSQL process has sufficient permissions to access and write to this directory. -
Configure PostgreSQL to Use the New Data Directory (if necessary):
After initializing the database, you need to ensure PostgreSQL is configured to use the new data directory. This can often involve editing the PostgreSQL service file or a related environment file to specify the
PGDATAenvironment variable.However, specifying
-Ddirectly in the systemdsystemctlcommand is not valid, as systemd does not accept PostgreSQL-specific flags like-Ddirectly.Instead, to change the data directory that the PostgreSQL service uses, you would typically edit the PostgreSQL service file located at
/usr/lib/systemd/system/postgresql-14.serviceor a custom environment file referenced therein. You would look for a line that sets thePGDATAenvironment variable and change its value to/pg_data/ariel/. -
Reload systemd and Start PostgreSQL:
After editing the service file or its associated environment file, you must inform
systemdabout the changes and then attempt to start the PostgreSQL service. You can do this with:sudo systemctl daemon-reload sudo systemctl start postgresql-14 -
Enable PostgreSQL to Start on Boot (optional):
If you want PostgreSQL to start automatically when the system boots, use:
sudo systemctl enable postgresql-14
If you encounter errors about not finding the
PGDATAsetting, it’s likely because the system's service file for PostgreSQL does not recognize the custom data directory. This typically means you need to ensure thePGDATAenvironment variable is correctly set either in the PostgreSQL service file or an associated environment configuration that the service file reads from. Also, verify the specific service name (postgresql-14in your case) matches the installed version and naming convention used by your system. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.