psqlでtimingコマンドを実行すると、SQLの実行時間を計測できる
DB=> \timing Timing is on.
コマンドを実行した後、SQLを発行すると実行時間が出力される
SELECT relname FROM pg_class WHERE relkind = 'r' AND relname = 'テーブル名';
pg_classには、テーブルや その他の列を保持しているすべての情報が格納されているので、「relkind = ‘r’ 」でテーブルに限定する。
select relname, n_live_tup from pg_stat_user_tables where schemaname='public';
非推奨です
ホスト(親)側で以下の設定
jail_sysvipc_allow="YES"
すぐに動かすなら
# sysctl security.jail.sysvipc_allowed=1
allow.sysvipc=1;
GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER } [, ...] | ALL [ PRIVILEGES ] } ON { [ TABLE ] TABLE_NAME [, ...] | ALL TABLES IN SCHEMA schema_name [, ...] } TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
GRANT SELECT ON ALL TABLES IN SCHEMA public TO RoleName;
インスタンス、DB、ユーザ単位で参照モードに設定することが可能
postgresql.conf
default_transaction_read_only=on
service postgresql restart
alter database DB名 set default_transaction_read_only = on;
alter role role名 set default_transaction_read_only = on;
SELECT rolname, relname, crud FROM (SELECT r.oid, r.rolname, c.relname, ((CASE WHEN has_table_privilege(r.oid, c.oid, 'INSERT') THEN 'C' ELSE ' ' END) || (CASE WHEN has_table_privilege(r.oid, c.oid, 'SELECT') THEN 'R' ELSE ' ' END) || (CASE WHEN has_table_privilege(r.oid, c.oid, 'UPDATE') THEN 'U' ELSE ' ' END) || (CASE WHEN has_table_privilege(r.oid, c.oid, 'DELETE') THEN 'D' ELSE ' ' END)) AS crud FROM pg_roles r, pg_class c WHERE c.relkind = 'r' AND r.rolcanlogin = TRUE AND relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname NOT IN ('pg_catalog','information_schema','pg_toast')) ) t ORDER BY rolname, relname ;
こんな感じで表示される
rolname | relname | crud ----------------+-----------------+------ postgres | table_name | CRUD admin | table_name | CRUD readonly | table_name | R
postgresql.confのlc_messages を変更すれば治る
lc_messages = 'ja_JP.UTF-8' ↓ lc_messages = 'C'
CentOSなどでインストールした場合、OSのロケールが日本語のためPostgreSQLのログ出力も日本語でインストールされている
psqlで
postgres=# show lc_messages; lc_messages ------------- ja_JP.UTF-8 (1 行)
postgres=# show lc_messages; lc_messages ------------- C (1 行)
psqlコマンドを確認する
# psql --version
version関数で確認する方法
db01=# SELECT version();
標準では9.2
# yum -y localinstall https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
# yum install postgresql96-server