デフォルトのデータベースディレクトリ

デフォルトのデータベースディレクトリ

私はSlackbuildを介してpostgresとpsqlをインストールしたかったです。インストール後にSlackbuildのreadmeで提案されているようにコマンドを実行してみましたが、説明どおりに実行するとエラーが発生しました。

su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"

1行でなければならず、コピーして貼り付けた内容の1行にsuがあり、もう1行に残りのコマンドがあります。これがあなたのフォーマットの問題であるかどうかはわかりませんが、確かにそうではありません。また、報告されたエラーメッセージは、1行にコマンドを提供していないため、正しいユーザーでコマンドを実行しなかったという考えを裏付けているようです。ファイルで実行してみました。私はソースを介してインストールしようとしましたが、非常に複雑で、Slackbuildを介してインストールしました。以下を実行するまで、すべてが正常です。コード:

su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"

上記のコマンドをさまざまな方法で実行しようとすると、この結果が得られます。実行されず、これがPostgresが機能しない理由だと思います。私はこの問題を克服し、Slackware、Linux、PSQL、およびFull Stackの使い方を学び、知識ベースを最大化し、Slackwareプロジェクトに貢献することにしました。このブログを介してPostgresをインストールしている間、いくつかの重要ですが、古いプログラムが私が追加しようとしているSboサイトにはないことがわかりました。この人はSlackwareに関する興味深いブログを運営しています。http://www.pmoghadam.com/homepage/HT...esql-epkg.html 以下は、コマンドを実行する試みです。何が起こっていると思いますか?

bash-5.1$ su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ sudo postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
"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.
bash-5.1$ su - postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ su - postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ su postgres -c init -D /var/lib/pgsql/14/data --locale-en_US.UTF-8 -A md5 -W
su: invalid option -- 'D'
Usage: su [options] [-] [username [args]]

Options:
  -c, --command COMMAND         pass COMMAND to the invoked shell
  -h, --help                    display this help message and exit
  -, -l, --login                make the shell a login shell
  -m, -p,
  --preserve-environment        do not reset environment variables, and
                                keep the same shell
  -s, --shell SHELL             use SHELL instead of the default in passwd

If no username is given, assume root.



bash-5.1$ su
Password: 
bash-5.1# postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
"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.
bash-5.1# su - postgres

We are upping our standards ... so up yours.
                -- Pat Paulsen for President, 1988

postgres@Bern:~$ postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
2022-03-27 14:57:17.257 GMT [32152] FATAL:  unrecognized configuration parameter "initdb _D /var/lib/pgsql/14/data __locale"
postgres@Bern:~$ postgres -c initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W
2022-03-27 14:57:30.413 GMT [32155] FATAL:  -c initdb requires a value
postgres@Bern:~$

私は聖書で私に言ったことを聞いて従ったので、なぜこれがうまくいかないのかわかりません。私はLinuxともっと重要なことに、Slackwareは神聖で魔法のようなソフトウェアだと思います。引き続き結果を探してみましょう。

6.0/import_db.sh

#!/usr/bin/env sh

dropdb sqlzoo
createdb sqlzoo
psql sqlzoo < data/create_tables.sql
ls

psqlを使用する必要があるプロジェクトファイルディレクトリ。次のエラーが発生します。

bash-5.1# cd skeleton
bash-5.1# ls
Gemfile  Gemfile.lock  data  database  import_db.sh  lib  logfile  spec
bash-5.1# ./import_db.sh 
dropdb: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?
createdb: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?
Gemfile  Gemfile.lock  data  database  import_db.sh  lib  logfile  spec
bash-5.1# startdb
bash: startdb: command not found
bash-5.1# initdb
initdb: error: no data directory specified
You must identify the directory where the data for this database system
will reside.  Do this with either the invocation option -D or the
environment variable PGDATA.
bash-5.1# psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?
bash-5.1# 
bash-5.1# nano import_db.sh 

このエラーはなぜ発生しますか? psqlが利用できないのはなぜですか?

ベストアンサー1

いいですね。これはすべてSlackBuildによって実行され、パッケージに含める必要があります。

パスワード:

デフォルトのデータベースディレクトリ

Postgresユーザーのホームディレクトリとして/var/lib/pgsqlを使用するとします。

mkdir -p $PKG/var/lib/pgsql/$PG_VERSION/data chown -R postgres:postgres $PKG/var/lib/pgsql chmod 700 $PKG/var/lib/pgsql

DATADIRの権限はu = rwx(0700)でなければなりません。

chmod 700 $PKG/var/lib/pgsql/$PG_VERSION/data

OPがREADME.SBoのデータベース生成コマンドをrootとして実行する限り、/var/lib/pgsql/14/dataの下のサブディレクトリにも正しい権限が必要です。

デフォルトでは、postgresql DATADIRのすべての内容は、プロセスを所有しているユーザーであるpostgresが所有する必要があります。したがって、chown LOCATION_OF_DATADIRで十分です。パスワード:

chown -R postgres:postgres /var/lib/pgsql

デフォルトのスーパーユーザー以外のpostgresqlユーザーを作成していない場合(ユーザーpostgresなど)、postgresqlに自分のユーザーを追加するなど、データベースを変更するには、ユーザーpostgresでsuを実行して次のようにします。 postgresの代わりに自分のユーザーとしてpostgresqlにログインするコマンドです。

$ su -
# su postgres
$ createuser your_username

Linuxセキュリティモデルの一部は、最小特権原則に基づいて動作します。ほとんどのプロセスは、rootではなくシステムユーザーとして実行されます。 /etc/passwdファイルを見ると、ルート、一般ユーザー以外に多くのユーザーがいるが、これらがまさにシステムユーザーである。サービスを実行するのに十分な権限しかありません。 postgresqlのシステムユーザーはpostgresです。データベースディレクトリはユーザーpostgresが所有し、読み取り/書き込み権限のみを持ちます。

システムユーザーには通常パスワードがないため、まずrootとしてログインしてからsu postgres -c initdb ...を実行する必要があります。

または単にルートから始めてください

su postgres initdb ...

おすすめ記事