0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

postgresqlがダウンロードできない(brewがアップデートできないから)

Posted at

状況
僕:最近未経験でプログラマー に転職した
環境 スペック?: iMac (21.5-inch, Late 2012)
   バージョン: 10.15.7(19H1217)

会社でpostgresqlを使う必要が出てきた。
早速調べて、brewが使えることがわかり以下を打ってみた。

$ brew install postgresql

しかしエラー(エラー文はどこかに行ってしまいました...)
その時の最後の方に乗っていたエラーと同じもの↓

Warning: You are using macOS 10.15.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience, as you are running this pre-release version.

OSやpythonのアップデートを行い、もう一度postgresをインストールしようとしたが結果は変わらず。
そこで、brewが最新版では無いのではと考え以下を打ったがエラー

% brew update
touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
error: could not lock config file .git/config: Permission denied
Already up-to-date.

権限関係の問題かと考え、色々試した後以下を打った

sudo chown -R $(whoami) $(brew --prefix)/*

chown : 指定したファイルやディレクトリのユーザー所有権(所有者)やグループ所有権(グループ)を変更する。

-R : 指定したディレクトリとそのディレクトリ以下のファイルやディレクトリの所有権を再起的に変更する

$(~~) : そのコマンドを入力してその出力をそこに書いたものと同じになる

whoami : 自分のユーザー名を表示

brew --prefix : brewのインストール先のアドレス

/* : ディレクトリ内の全て

 $ brew upgrade
     Updating Homebrew..

そうするとupgradeができて、updateのエラー文も変わった。

$ brew update
   Error: 
   homebrew-core is a shallow clone.
   To `brew update`, first run:
   git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
   This command may take a few minutes to run due to the large size of the repository. ...

あとは適宜言われたエラー文に示されたコマンドを打つことで対応できた

$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch –unshallow
python --version                                                           
Python 2.7.16
brew install postgresql   
To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /usr/local/var/postgres
For more details, read:
  https://www.postgresql.org/docs/13/app-initdb.html

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
% psql
psql: error: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
brew services start postgresql
psql                            
psql: error: FATAL:  database "hayano" does not exist

psql -l
                          List of databases
   Name    | Owner  | Encoding | Collate | Ctype | Access privileges 
-----------+--------+----------+---------+-------+-------------------
 postgres  | hayano | UTF8     | C       | C     | 
 template0 | hayano | UTF8     | C       | C     | =c/hayano        +
           |        |          |         |       | hayano=CTc/hayano
 template1 | hayano | UTF8     | C       | C     | =c/hayano        +
           |        |          |         |       | hayano=CTc/hayano
psql postgres
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?