カテゴリー【PostgreSQL、Ubuntu、Debian】
PostgreSQLをソースコードからインストールしてsystemdのサービスとして動かす
POSTED BY
2024-06-08
2024-06-08



Ubuntu/Debianでは/etc/init.d + chkconfigではなく、/lib/systemd/system + systemctlの方式を取る。
aptでパッケージインストールしたサーバーソフトならそのまま自動でsystemdに登録されるので問題ないが、ソースコードからコンパイルしてインストールしたサーバーソフトは、手動でサービスファイルを作成しsystemdに登録して起動・停止を行う必要がある。
https://www.postgresql.jp/document/9.6/html/server-start.html
を参考にして、Ubuntu ServerにPostgreSQL14.3をソースからインストール・systemdに登録・起動・停止・自動起動まで行う。
/usr/local/pgsqlにインストール
--with-systemdをつけるのが最大のポイント。
sudo -s apt install build-essential libreadline-dev zlib1g-dev libsystemd-dev cd /usr/local/src wget https://ftp.postgresql.org/pub/source/v14.3/postgresql-14.3.tar.gz tar xvfzp postgresql-14.3.tar.gz cd postgresql-14.3 ./configure --prefix=/usr/local/pgsql --with-systemd make make install
postgresユーザ・グループ・データ初期化
sudo -s groupadd postgres useradd -d /usr/local/pgsql -g postgres postgres chown -Rh postgres:postgres /usr/local/pgsql sudo -s -u postgres cd /usr/local/pgsql mkdir data chmod go-rwx data ./bin/initdb –no-locale -D /usr/local/pgsql/data
/lib/systemd/system/postgresql.serviceの作成
以下の内容で作成する。
[Unit] Description=PostgreSQL database server Documentation=man:postgres(1) [Service] Type=notify User=postgres ExecStart=/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data ExecReload=/bin/kill -HUP $MAINPID KillMode=mixed KillSignal=SIGINT TimeoutSec=0 [Install] WantedBy=multi-user.target
systemctlによる起動・終了・自動起動登録
ここまでくれば、あとはsystemctlが認識する。
確認
systemctl status postgresql
起動・確認
systemctl start postgresql systemctl status postgresql
終了・確認
systemctl stop postgresql systemctl status postgresql
自動起動登録・確認
systemctl enable postgresql systemctl status postgresql
これでマシン起動時に自動的にpostgresqlが立ち上がり、終了時自動でstopしてくれる。
自動起動登録をやめるにはsystemctl disable postgresqlとすればよい。
Android
iPhone/iPad
Flutter
MacOS
Windows
Debian
Ubuntu
CentOS
FreeBSD
RaspberryPI
HTML/CSS
C/C++
PHP
Java
JavaScript
Node.js
Swift
Python
MatLab
Amazon/AWS
CORESERVER
Google
仮想通貨
LINE
OpenAI/ChatGPT
IBM Watson
Microsoft Azure
Xcode
VMware
MySQL
PostgreSQL
Redis
Groonga
Git/GitHub
Apache
nginx
Postfix
SendGrid
Hackintosh
Hardware
Fate/Grand Order
ウマ娘
将棋
ドラレコ
※本記事は当サイト管理人の個人的な備忘録です。本記事の参照又は付随ソースコード利用後にいかなる損害が発生しても当サイト及び管理人は一切責任を負いません。
※本記事内容の無断転載を禁じます。
※本記事内容の無断転載を禁じます。
【WEBMASTER/管理人】
自営業プログラマーです。お仕事ください!ご連絡は以下アドレスまでお願いします★
【キーワード検索】
【最近の記事】【全部の記事】
ファイアウォール内部のOpenAPI/FastAPIのdocsを外部からProxyPassで呼ぶDebian 12でsshからshutdown -h nowしても電源が切れない場合
【Windows&Mac】アプリのフルスクリーンを解除する方法
Debian 12でtsコマンドが見つからないcommand not found
Debian 12でsyslogやauth.logが出力されない場合
Debian 12で固定IPアドレスを使う設定をする
Debian 12 bookwormでNVIDIA RTX4060Ti-OC16GBを動かす
【Debian】apt updateでCD-ROMがどうのこうの言われエラーになる場合
【Debian】あるはずのコマンドが無いと言われる場合
nohupで常時起動したPythonスクリプトがログを出力しない場合
【人気の記事】【全部の記事】
進研ゼミチャレンジタッチをAndroid端末化するWindows11+WSL2でUbuntuを使う【2】ブリッジ接続+固定IPの設定
【Windows10】リモートデスクトップ間のコピー&ペーストができなくなった場合の対処法
Windows版Google Driveが使用中と言われアンインストールできない場合
【Apache】サーバーに同時接続可能なクライアント数を調整する
【C/C++】小数点以下の切り捨て・切り上げ・四捨五入
【ひかり電話+VoIPアダプタ】LANしか通ってない環境でアナログ電話とFAXを使う
Intel Macbook2020にBootCampで入れたWindows11 Pro 23H2のBluetoothを復活させる
【OpenSSL1.1】Diffie-Hellman(ディフィ・ヘルマン)方式の鍵交換を行う
Googleファミリーリンクで子供の端末の現在地がエラーで取得できない場合
【カテゴリーリンク】
Android
iPhone/iPad
Flutter
MacOS
Windows
Debian
Ubuntu
CentOS
FreeBSD
RaspberryPI
HTML/CSS
C/C++
PHP
Java
JavaScript
Node.js
Swift
Python
MatLab
Amazon/AWS
CORESERVER
Google
仮想通貨
LINE
OpenAI/ChatGPT
IBM Watson
Microsoft Azure
Xcode
VMware
MySQL
PostgreSQL
Redis
Groonga
Git/GitHub
Apache
nginx
Postfix
SendGrid
Hackintosh
Hardware
Fate/Grand Order
ウマ娘
将棋
ドラレコ