Database JUNKY

MySQL,MariaDBを中心としたブログです

データベースユーザーを作成する

ここあたりを参考にしてみます。 http://www.postgresql.jp/document/pg732doc/reference/app-createuser.html

今回、作成しようとしているユーザーは、デフォルトのpostgresユーザーではなくて、dbuserという新規のアカウントです。 ちょっと手順があっているかどうか微妙ですけど、やってみます。

  1. linux のアカウントを作成します。 # useradd dbuser # passwd dbuser Changing password for user dbuser. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.
  2. postgres ユーザーにスイッチする。 # su - postgres -bash-3.2$
  3. データベースユーザーをクリエイトする -bash-3.2$ createuser -adP dbuser Enter password for new role: Enter it again: CREATE ROLE
  4. 作成したアカウントでpostgresが利用できるか確認する。 # su - dbuser $ psql -l List of databases    Name    |  Owner   | Encoding -----------+----------+----------  postgres  | postgres | UTF8  template0 | postgres | UTF8  template1 | postgres | UTF8 (3 rows)
  5. 上記アカウントで、template1に接続できるか確認する。 $ psql template1 dbuser Welcome to psql 8.1.11, the PostgreSQL interactive terminal. Type:  \copyright for distribution terms        \h for help with SQL commands        \? for help with psql commands        \g or terminate with semicolon to execute query        \q to quit
  6. 接続の確認が取れたので切断する template1=# \q