Postgresql ソース コードのコンパイルとインストール (linux-postgresql13.8)

Postgresql ソース コードのコンパイルとインストール (linux-postgresql13.8)

1. インストールパッケージをダウンロードする

postgresql官方下载地址:https://www.postgresql.org/ftp/source/

2. 環境整備

1. ユーザープロセスの最大数を変更する

cat >> /etc/security/limits.conf << 'EOF'
* soft     nproc          65535
* hard     nproc          65535
* soft     nofile         65535
* hard     nofile         65535
EOF

2. 一般ユーザーの変更

cat >> /etc/security/limits.d/90-nproc.conf << 'EOF'

*          soft     nproc          65535
*          hard     nproc          65535
*          soft     nofile         65535
*          hard     nofile         65535
EOF

3. ファイルハンドルの数を変更する

cat >> /etc/sysctl.conf << 'EOF'
fs.file-max = 65536
EOF

4. 検証

 ulimit -a

5. インストールの依存関係

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel  python-devel gcc-c++ openssl-devel cmake perl python36 tcl openssl-devel ncurses-devel openldap pam

3. インストール手順

解凍する

tar -zxvf postgresql-13.8.tar.gz

インストールディレクトリを入力してください

cd postgresql-13.8

コンパイルされたファイルを生成する

/home/pgsql/ はインストール パスであり、必要に応じて変更できます。

./configure \
--prefix=/home/pgsql \
--bindir=/home/pgsql/bin \
--with-pgport=5432 \
--with-wal-blocksize=16 \
--with-segsize=1 \
--with-blocksize=8 \
--with-libedit-preferred \
--with-perl \
--with-openssl \
--with-libxml \
--with-libxslt \
--enable-thread-safety

コンパイル

make -j4 

インストール

make -j4 install

postgresqlユーザーを作成し、

useradd postgres

データ保存ディレクトリを作成し、権限を付与する

mkdir /home/pgsql/data
chown postgres.postgres -R /home/pgsql

ユーザーを切り替える

su - postgres

環境変数を設定する

cat >>.bash_profile EOF
export PGDATA=/home/pgsql/data
export PGHOME=/home/pgsql/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
export PATH=$PATH:$PGHOME/bin/
EOF

環境変数が有効になる

source .bash_profile

データベースを初期化する

su - postgres

initdb

postgresql.conf ファイルの構成パラメータ

cat >> /home/pgsql/data/postgresql.conf <<'EOF'
listen_addresses = '*'
port=5432
unix_socket_directories='/home/pgsql/data'
wal_level = logical
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_timezone = 'Asia/Shanghai'
timezone = 'Asia/Shanghai'
max_wal_size = 1GB
min_wal_size = 80MB
dynamic_shared_memory_type = posix      # the default is the first option
shared_buffers = 128MB                  # min 128kB
max_connections = 1000                   # (change requires restart)
datestyle = 'iso, ymd'
lc_messages = 'zh_CN.UTF-8'                     # locale for system error message  # strings
lc_monetary = 'zh_CN.UTF-8'                     # locale for monetary formatting
lc_numeric = 'zh_CN.UTF-8'                      # locale for number formatting
lc_time = 'zh_CN.UTF-8'                         # locale for time formatting
default_text_search_config = 'pg_catalog.simple'
EOF

pg_hba.conf ファイルのリモート ログイン設定パラメータ

cat   > /home/pgsql/data/pg_hba.conf << EOF
# TYPE  DATABASE    USER    ADDRESS       METHOD
local     all       all                    trust
local   replication     all                                     trust
host      all       all   127.0.0.1/32     trust
host      all       all    0.0.0.0/0        md5
host    replication     all    127.0.0.1/32    trust
host   replication  all    0.0.0.0/0        md5
EOF

システムサービスの設定 (root ユーザーを使用)

cat > /etc/systemd/system/postgresql-13.service <<'EOF'
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGPORT=5432
Environment=PGDATA=/home/pgsql/data
OOMScoreAdjust=-1000
ExecStart=/home/pgsql/bin/pg_ctl start -D ${
    
    PGDATA} -s -o '-p ${
    
    PGPORT}' -w -t 300
ExecStop=/home/pgsql/bin/pg_ctl stop -D ${
    
    PGDATA} -s -m fast
ExecReload=/home/pgsql/bin/pg_ctl reload -D ${
    
    PGDATA} -s
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0
[Install]
WantedBy=multi-user.target
EOF

システム環境変数を構成する

export PATH=$PATH:/home/pgsql/bin/

環境変数が有効になる

source /etc/profile

ブートセルフスタート

systemctl status postgresql-13
systemctl enable postgresql-13

バージョン情報を表示する

psql --version

データベース テストにログインします。デフォルトのポートは 5432 です。

psql -h 127.0.0.1 -U postgres

パスワードを変更する

\password
或
alter user postgres with password '密码'

インストールを完了してください!

おすすめ

転載: blog.csdn.net/LSW1737554365/article/details/129789740
おすすめ