カテゴリー【PostgreSQL、Ubuntu、Debian】
PostgreSQLをソースコードからインストールしてsystemdのサービスとして動かす
POSTED BY
2023-06-08
2023-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/管理人】
自営業プログラマーです。お仕事ください!ご連絡は以下アドレスまでお願いします★
【キーワード検索】
【最近の記事】【全部の記事】
CORESERVER v1プランからさくらインターネットスタンダートプランへ引っ越しメモさくらインターネットでPython MecabをCGIから使う
さくらインターネットのPHPでAnalytics-G4 APIを使う
インクルードパスの調べ方
【Git】特定ファイルを除外する.gitignore
【Ubuntu/Debian】NVIDIA関係のドライバを自動アップデートさせない
【Python】Spacyを使用して文章から出発地と目的地を抜き出す
HomeBrewでApache2を入れて自動起動つきで動かしPHPモジュールと連携する
macOSに標準付属のApacheを自動起動つきで動かす
HomeBrewでPostgreSQLを入れて自動起動つきで動かす
【人気の記事】【全部の記事】
【Windows10】リモートデスクトップ間のコピー&ペーストができなくなった場合の対処法進研ゼミチャレンジタッチをAndroid端末化する
Windows版Google Driveが使用中と言われアンインストールできない場合
Windows11+WSL2でUbuntuを使う【2】ブリッジ接続+固定IPの設定
【C/C++】小数点以下の切り捨て・切り上げ・四捨五入
【PHP】Mail/mimeDecodeを使ってメールの中身を解析(準備編)
【Apache】サーバーに同時接続可能なクライアント数を調整する
【Hackintosh】Z370 MORTARにmacOS Sonomaをインストール
cannot guess build type; you must specify oneと言われた場合
【MinGW】Windowsでgcc/g++コンパイラを使って開発する
【カテゴリーリンク】
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
ウマ娘
将棋
ドラレコ