# PostgreSQL14へのアップグレード手順書

{% hint style="warning" %}
作業前に必ずバックアップを実施してください。
{% endhint %}

<div align="left"><figure><img src="/files/4Vqv2t5vXFtGWKR9ZZ0L" alt="" width="563"><figcaption></figcaption></figure></div>

## **必要なもの**

* 本手順
* PostgreSQLアップグレードモジュール

{% hint style="success" %}
【PostgreSQLアップグレードモジュール について】

下記「モジュールダウンロード（PostgreSQL\*\*用）」より、アップグレード先であるPostgreSQLバージョンのモジュールをダウンロードします。

解凍して展開されたToolsフォルダを 「C:\ConMas\Tools」 に上書きしてください。
{% endhint %}

{% hint style="info" %}

* [モジュールダウンロード（PostgreSQL14用）](https://cimtops-support.com/i-Reporter/ir_manuals/jp/manager/Tools14.zip)
* [モジュールダウンロード（PostgreSQL16用）](https://cimtops-support.com/i-Reporter/ir_manuals/jp/manager/Tools16.zip)
* [モジュールダウンロード（PostgreSQL18用）](https://cimtops-support.com/i-Reporter/ir_manuals/jp/manager/Tools18.zip)
  {% endhint %}

## **条件**

* PostgreSQL11で使用されている容量の倍以上の空き容量が必要。

  <div data-gb-custom-block data-tag="hint" data-style="success" class="hint hint-success"><p>別ディスク推奨。</p></div>

* バックアップダンプを出力できる領域があること。

  <div data-gb-custom-block data-tag="hint" data-style="success" class="hint hint-success"><p>出力先は外付けHDDでも可能です。</p></div>

* ConMas Serverバージョンはアップグレード先PostgreSQLのメジャーバージョンに対応したバージョン以上であること。

PostgreSQLに対応しているConMas Server のバージョンは以下の通りです。

* PostgreSQL12 : ConMas Server 8.0.21060 以上
* PostgreSQL13 : ConMas Server 8.0.22060 以上
* PostgreSQL14 : ConMas Server 8.1.23040 以上

{% hint style="warning" %}
【注意】

同一サーバー上にPostgreSQL14をインストールします。\
複数のPostgreSQLデータベースが存在する状態となるため、ポート番号に注意して作業を行ってください。
{% endhint %}

## **アップグレード手順**

**【手順概要】**

1. IIS停止。
2. PostgreSQL11のサービス停止。
3. 既存のサーバーにPostgreSQL14をインストール。
4. PostgreSQL14のサービス停止、11のサービス開始。
5. PostgreSQL11のバックアップダンプを取得する。
6. PostgreSQL11のサービスを停止し、PostgreSQL14のサービスを開始。
7. PostgreSQL14にデーターベースirepodbを生成する。
8. PostgreSQL14のデーターベースirepodbに5．で取得したダンプをリストアする。
9. Devertプログラムを入れ替える。
10. アプリケーション構成ファイルの変更。

**【手順】**

1. IISを停止します。\
   ※下記画像は WindowsServer2012R2 の例です。

   <div align="left"><figure><img src="/files/P1UKsSH9hNapMuYSRkQE" alt=""><figcaption></figcaption></figure></div>

   <br>
2. PostgreSQL11のサービスを停止します。

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>これを実施しないと、PostgreSQL14の既定ポート番号である5432ポートが選択できません。</p></div>

   \ <br>
3. 以下のファイルを実行し、既存のサーバーにPostgreSQL14をインストールします。\
   \
   C:\ConMas\Tools\db\postgresql-14.7-2-windows-x64.exe<br>

   <div align="left"><figure><img src="/files/tfXWIGbRhwX0Ed95FaG4" alt="" width="335"><figcaption></figcaption></figure></div>

   \
   インストールディレクトリを選択します。特別な理由がない限り以下とします。\
   C:\Program Files\PostgreSQL\14

   <div align="left"><figure><img src="/files/XuqnjtUhqv58rSGrxplq" alt="" width="404"><figcaption></figcaption></figure></div>

   <div data-gb-custom-block data-tag="hint" data-style="success" class="hint hint-success"><p>ここはPostgreSQL14のプログラムファイルが配置されるのみで、データーの格納場所ではありません。</p></div>

   \
   \
   「stack Buider」以外はチェックします。

   <div align="left"><figure><img src="/files/qt2UC64SLajBtNJQOQ6e" alt="" width="402"><figcaption></figcaption></figure></div>

   \
   データー格納先のディレクトリとなります。

   <div align="left"><figure><img src="/files/TkFEo3Fa9VSdozLTXoLv" alt="" width="400"><figcaption></figcaption></figure></div>

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>既存のPostgreSQLディレクトリには11版のデーターが格納されていますので、別の場所を指定します。</p><p>なお、データの格納場所のため容量が十分な場所を指定ししてください。</p></div>

   \
   \
   11の時と同じパスワードを指定します。

   <div align="left"><figure><img src="/files/9L7Ffysh4gu9JvbutnX5" alt="" width="400"><figcaption></figcaption></figure></div>

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>変更した場合、アプリケーション構成ファイル内の設定を変更します。</p></div>

   \
   \
   5432ポートを指定します。

   <div align="left"><figure><img src="/files/yLX3PoGwVioEVpAtGWRV" alt="" width="400"><figcaption></figcaption></figure></div>

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>変更する場合はアプリケーション構成ファイル内の設定を変更します。</p></div>

   \
   \
   「Advanced Options」にて、ローケルを「C」 に変更してください。

   <div align="left"><figure><img src="/files/cdXebXkUazWO5oVRI0US" alt="" width="400"><figcaption></figcaption></figure></div>

   <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>ドライブの指定ではなくロケールの指定になります。</p></div>

   <br>

   <div align="left"><figure><img src="/files/vC7aRTwlMia7HDOL6t9B" alt="" width="401"><figcaption></figcaption></figure></div>

   <div align="left"><figure><img src="/files/USMftI0LTq411OJz87Ve" alt="" width="403"><figcaption></figcaption></figure></div>

   <div align="left"><figure><img src="/files/Q8L6XbFHOXfBsecSHjaz" alt="" width="403"><figcaption></figcaption></figure></div>

   <div align="left"><figure><img src="/files/uFFOxTlsR95adPRfx0q9" alt="" width="403"><figcaption></figcaption></figure></div>

   <br>
4. PostgreSQL14のサービスを停止し、PostgreSQL11のサービスを開始します。\ <br>
5. PostgreSQL14のpg\_dumpを使用して、PostgreSQL11データーベースのバックアップダンプを取得します。\
   以下バッチを使用します。<br>

   \
   chcp 65001

   SET PGPASSWORD=cimtops

   SET PGPATH=C:\Program Files\PostgreSQL\14\bin\pg\_dump

   SET DUMPPATH=D:\db\temp\irepodb.dump

   SET LOGPATH=D:\db\temp\dump.log

   SET PORT=5432\
   \
   "%PGPATH%" -Fc -Z5 -c -h localhost -p %PORT% -U postgres -d irepodb -f %DUMPPATH% > %LOGPATH%\
   echo errorlevel=%ERRORLEVEL% >> %LOGPATH%<br>

   <table><thead><tr><th width="181">環境変数</th><th>設定値</th></tr></thead><tbody><tr><td>PGPASSWORD</td><td>PostgreSQL11のパスワード</td></tr><tr><td>PGPATH</td><td>"<strong>PostgreSQL14</strong>"pg_dump.exeのフルパス。</td></tr><tr><td>DUMPPATH</td><td>ダンプファイルを出力するフルパス</td></tr><tr><td>LOGPATH</td><td>実行ログを出力する場所をフルパスで入力</td></tr><tr><td>PORT</td><td><strong>PostgreSQL11のポート番号（既定では5432）</strong></td></tr></tbody></table>

   バッチを実行します。\
   ログ内容がErrorLevel=0であれば成功です。\ <br>
6. PostgreSQL11のサービスを停止し、PostgreSQL14のサービスを開始します。\ <br>
7. PostgreSQL14データーベース生成します。\
   以下バッチを使用します。

   <div data-gb-custom-block data-tag="hint" data-style="success" class="hint hint-success"><p>1.createdb.batファイルをご利用ください。</p></div>

   \
   chcp 65001

   SET PGPASSWORD=cimtops

   SET NEWDATABASE=irepodb

   SET PGPATH=C:\Program Files\PostgreSQL\14\bin\createdb

   SET LOGPATH=C:\xxxxx\1.createdb.log

   SET PORT=5432<br>

   "%PGPATH%" -h localhost -p %PORT% -U postgres %NEWDATABASE% 2> %LOGPATH%

   echo CreateDb ErrorLevel=%ERRORLEVEL% >> %LOGPATH%<br>

   <table><thead><tr><th width="172">環境変数</th><th>設定値</th></tr></thead><tbody><tr><td>PGPASSWORD</td><td>PostgreSQL14のパスワード</td></tr><tr><td>NEWDATABASE</td><td>irepodb</td></tr><tr><td>PGPATH</td><td>createdb.exeのフルパス。 <br>※Fig.2-2で設定したパスの先にあります。変更していない場合はそのまま</td></tr><tr><td>LOGPATH</td><td>実行ログを出力する場所をフルパスで入力</td></tr><tr><td>PORT</td><td><strong>PostgreSQL14のポート番号</strong></td></tr></tbody></table>

   バッチを実行します。\
   実行するとLOGPATHで設定したファイルができるのでメモ帳で成否を確認します。\
   ログ内容がErrorLevel=0であれば成功です。\ <br>
8. PostgreSQL14データーベースへのリストアを行います。\
   以下内容でバッチファイルを作成し、環境変数を環境に合わせて変更します。<br>

   chcp 65001

   SET PGPASSWORD=cimtops

   SET PGPATH=C:\Program Files\PostgreSQL\14\bin\pg\_restore

   SET DUMPPATH=C:\xxxxx\irepodb.dump

   SET LOGPATH=C:\xxxxx\dump.log

   SET PORT=5432<br>

   "%PGPATH%" -h localhost -U postgres -p %port% -d irepodb %DUMPPATH% > %LOGPATH% 2>&1

   echo Restore ErrorLevel=%ERRORLEVEL% >> %LOGPATH%

   <table><thead><tr><th width="168">環境変数</th><th>設定値</th></tr></thead><tbody><tr><td>PGPASSWORD</td><td><strong>PostgreSQL14</strong>のパスワード</td></tr><tr><td>PGPATH</td><td>"<strong>PostgreSQL14</strong>"pg_restore.exeのフルパス。</td></tr><tr><td>DUMPPATH</td><td>リストアするダンプファイルのフルパス</td></tr><tr><td>LOGPATH</td><td>実行ログを出力する場所をフルパスで入力</td></tr><tr><td>PORT</td><td><strong>PostgreSQL14のポート番号</strong></td></tr></tbody></table>

   バッチを実行します。\
   実行するとLOGPATHで設定したファイルができるのでメモ帳で成否を確認します。\
   ログ内容がErrorLevel=0であれば成功です。

   <div data-gb-custom-block data-tag="hint" data-style="success" class="hint hint-success"><p>ログの一番下にあります。</p></div>

   &#x20;\ <br>
9. 以下のファイルを実行し、dotConnectをインストールします。\
   **事前に、以前のバージョンのものをアンインストールします。**&#x43;:\ConMas\Tools\ap\dcpostgresqlfree7.24.2066.exe<br>

   <div align="left"><figure><img src="/files/VU372cvHBCrbjQzIQqpg" alt="" width="503"><figcaption><p><br></p></figcaption></figure></div>

   <div align="left"><figure><img src="/files/cRZyE5Y7Ju8x16Sow7km" alt="" width="510"><figcaption></figcaption></figure></div>

   <div align="left"><figure><img src="/files/LHnb9QLX2qjbsNHES3rW" alt="" width="478"><figcaption><p><br></p></figcaption></figure></div>

   SampleとHelpはチェックを外しても構いません。

   <div align="left"><figure><img src="/files/ZGpLgDCvN1L6zCByDB1U" alt="" width="479"><figcaption></figcaption></figure></div>

   <div align="left"><figure><img src="/files/w3cJtPkpCIaUDuwNJtCZ" alt="" width="475"><figcaption></figcaption></figure></div>

   <div align="left"><figure><img src="/files/nKM1mFdRARoEhf3HIbjb" alt="" width="482"><figcaption></figcaption></figure></div>

   <div align="left"><figure><img src="/files/HsgtdHI0qjw7x1ojnTHJ" alt="" width="476"><figcaption></figcaption></figure></div>

   <div align="left"><figure><img src="/files/jkB6ULNVgFIeeM6qUYBd" alt="" width="482"><figcaption></figcaption></figure></div>

   <br>
10. アプリケーション構成ファイルの変更を行います。

    <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>PostgreSQL14のポート番号を<strong>5432以外</strong>に変更した場合のみ実施します。</p></div>

    \
    ConMasAPI,ConMasManager,ConMasWebのweb.configを修正します。<br>

    <div align="left"><figure><img src="/files/hZYhF8Zc8O2zfeymmmEE" alt=""><figcaption></figcaption></figure></div>

    Port番号をPostgreSQL14の番号に切り替えます。

{% hint style="success" %}
【補足】

上記すべての作業を実施することで、PostgreSQL14アップグレードは完了です。

なお、過去のPostgreSQL11のプログラム、データーはそのまま残ります。\
破棄する場合は、以下手順を実施してください。

１．プログラムと機能より、PostgreSQL11をアンインストール\
２．PostgreSQL11を利用していたデーター格納ディレクトリを削除

※PostgreSQL14で動作確認、データー確認したのち、実施してください。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manuals.i-reporter.jp/server-construction-maintenance/maintenance/postgresql-upgrade-instructions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
