
					  
					    ここでは、お使いのサーバーに、『PostgreSQL 16.3』をインストールする手順を説明します。
					   
						インストール前にご一読ください
						PostgreSQLは、本格的なオープンソースRDBMS(Relational Database Management System)です。
						PostgreSQLのダウンロードはこちら
						PostgreSQLに関する詳細は、「日本PostgreSQLユーザー会」の公式サイトをご参照ください。
					  ご注意
                        desknet's NEOでご利用いただけるPostgreSQLのバージョンは、「動作環境」をご確認の上、インストールを行ってください。
1.パッケージソースの展開
suコマンドにて、rootユーザーにスイッチしてください。					  
		      
					      | 
					        
					          | [guest@xxxxxx guest]# su -Password:
 |  | 
				      
					  ダウンロードサイトからダウンロードしたPostgreSQLのパッケージソースを展開します。ここでは、guestユーザーのホームディレクトリにあるものとします。 
                      
                        
                          | 
                            
                              | [root@xxxxxx guest]# cd /usr/local/src[root@xxxxxx src]# tar zxvf /home/guest/postgresql-16.3.tar.gz
 |  | 
                      
                      展開が完了すると、/usr/local/srcディレクトリ下に「postgresql-16.3」というディレクトリが作成されます。
                      2.パッケージのインストール
						インストールするサーバー環境による構成を行います。
                        
                          
                            | 
                              
                                | [root@xxxxxx guest]# cd postgresql-16.3[root@xxxxxx postgresql-16.3]# ./configure  --prefix /usr/local/pgsql16.3 --without-icu
  ・  ・(中略)  ・  
                                  configure: creating ./config.statusconfig.status: creating GNUmakefile
 config.status: creating src/Makefile.global
 config.status: creating src/include/pg_config.h
 config.status: creating src/include/pg_config_ext.h
 config.status: creating src/interfaces/ecpg/include/ecpg_config.h
 config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
 config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
 config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
 config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
 config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
 
 [root@xxxxxx postgresql-16.3]# |  | 
                      
※ここでは、/usr/local/pgsql16.3にインストールされる構成で説明します。インストール先等変更したい場合には"--prefix"オプションなど、PostgreSQLのインストールガイドをご参照ください。
サーバー上に不足しているパッケージなどがある場合、ここで構成エラーが発生しますので、不足しているパッケージを追加インストールするなどのご対応をお願いいたします。					  
 
次に、パッケージのコンパイルを行います。ここではGNU makeコマンドを使用してコンパイルします。
コンパイルは、お使いのハードウェアスペックにより、数分から数十分を要しますので、完了までお待ちください。
  
    | 
      
        | [root@xxxxxx postgresql-16.3]# gmake   ・・(中略)
 ・
 gmake -C test/perl all
 gmake[2]: ディレクトリ `/usr/local/src/postgresql-16.3/src/test/perl' に入ります
 gmake[2]: `all' に対して行うべき事はありません.
 gmake[2]: ディレクトリ `/usr/local/src/postgresql-16.3/src/test/perl' から出ます
 gmake[1]: ディレクトリ `/usr/local/src/postgresql-16.3/src' から出ます
 gmake -C config all
 gmake[1]: ディレクトリ `/usr/local/src/postgresql-16.3/config' に入ります
 gmake[1]: `all' に対して行うべき事はありません.
 gmake[1]: ディレクトリ `/usr/local/src/postgresql-16.3/config' から出ます
 [root@xxxxxx postgresql-16.3]#
 |  | 
 
コンパイルが完了したら、インストールを行う前に、PostgreSQLが正しく動作するかを検証するためにリグレッションテストを行います。
リグレッションテストは、rootユーザーでは実行することができませんので、rootユーザー以外のユーザーにスイッチします。(ここでは「guest」ユーザーで実行します。)
  
    | 
      
        | [root@xxxxxx postgresql-16.3]# su guest [guest@xxxxxx postgresql-16.3]# gmake check・
 ・(中略)
 ・
 ok 211       + stats                                    2356 ms
 # parallel group (2 tests):  event_trigger oidjoins
 ok 212       + event_trigger                             131 ms
 ok 213       + oidjoins                                  251 ms
 ok 214       - fast_default                               76 ms
 ok 215       - tablespace                                191 ms
 1..215
 # All 215 tests passed.
 gmake[1]: ディレクトリ '/usr/local/src/postgresql-16.3/src/test/regress' から出ます
 [guest@xxxxxx postgresql-16.3]#
 |  | 
"All 215 tests passed."が表示されればテストが正しく完了していますので、インストールを行います。
インストールは、rootユーザーで行います。先ほどスイッチした「guest」ユーザーから戻します。
  
    | 
      
        | [guest@xxxxxx postgresql-16.3]# exit [root@xxxxxx postgresql-16.3]# gmake install・
 ・(中略)
 ・
 gmake -C config install
 gmake[1]: ディレクトリ `/usr/local/src/postgresql-16.3/config' に入ります
 /usr/bin/mkdir -p '/usr/local/pgsql16.3/lib/pgxs/config'
 /usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql16.3/lib/pgxs/config/install-sh'
 /usr/bin/install -c -m 755 ./missing '/usr/local/pgsql16.3/lib/pgxs/config/missing'
 gmake[1]: ディレクトリ `/usr/local/src/postgresql-16.3/config' から出ます
 [root@xxxxxx postgresql-16.3]#
 |  | 
 
"gmake[1]: /usr/bin/install -c -m 755 ./missing '/usr/local/pgsql16.3/lib/pgxs/config/missing'"が表示されればインストールは完了です。
次に、ファイル内検索オプションを利用するために、PostgreSQLの"dblink"機能をコンパイルします。引き続き、rootユーザーで実行します。
  
    | 
      
        | [root@xxxxxx postgresql-16.3]# cd contrib/dblink  [root@xxxxxx dblink]# gmake  ・・(中略)
 ・
 gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I../../src/interfaces/libpq -I. -I. -I../../src/include  -D_GNU_SOURCE   -c -o dblink.o dblink.c
 gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -shared -o dblink.so  dblink.o -L../../src/port -L../../src/common -L../../src/interfaces/libpq -lpq   -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql16.3/lib',--enable-new-dtags
 
 [root@xxxxxx dblink]# |  | 
 
"dblink"機能のコンパイル完了後、インストールを行います。
  
    | 
      
        | 
            [root@xxxxxx dblink]# gmake install [root@xxxxxx dblink]# cd ../.. [root@xxxxxx postgresql-16.3]# |  | 
 
以上で"dblink"機能のインストールは完了です。
 
最後に、パッケージのコンパイルで生成されたオブジェクトファイルを削除することで、使用しているディスク容量を空けることができますので、必要に応じて実行してください。
  
    | 
      
        | [root@xxxxxx postgresql-16.3]# gmake clean |  | 
 
3.データベース管理ユーザーの設定
postgresユーザーの環境変数に、PostgreSQLコマンドまでのパスを通します。これにより、作成した"postgres"ユーザーが、PostgreSQLデータベース管理コマンドなどを実行することができるようになります。
viコマンドで「.bash_profile」を開き、PATH変数を編集します。
  
    | 
      
        | [root@xxxxxx postgresql-16.3]# cd /home/postgres [root@xxxxxx postgresql-16.3]# vi .bash_profile |  | 
以下のパスを環境変数「PATH」に追加設定してください。
  
    | 
      
        | 
# .bash_profile
 # Get the aliases and functions
 if [ -f ~/.bashrc ]; then
 . ~/.bashrc
 fi
 
 # User specific environment and startup programs
 
 PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin ←ここをpgsql16.3に変更
 
 export PATH
 
 
 |  | 
編集が完了したら、viコマンドの":wq"(保存して閉じる)を実行してください。
 
4.データベースクラスターの初期化
PostgreSQLのデータベースクラスターの初期化を行います。
データベース格納先のディレクトリを作成し、"postgres"ユーザーをディレクトリオーナーに設定します。
  
    | 
      
        | [root@xxxxxx postgres]# mkdir -p /var/pgsql16.3/data [root@xxxxxx postgres]# chown -R postgres:postgres /var/pgsql16.3
 |  | 
次に、"postgres"ユーザーにスイッチして、データベースクラスターを初期化します。
ここでは、先に作成した"/var/pgsql16.3/data"をデータベースファイル格納先として指定します。
  
    | 
      
        | [root@xxxxxx postgres]# su - postgres [postgres@xxxxxx postgres]# initdb --encoding=utf8 --locale=C -D /var/pgsql16.3/data ・ ・(中略) ・ Success. You can now start the database server using:
 pg_ctl -D /var/pgsql16.3/data -l logfile start
 
 
 [root@xxxxxx postgresql-16.3]# |  | 
 
PostgreSQLのport番号の変更を行います。
  
    | 
      
        | [postgres@xxxxxx postgres]$ cd /var/pgsql16.3/data [postgres@xxxxxx data]$ vi postgresql.conf |  | 
以下の設定を変更してください。
※portには過去のPostgreSQLのバージョンで使用していないポート番号を指定してください。
  
    | 
      
        | 
 
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
(中略)
#listen_addresses = 'localhost'         # 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)
port = 5435                             # (change requires restart)←使用していないポートを追加
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
 |  | 
編集が完了したら、viコマンドの":wq"(保存して閉じる)を実行してください。また、保存した内容を反映します。
 
ここまで完了すると、PostgreSQLデータベースを起動する準備が整いましたので、PostgreSQLを起動します。
  
    | 
      
        | [postgres@xxxxxx postgres]# pg_ctl -D /var/pgsql16.3/data -l logfile start waiting for server to start.... doneserver started
 
 [postgres@xxxxxx postgres]#   |  | 
正常に起動できたら、確認用のデータベースを作成し、接続確認しましょう。
※postgresql.confにportを5435以外を指定してPostgreSQLを起動した場合、読み替えて実行してください。
  
    | 
      
        | [postgres@xxxxxx postgres]# createdb test -p 5435 [postgres@xxxxxx postgres]# psql test -p 5435 psql (16.3) Type "help" for help.   test=#   |  | 
正常に接続できたら、データベース一覧(\lコマンド)を実行し、正しく作成できていることをご確認ください。
※作成した「test」データベースのCollate、Ctypeが"C"となっていない場合、desknet's NEOが正しく動作しない可能性がありますので、ご注意ください。(クラスターの初期化に誤りがある可能性があります。)
  
    | 
      
        | test=# \l                                                      List of databases
   Name    |  Owner   | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules |   Access privileges
-----------+----------+----------+-----------------+---------+-------+------------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | C       | C     |            |           |
 template0 | postgres | UTF8     | libc            | C       | C     |            |           | =c/postgres          +
           |          |          |                 |         |       |            |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | C       | C     |            |           | =c/postgres          +
           |          |          |                 |         |       |            |           | postgres=CTc/postgres
 test      | postgres | UTF8     | libc            | C       | C     |            |           |
(4 rows)
 test=#    |  | 
 
 
postgresユーザーのパスワードを設定します。
※この後、pg_hba.confファイルの設定を変更する為、postgresユーザーのパスワードが必要になります。
  
    | 
      
        | test=# alter role postgres with password 'postgres'; ALTER ROLE test=# |  | 
"psql"コマンドを終了するには\qを入力してください。
 
PostgreSQLの接続方法の変更を行います。
  
    | 
      
        | [postgres@xxxxxx postgres]$ cd /var/pgsql16.3/data [postgres@xxxxxx data]$ vi pg_hba.conf |  | 
以下の設定を変更してください。
  
    | 
      
        | # PostgreSQL Client Authentication Configuration File
# ===================================================
(中略)
# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     trust ←ここをmd5に変更
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust ←ここをmd5に変更
# IPv6 local connections:
host    all             all             ::1/128                 trust ←ここをmd5に変更
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                trust
#host    replication     postgres        127.0.0.1/32            trust
#host    replication     postgres        ::1/128                 trust
 |  | 
編集が完了したら、viコマンドの":wq"(保存して閉じる)を実行してください。また、保存した内容を反映します。
  
    | 
      
        | [postgres@xxxxxx data]$ pg_ctl -D /var/pgsql16.3/data reload  |  | 
 
ここまでで、PostgreSQLのインストールは完了です。
 
5.PostgreSQLサーバーの自動起動設定
サーバーのリブート時などに、PostgreSQLデータベースが自動的に起動するように設定しましょう。
systemdで自動起動を行うにはユニットファイルを作成して、systemctlコマンドで自動起動登録をします。
/etc/systemd/system/にユニットファイルpostgresql16.serviceを作成します。
viコマンドでエディタを開きます。
  
    | 
        
          | 
[root@localhost ~]# su -Password:
 [root@localhost ~]# cd /etc/systemd/system
 [root@localhost system]# vi postgresql16.service
 |  | 
以下の内容を入力します。
  
    | 
        
          | 
[Unit]Description=PostgreSQL database server
 
 [Service]
 Type=forking
 User=postgres
 PIDFile=/var/pgsql16.3/data/postmaster.pid
 OOMScoreAdjust=-1000
 ExecStart=/usr/local/pgsql16.3/bin/pg_ctl start -w -D /var/pgsql16.3/data/
 ExecReload= /bin/kill -HUP $MAINPID
 KillMode=mixed
 KillSignal=SIGINT
 TimeoutSec=0
 TimeoutStartSec=0
 TimeoutStopSec=1h
 
 [Install]
 WantedBy=multi-user.target
 |  | 
編集が完了したら、":wq"(保存して閉じる)を実行してください。
リロードしてユニットファイルを反映します。
  
    | 
        
          | 
[root@localhost ~]# systemctl daemon-reload
             |  | 
systemctlコマンドで作成したユニットファイルが反映されているかを確認します。
  
    | 
        
          | 
[root@localhost system]# systemctl status postgresql16○ postgresql16.service - PostgreSQL database server
 ・
 ・(中略)
 ・
 [root@localhost system]#
 |  | 
上記のように"PostgreSQL database server"と表示されていれば、作成したユニットファイルが正常に読み込まれています。
  
    | 
        
          | 
[root@localhost ~]# systemctl enable postgresql16Created symlink /etc/systemd/system/multi-user.target.wants/postgresql16.service → /etc/systemd/system
 /postgresql16.service.
 [root@localhost ~]#
 |  | 
 
以上で、PostgreSQLの自動起動の設定は完了です。
 
►続いて『desknet's NEOアップデートツールのインストールとデータベース構築』を行います。
 

						
							記載の製品名および商品名は、各社の商標、または登録商標です。