如何在wsl2的Ubuntu20.4上安装postgres

指令列表

sudo apt update
sudo apt install postgresql postgresql-contrib

# postgres起動
sudo /etc/init.d/postgresql start

# postgresユーザで接続
sudo -i -u postgres

# postgresに入れるか検証(はいれたら\qで終了)
psql

# postgresにuser追加し、権限とか聞かれるので確認
createuser --interactive

#psql内に入り、作成したパスワード変更 passwordはdetabase.ymlのdevelopmentに記載されているやつ
psql
alter role username with password 'password'

# user名でDB作成
createdb username

# psqlでユーザ経由で入れるか確認(パスワード入れる)
psql -U username

# developmentのDB作成
createdb development_database -O username
 
# 認証の変更
sudo vi /etc/postgresql/12/main/pg_hba.conf

## 変更前
local all postgres peer
## 変更後
local all postgres md5

如果途中遇到问题,请适时重新启动postgresql。
使用sudo /etc/init.d/postgresql restart。

以下是参考资料。

以下是资料的参考。

以下是可以参考的资料。

以下是可以作为参考的资料。

以下是提供参考的资料。

以下是用作参考的资料。

以下是一个用中文进行的本地化改写:

1. DigitalOcean中的教程:在Ubuntu 20.04上如何安装和使用PostgreSQL
链接:https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-20-04-ja

2. Ryota Take的日本博客:解决PostgreSQL同行验证失败的问题
链接:https://ryotatake.hatenablog.com/entry/2019/05/03/postgresql_peer_authentication_failed

bannerAds