LoginSignup
16
22

More than 5 years have passed since last update.

postgresql よく使うコマンド集

Last updated at Posted at 2017-02-12
  • postgresql操作(OSはCentOS7を想定)
操作 コマンド
postgresqlインストール確認 rpm -qa | grep postgres
postgresql起動 pg_ctl start -w
postgresql起動確認 ps -ef | grep postgres
postgresql停止 pg_ctl stop -m fast
postgresユーザのパスワード変更 passwd postgres
  • データベース操作
操作 コマンド
データベースへ接続 psql <DB_NAME>
データベースから出る \q
データベース一覧表示 \l
データベースの切り替え \connect <DB_NAME>
データベースの作成 create database <DB_NAME>;
  • スキーマ操作
操作 コマンド
スキーマ作成 create schema <SCHEMA_NAME>;
スキーマ確認 select current_schema;
スキーマ一覧 \dn
スキーマ変更 set search_path to <SCHEMA_NAME>;
  • テーブル操作
操作 コマンド
テーブル一覧表示(viewやsequenceも含む) \d
テーブル一覧表示 \dt
テーブルのスキーマの詳細を表示 \d <TABLE_NAME>
テーブルの作成 create table <TABLE_NAME> (<column_name> <column_type>);
テーブルの作成例 create table people (name VARCHAR(255));
16
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
22