LoginSignup
0
0

postgresqlの初期設定の仕方

Posted at

postgresqlの初期設定のメモ
Ubuntu22.04

以下のコマンドを実行

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo apt -y install postgresql-15

postgres起動

sudo systemctl enable postgresql
sudo systemctl start postgresql

以下でpostgresユーザでpostgresに入る。

psql -U 自分のuser名 -d postgres

/etc/postgresql/15/main/pg_hba.confを編集

# Database administrative login by Unix domain socket
local   all             all                                     password

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256

sudo -u postgres psqlをすると怒られる。

sudo -u postgres psql
postgres=# ALTER USER OSのユーザ PASSWORD 'パスワード';
ERROR:  ロール"OSのユーザ"は存在しません

postgres=# SELECT usename FROM pg_user;
 usename  
----------
 postgres
(1 行)

以下でOSのユーザ名のpostgresユーザ作成

postgres=# CREATE USER OSのユーザ WITH PASSWORD 'パスワード';
CREATE ROLE

postgres=# ALTER USER OSのユーザ WITH SUPERUSER;
ALTER ROLE

postgresql再起動しOSユーザでpostgresqlに入る

sudo systemctl restart postgresql
psql -U OSのユーザ -d postgres
0
0
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
0
0