対象者
ポスグレを起動できない人
postgres: could not access directory "/usr/local/var/postgres": No such file or directory Run initdb or pg_basebackup to initialize a PostgreSQL data directory. このエラーが出力される人
結論
このコマンドでポスグレを初期化し
initdb -D ~/postgres_data
↓のコマンドでポスグレが起動できました。
brew services start postgresql
↑homebrewでポスグレをインストールした人はこのコマンドでDBを実行できるみたいです。
エラー原因
エラーは、PostgreSQLのデータディレクトリが見つからないことを示しています。 デフォルトでは/usr/local/var/postgresこのパス配下にデータベース起動のための必要なファイル等が作成されるみたいですが私の場合なぜか作成されていませんでした。そこで
initdb -D ~/postgres_data
このコマンドでルートディレクトリ配下にpostgres_dataというDB起動に必要なディレクトリを作成しました。またコマンドを ↓実行すると初期化に成功したみたい
The files belonging to this database system will be owned by user "umekin". This user must also own the server process. The database cluster will be initialized with locale "ja_JP.UTF-8". The default database encoding has accordingly been set to "UTF8". initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8" The default text search configuration will be set to "simple". Data page checksums are disabled. creating directory /Users/umekin/postgres_data ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Asia/Tokyo 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 /Users/umekin/postgres_data -l logfile start