记录:PostgreSQL
以下为中文翻译:请参考
- https://wiki.postgresql.org/wiki/Apt
操作步骤
sudo apt-get install curl ca-certificates gnupg
# 鍵の追加
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# リポジトリの追加
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# 最新の12をインストール
sudo apt install -y postgresql-12
# 起動
sudo systemctl start postgresql
连接
sudo -s
# postgresユーザーになる
su - postgres
# postgresユーザとしてDBにログイン
psql
- デフォルトのポート番号は 5432
进行操作
- createdb
# DB一覧確認
psql -l
# DB作成
createdb test1
# DB一覧確認
psql -l
- SQLによるダンプ,リストア
# リストア
psql dbname < infile
# リストア (pg_restore)
pg_restore -d test1 /tmp/infile
# show tablesの代わり
\dt
# 縦に表示
\x
select * from table1;
家庭目录
- /var/lib/postgresql/
其他
- サーバーへの接続方法
psql -U postgres -d postgres -h postgres13
-
- 接続上の注意
postgresql 13にはpostgresql 12からしか接続ができない(OIDがなくなったため。)
forumdb=# \d categories
错误: 列c.relhasoids不存在
第1行: …, c.relhasindex, c.relhasrules, c.relhastriggers, c.relhasoi…
-- テーブルの作成方法
CREATE TABLE table1 (id integer, name varchar(10));
-
- 設定ファイル
~/.psqlrc
kikuchi@kvm:~/a/postgres$ cat docker-compose.yml
version: '3'
services:
p13:
image: postgres:13
container_name: postgres13
environment:
- POSTGRES_PASSWORD=password
p12:
image: postgres:12
container_name: postgres12
environment:
- POSTGRES_PASSWORD=password