PostgreSQLの基本操作
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[PostgreSQL]]
~
*ログイン・ログアウト [#a7f2a35b]
# su postgres
$ psql
$ ¥q
*バージョン確認 [#n1b571ff]
# su postgres
$ psql
$ select version();
PostgreSQL 8.1.23 on i686-pc-linux-gnu, compiled by GCC...
(1 row)
*PostgreSQL 起動 [#s49b8d04]
[postgres@www ~]$ pg_ctl start -D /home/postgres/data -w
-D initdbしたディレクトリ、起動中の場合はps aux | grep p...
-w 起動もしくは停止処理が終了するのを待ちます。60秒でタ...
*PostgreSQL停止 [#ha608020]
[postgres@www ~]$ pg_ctl stop -D /home/postgres/data
*PostgreSQL再起動 [#ke01e354]
[postgres@www ~]$ pg_ctl restart -D /home/postgres/data
*PostgreSQL設定ファイル再読み込み [#ocf771da]
[postgres@www ~]$ pg_ctl reload -D /home/postgres/data
*ユーザーの確認 [#b2a5b411]
[postgres@www ~]$ psql
postgres=# select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatupd...
----------+----------+-------------+----------+---------...
postgres | 10 | t | t | t ...
*ユーザー作成 [#d9bbb0a8]
[postgres@www ~]$ createuser -U postgres -P
Enter name of role to add: hogeuser
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? ...
[postgres@www ~]$ psql
postgres=# select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatup...
----------+----------+-------------+----------+---------...
postgres | 10 | t | t | t ...
hogeuser | 16390 | f | f | f ...
(2 rows)
*データベースの確認 [#i74e089e]
その1
[postgres@www ~]$ psql -l
Name | Owner | Encoding | Collation | Ctype | ...
-----------+----------+-----------+-----------+-------+-...
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
template1 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
その2
[postgres@www ~]$ psql
postgres=# select oid, datname from pg_database;
oid | datname
-------+-----------
1 | template1
11866 | template0
11874 | postgres
(3 rows)
oidは/home/postgres/data/baseの下にある。
*データベースの作成 [#z3a8038e]
[postgres@www ~]$ createdb -U postgres testdb01;
[postgres@www ~]$ psql -l
List of databases
Name | Owner | Encoding | Collation | Ctype | ...
-----------+----------+-----------+-----------+-------+-...
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
template1 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
testdb01 | postgres | SQL_ASCII | C | C |
(4 rows)
*データベースの表示 [#qe39bee8]
[postgres@www ~]$ psql
postgres=# ¥l
List of databases
Name | Owner | Encoding | Collation | Ctype | ...
-----------+----------+-----------+-----------+-------+-...
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
template1 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
testdb01 | postgres | SQL_ASCII | C | C |
(4 rows)
*データベースの選択 [#sbd6e62c]
postgresq# ¥c testdb
You are now connected to database "testdb".
*テーブル一覧表示 [#p5e262ed]
testdb# ¥dt
終了行:
[[PostgreSQL]]
~
*ログイン・ログアウト [#a7f2a35b]
# su postgres
$ psql
$ ¥q
*バージョン確認 [#n1b571ff]
# su postgres
$ psql
$ select version();
PostgreSQL 8.1.23 on i686-pc-linux-gnu, compiled by GCC...
(1 row)
*PostgreSQL 起動 [#s49b8d04]
[postgres@www ~]$ pg_ctl start -D /home/postgres/data -w
-D initdbしたディレクトリ、起動中の場合はps aux | grep p...
-w 起動もしくは停止処理が終了するのを待ちます。60秒でタ...
*PostgreSQL停止 [#ha608020]
[postgres@www ~]$ pg_ctl stop -D /home/postgres/data
*PostgreSQL再起動 [#ke01e354]
[postgres@www ~]$ pg_ctl restart -D /home/postgres/data
*PostgreSQL設定ファイル再読み込み [#ocf771da]
[postgres@www ~]$ pg_ctl reload -D /home/postgres/data
*ユーザーの確認 [#b2a5b411]
[postgres@www ~]$ psql
postgres=# select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatupd...
----------+----------+-------------+----------+---------...
postgres | 10 | t | t | t ...
*ユーザー作成 [#d9bbb0a8]
[postgres@www ~]$ createuser -U postgres -P
Enter name of role to add: hogeuser
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? ...
[postgres@www ~]$ psql
postgres=# select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatup...
----------+----------+-------------+----------+---------...
postgres | 10 | t | t | t ...
hogeuser | 16390 | f | f | f ...
(2 rows)
*データベースの確認 [#i74e089e]
その1
[postgres@www ~]$ psql -l
Name | Owner | Encoding | Collation | Ctype | ...
-----------+----------+-----------+-----------+-------+-...
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
template1 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
その2
[postgres@www ~]$ psql
postgres=# select oid, datname from pg_database;
oid | datname
-------+-----------
1 | template1
11866 | template0
11874 | postgres
(3 rows)
oidは/home/postgres/data/baseの下にある。
*データベースの作成 [#z3a8038e]
[postgres@www ~]$ createdb -U postgres testdb01;
[postgres@www ~]$ psql -l
List of databases
Name | Owner | Encoding | Collation | Ctype | ...
-----------+----------+-----------+-----------+-------+-...
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
template1 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
testdb01 | postgres | SQL_ASCII | C | C |
(4 rows)
*データベースの表示 [#qe39bee8]
[postgres@www ~]$ psql
postgres=# ¥l
List of databases
Name | Owner | Encoding | Collation | Ctype | ...
-----------+----------+-----------+-----------+-------+-...
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
template1 | postgres | SQL_ASCII | C | C | ...
| | | | | ...
testdb01 | postgres | SQL_ASCII | C | C |
(4 rows)
*データベースの選択 [#sbd6e62c]
postgresq# ¥c testdb
You are now connected to database "testdb".
*テーブル一覧表示 [#p5e262ed]
testdb# ¥dt
ページ名: