PostgreSQL のインストール
PostgreSQL をインストールするには、まずパッケージリストを更新します。
sudo apt update sudo apt install postgresql postgresql-contrib postgresql-contrib は便利な追加機能(拡張)が含まれています。例えば uuid-ossp, pgcrypto などです。
インストールされたか確認するには、以下のコマンドを実行します。
psql --version PostgreSQL の起動・停止・再起動
基本的なコマンドは以下のようなものがあります。
# 起動
sudo systemctl start postgresql
# 停止
sudo systemctl stop postgresql
# 再読み込み
sudo systemctl reload postgresql
# 再起動
sudo systemctl restart postgresql
# ステータス確認
sudo systemctl status postgresql 初期ユーザーと接続
PostgreSQL インストール直後は、自動的に OS ユーザー postgres が作成され、同名の DB ユーザーとして使用されます。
postgres ユーザーに切り替えするには、以下のコマンドを実行します。
sudo -i -u postgres psql にログインするには、以下のコマンドを実行します。
psql psql からログアウトするには、以下のコマンドを実行します。
\q postgres ユーザーからログアウトするには、以下のコマンドを実行します。
exit