Linux7.8環境下的原始碼安裝部署PG14.8

pingdanorcale發表於2024-01-03

1.建立目錄
   # mkdir -p /data/pgsql
   # mkdir -p / data/pgsql/data

2.安裝依賴包
   # yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel  python36-devel gcc-c++ openssl-devel cmake make

3.下載安裝介質

postgresql.org/ftp/source/v14.8/

  上傳到 /data

5. 建立postgresql使用者
    # useradd postgres

6.設定資料目錄
    # chown postgres:postgres -R   /data/pgsql

7 .設定postgres使用者環境變數
    # su - postgres
    $ vi .bash_profile

    export PATH

    export PGHOME=/data/pgsql

    export PGDATA=/data/pgsql/data

    xport GG_HOME=/data/ogg

    export PATH=$PGHOME/bin:$PATH:$GG_HOME/bin

8.解壓 安裝源包
     cd /data
    tar -xvf postgresql-14.8.tar.gz

9 .安裝配置
  cd /data/postgresql-14.8
   ./configure --prefix=/ data/pgsql --with-wal-blocksize=8 --with-segsize=1 --with-blocksize=8

10.編譯  安裝
    $ make
    make install

11 .安裝擴充套件
    export PATH= /data/pgsql/bin:$PATH
    cd /data/postgresql-14.8/contrib
    make all
    make install

12. 初始化資料庫

postgres@pgdb bin]$ ./initdb  -D /data/pgsql/data/

The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.


The database cluster will be initialized with locale "zh_CN.UTF-8".

The default database encoding has accordingly been set to "UTF8".

initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"

The default text search configuration will be set to "simple".


Data page checksums are disabled.


fixing permissions on existing directory /data/pgsql/data ... ok

creating subdirectories ... ok

selecting dynamic shared memory implementation ... posix

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

selecting default time zone ... PRC

creating configuration files ... ok

running bootstrap script ... ok

performing post-bootstrap initialization ... ok

syncing data to disk ... ok


initdb: warning: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the option -A, or

--auth-local and --auth-host, the next time you run initdb.


Success. You can now start the database server using:


    ./pg_ctl -D /data/pgsql/data/ -l logfile start

13. 修改引數

pg_hba.conf 

host      all           all              0.0.0.0/0              trust

listen_addresses = '*'          # what IP address(es) to listen on;

                                        # comma-separated list of addresses;

                                        # defaults to 'localhost'; use '*' for all

                                        # (change requires restart)

port = 5432                             # (change requires restart)

max_connections = 100                   # (change requires restart)

#superuser_reserved_connections = 3     # (change requires restart)

#unix_socket_directories = '/tmp'       # comma-separated list of directories

unix_socket_directories = '/data/pgsql/run'

                                        # (change requires restart)

#unix_socket_group = ''                 # (change requires restart)

#unix_socket_permissions = 0777         # begin with 0 to use octal notation

                                        # (change requires restart)




附:

自動啟動指令碼

1.

[root@pgdb system]# cat /etc/systemd/system/postgresql.service 

[Unit]

Description=PostgreSQL Database Server

After=network.target

[Service]

Type=forking

User=postgres

Group=postgres

Environment=PGPORT=5432

Environment=PGDATA=/data/pgsql/data

1OOMScoreAdjust=-1000

# 啟動命令

ExecStart=/data/pgsql/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300

# 重新載入

ExecReload=/data/pgsql/bin/pg_ctl reload -D ${PGDATA} -s

# 停止程式

ExecStop=/data/pgsql/bin/pg_ctl  stop -D ${PGDATA} -s -m fast

KillMode=mixed

KillSignal=SIGINT

TimeoutSec=0

PrivateTmp=true

[Install]

WantedBy=multi-user.target

 2.過載systemctl服務

@pgdb ~]$systemctl daemon-reload 

3. 啟動postgresql服務

@pgdb ~]$ sudo systemctl start postgresql.service

4.判斷服務是否啟動,這裡提示成功啟動

@pgdb ~]$ systemctl is-active postgresql.service 

active

5. 也可以透過此命令判斷服務狀態

@pgdb ~]$  systemctl status postgresql.service

6. 停止postgresql服務

pgdbt ~]$  systemctl stop postgresql.service

7. 如果啟動配置失敗,也可以透過journalctl命令檢視日誌查詢原因

pgdb ~]$ journalctl -u postgresql.service 

設定開機自啟動


來自 “ ITPUB部落格 ” ,連結:https://blog.itpub.net/10201716/viewspace-3002437/,如需轉載,請註明出處,否則將追究法律責任。

相關文章