PostgreSQL実験室/データベースクラスタ初期設定
- 記事一覧 PostgreSQL実験室
設定ファイル
設定ファイル変更後は, potgresqlサーバーを再起動します.
postgresql.conf
- 変更前
#listen_addresses = 'localhost' # what IP address(es) to listen on; - 変更後
listen_addresses = '*' # what IP address(es) to listen on;
pg_hba.conf
-
変更前
# IPv4 local connections: host all all 127.0.0.1/32 scram-sha-256 # IPv6 local connections: host all all ::1/128 scram-sha-256 -
変更後
# IPv4 local connections: host all all 127.0.0.1/32 scram-sha-256 host all all 192.168.56.0/24 scram-sha-256 # IPv6 local connections: host all all ::1/128 scram-sha-256
postgresユーザーパスワード
postgresユーザーのパスワードを設定します.
- コマンド
$ LC_ALL=C psql -d postgres -U postgres ... postgres@postgres=# \password postgres Enter new password for user "postgres": ******** Enter it again: ******** postgres@postgres=# \q
テーブル空間格納ディレクトリ
ユーザーデータ格納用のテーブル空間を作成するため, ディレクトリを作成します.
- コマンド
PGDB_TBLSPC_ROOT=/pgdata PGDB_VERSION=17 PGDB_TBLSPC_DATA=${PGDB_TBLSPC_ROOT}/${PGDB_VERSION}/tblspc # # make directories # mkdir -p ${PGDB_TBLSPC_ROOT} # Tablespace for non-partition tables mkdir -p ${PGDB_TBLSPC_DATA}/dbx_tbs1 # Tablespace for partition tables mkdir -p ${PGDB_TBLSPC_DATA}/dbx_ptbs1 chown -R postgres.postgres ${PGDB_TBLSPC_ROOT} chmod -R 700 ${PGDB_TBLSPC_ROOT} - 確認
$ tree -pug /pgdata [drwx------ postgres postgres] /pgdata `-- [drwx------ postgres postgres] 17 `-- [drwx------ postgres postgres] tblspc |-- [drwx------ postgres postgres] dbx_ptbs1 `-- [drwx------ postgres postgres] dbx_tbs1
ユーザー作成
パスワードは適切に設定します.
-
コマンド
$ LC_ALL=C psql -d postgres -U postgres ... postgres@postgres=# create user dbxadmin password '********' superuser createdb createrole; CREATE ROLE create user dbxowner1 password '********' login; CREATE ROLE create user dbxowner2 password '********' login; CREATE ROLE create user dbxuser1 password '********' login; CREATE ROLE create user dbxuser2 password '********' login; CREATE ROLE postgres@postgres=# commit; COMMIT postgres@postgres=# \q
テーブル空間作成
ユーザーデータ格納用のテーブル空間dbx_tbs1,dbx_ptbs1を作成します.
-
コマンド
$ LC_ALL=C psql -d postgres -U postgres ... postgres@postgres=# create tablespace dbx_tbs1 owner dbxadmin location '/pgdata/17/tblspc/dbx_tbs1'; CREATE TABLESPACE postgres@postgres=# grant create on tablespace dbx_tbs1 to dbxowner1; GRANT postgres@postgres=# grant create on tablespace dbx_tbs1 to dbxowner2; GRANT postgres@postgres=# create tablespace dbx_ptbs1 owner dbxadmin location '/pgdata/17/tblspc/dbx_ptbs1'; CREATE TABLESPACE postgres@postgres=# grant create on tablespace dbx_ptbs1 to dbxowner1; GRANT postgres@postgres=# grant create on tablespace dbx_ptbs1 to dbxowner2; GRANT postgres@postgres=# commit; COMMIT postgres@postgres=# \q