0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ubuntuにPostgresをインストール

Last updated at Posted at 2023-03-15

postgresユーザの作成

$ sudo adduser postgres
$ sudo passwd postgres

公式に概ね従ってpostgres最新版をインストール
https://www.postgresql.org/download/linux/ubuntu/

# ダウンロード予定のバージョンを確認
$ sudo apt info postgresql
Package: postgresql
Version: 14+238               # 古い

# Create the file repository configuration:
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:
$ sudo apt update

# ダウンロード予定のバージョンを確認
$ sudo apt info postgresql
Package: postgresql
Version: 15+248.pgdg22.04+1   # 新しい

# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
$ sudo apt -y install postgresql

途中で以下のエラーが出た場合は

Setting up postgresql (15+248.pgdg22.04+1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...
Running kernel seems to be up-to-date.
Failed to check for processor microcode upgrades.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.

これで対処

$ sudo apt -y remove postgresql
$ apt purge needrestart
$ sudo apt -y install postgresql

インストール場所を探す

$ sudo find / -name postgresql
/var/log/postgresql
/var/lib/postgresql
/usr/lib/postgresql
/usr/share/doc/postgresql
/usr/share/postgresql
/etc/postgresql
/run/postgresql

postgresql起動

$ sudo systemctl enable postgresql
$ sudo systemctl start postgresql

DB初期設定

sudo su - postgres
vi .profile
export PGHOME=/usr/lib/postgresql/15
export PGDATA=/var/lib/postgresql/15/data
export PGLIB=$PGHOME/lib
export LD_LIBRARY_PATH=$PGHOME/lib
export PATH=$PATH:$PGHOME/bin

source ~/.profile
initdb -E UTF8 --no-locale

DB起動
pg_ctl start

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?