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 Linux 備忘録

Last updated at Posted at 2022-01-24

インストール

sudo apt update
sudo apt install postgresql postgresql-contrib

contrib モジュール とは、限られたユーザ向けだったり、実験的すぎたりして、PostgreSQL 本体に取り込まれていないモジュールのことです。ちなみに contrib は contribution の略で、ユーザから寄贈されたモジュールであるのに由来するものだからでしょう。

ロール

デフォルトでは、Postgresは「ロール」と呼ばれる概念を使用して認証と承認を処理します。

  • インストール時に自動で「postgres」ユーザーが作成される

大まかな流れ

ロールの追加

  1. sudo -u postgres createuser --interactive<
  2. Enter name of role to add: sampleuser001
  3. Shall the new role be a superuser? (y/n) y

DB作成

1.sudo -u 〇〇〇 createdb sampleDB

linux側にユーザーを追加

1.上記で作成したロールと同名のlinuxユーザー(上記例ではsampleuser001)を作成する

DROP DATABASEができない時

 sudo -iu postgres dropdb sampleDB

A5M2で接続

エラー
接続済みの呼び出し先が一定の時間を過ぎても正しく応答しなかったため、接続できませんでした。または接続済みのホストが応答しなかったため、確立された接続は失敗しました。

→SSH接続設定ミス

エラー
 password authentication failed for user "sampleuser001"

→ユーザーにパスワードを設定する

ユーザーにパスワードを設定

sudo su sampleuser001 -c 'psql --username=sampleuser001'
ALTER USER sampleuser001 with encrypted password '××××××××××';

pg_hba.conf設定

/etc/postgresql/12/main/pg_hba.conf
# Database administrative login by Unix domain socket
local   all     sampleuser001     md5

# "local" is for Unix domain socket connections only
local   all             all                                     trust

Posgre再起動

sudo /etc/init.d/postgresql restart
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?