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 1 year has passed since last update.

PostgreSQL備忘録

Last updated at Posted at 2022-07-19

copyと\copy

copyと\copyで挙動が変わる。

copyコマンドはサーバー側、つまりLinuxのユーザpostgresで実行される。file.csvに対してpostgresユーザーの権限がないとエラーになる。

NG
db=# copy split from 'file.csv' with csv;
ERROR:  ファイルを読み取り用にオープンできませんでした: 許可がありません

\copyコマンドはクライアント側、psqlを実行しているユーザーの権限で実行される。file.csvに対してpsqlを実行しているユーザーの権限があれば実行できる。

OK
db=# \copy split from 'file.csv' with csv;

外部接続

二段階の認証になっていて、2つの設定ファイルがある

  • pg_hba.conf
    • データベースやユーザ単位で設定できる
  • postgresql.conf
    • IPアドレスで接続元を制限する
pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD
# localは同一ホスト内通信
local   all             all                                     peer
# 以下TYPEがhostなのでTCP/IPの設定
host    all             all             127.0.0.1/32            trust
METHOD 意味
trust 認証なし
peer postgresqlのユーザー名とlinuxのユーザー名が同じでないと拒否する
md5 md5(ハッシュ値)を使ったパスワード認証
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?