Index ソフト・ハード | PostgreSQL タスク |
機能・要件 構成・方式 タスク 起動・停止 スイッチユーザー ユーザー作成 DB作成 DBバックアップ DBリストア 他ホストから接続 クライアント認証 pgAdmin4 アンインストール postgreSQL導入 DBクラスタ導入 |
PostgreSQLの起動・停止 CentOS $ pg_ctl -w start $ pg_ctl stop $ /usr/pgsql-11/bin/pg_ctl -D /var/lib/pgsql/11/data/ -l testxxxx.log startスイッチユーザー $ sudo -s # su - postgresユーザー作成 ・レプリケーションユーザー作成、権限・パスワード付与 $ psql -c "CREATE ROLE repuser REPLICATION LOGIN PASSWORD 'reppasswd'"・httpユーザー作成、権限付与 $ psql -c "CREATE ROLE http CREATEDB"・ユーザー、権限などを確認 $ psql -c "\du"
ロール名 | 属性 | 所属グループ
-------------+-------------------------------------------------------+--------------
postgres | スーパーユーザ, ロール作成可, DB作成可,
レプリケーション可, RLS のバイパス | {}
repuser | レプリケーション可 | {}
http | DB作成可, ログインできません | {}
データベース作成 $ createdb dbname $ createdbは、利便性のためのラッパプログラム CREATE DATABASEコマンドを実行 引数のないcreatedbは現在のユーザ名のデータベースを作成 参考DBバックアップ ・DBダンプall $ pg_dumpall > outfile・DBダンプ $ pg_dump database名 > backup_file名 $ pg_dump database名 > xxxx.backup $ pg_dump database名 --format=t > xxxx.backup・pgAdmin4 newdb(例)の バックアップFileName 指定(例 bkup20230101.sql)DBリストア ・クラスタごと $ psql -f infile template1・DBリストア $ psql database名 < backup_file名 WindowsでpgAdminを用いる場合は、「--format=t」でのdumpが必要・pgAdmin4 からのファイル $ pg_restore -d newdb bkup20230101.sql他ホストから接続 ・他ホストからの接続を許可 ・「postgresql.conf」設定 「listen_addresses」”local”→”*” 「#port 5432」コメントを外す。・ファイアウォール(CentOS7) # firewall-cmd --add-port=5432/tcp --zone=public --permanentクライアント認証 ・「pg_hba.conf」設定
# PostgreSQLクライアント認証設定ファイル
# ===================================================
# TYPE DATABASE USER ADDRESS METHOD
# "local" はUnixドメインソケット接続専用
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.10.0/24 trust
# IPv6 local connections:
host all all ::1/128 trust
# レプリケーション権限を持つユーザーによる、
# ローカルホストからのレプリケーション接続を許可
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
# ユーザのパスワードを検証するために、
# SCRAM-SHA-256又はMD5認証を実行
host replication repuser 192.168.20.11/32 md5
host replication repuser 192.168.20.12/32 md5
・参考(pg_hba.confファイル) ・参考(クライアント認証) ・「trust認証」でもユーザ・パスワードの制限は適用 pgAdmin4 ・windows版には含まれる。(postgresql-11.11-1-windows-x64.exe) ・Edgeで起動する場合、Edge~設定~言語 「自分が読み取ることができない言語のページの翻訳を提案する」をOFFにする。・~.backup ファイルをリストア xxdb右クリック~Restore...~Formatで、Custom or tar でRestoreできる。アンインストール ・PostgreSQLサービス停止 systemctl stop postgresql13.service・PostgreSQLサービス無効化 systemctl disable postgresql13.service・PostgreSQLのパッケージをすべてアンインストール # rpm -qa | grep postgres 親パッケージを先にアンインストールしようとするとエラーメッセージ rpm -e postgresql13-libs-13.3-1PGDG.rhel7.x86_64 rpm -e postgresql13-13.3-1PGDG.rhel7.x86_64 rpm -e postgresql13-server-13.3-1PGDG.rhel7.x86_64・PostgreSQLのユーザディレクトリを削除 # ls /usr | grep pgsql # rm -rf /usr/pgsql-13/・PostgreSQLのライブラリディレクトリを削除 # ls /var/lib | grep pgsql # rm -rf /var/lib/pgsql・ユーザーpostgresを削除 # cut -d: -f1 /etc/passwd | grep postgres # userdel -r postgres |
All Rights Reserved. Copyright (C) ITCL |