2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PostgreSQLの管理ユーザーでログインしたときに環境変数を自動で反映する設定

2
Posted at

はじめに

OSS-DB Silverの試験勉強の際に、Linuxからリモートログインして勉強するため、.profileと.bashrcファイルを修正し、PATHとPGDATAをログイン時に反映させるように改造しました。

.bachrcファイル

.bashrcファイルに環境変数PATHとPostgreSQLのDBを管理するディレクトリを指す環境変数PGDATAを以下のように設定しました。

export PATH=$PATH:/usr/lib/postgresql/18/bin

export PGDATA=/usr/lib/postgresql/18/main

.profileファイル

PostgreSQLを管理するユーザーとしてpostgresユーザーを作り、sshでログインする際に.bashrcを読み込んでもらうため、以下の設定を追加しました。

#!/usr/bin/bash

if [ -f ~/.bashrc ] ; then
    source .bashrc
fi

ログインした結果

ログインして環境変数をechoで出力した結果です。

postgres@hattori-HP-EliteBook-820-G3:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/postgresql/18/bin
postgres@hattori-HP-EliteBook-820-G3:~$ echo $PGDATA
/usr/lib/postgresql/18/main

最後に

OSS-Silver DBの試験勉強を実機と問題集、両方で実施するための方法を記事にしました。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?