コンテンツにスキップ

PostgreSQLサービス

A pg_service.conf file allows to use an named alias for a PostgreSQL server connection. Instead of storing hostname, port, database name and more into the QGIS Project file, these can be stored separately. It is even possible to store username and password in a pg_service.conf file, to avoid having this stored in clear text in the QGIS Project.

PostgreSQLサービスについては、QGISドキュメントを参照してください。

QField - 直接接続

If you directly connect from QGIS to your database you can make use of a pg_service.conf file by placing it in the QField data folder. You can place your file either on the Internal Device Storage or on the SD Card Storage. You can check the path for the QField data folder in the bottom of the About QField screen in the app.

通常、Androidデバイスのパスは次のようになります: Android/data/ch.opengis.qfield/files/QField.

備考

.pg_service.confというファイル名の*NIXシステムとは異なり、Androidのファイル名はpg_service.confで、先頭のドット記号(.)はありません。

QFieldCloud

QFieldCloud support pg_service.conf configurations too. You need to configure your PostgreSQL layers with "Offline editing" cloud action and store your service settings on QFieldCloud Project's Secrets page.

QFieldCloudドキュメントのPostgreSQLサービスの設定方法を参照してください。

QGISとシークレットキーを使用してPostgreSQLに接続するためのpg_service.confファイルの作成

Before beginning, ensure that your PostgreSQL database allows connections from QFieldCloud. Refer to Technical specs for instructions.

pg_service.confファイルのセットアップ

We first need to set up a configuration file. There are many options to organize this, read more in the PostgreSQL documentation or follow the description below.

  1. 設定ファイルを作成する:

  2. Windowsの場合: pg_service.confという名前のファイルを作成し、使いやすい場所に保存します。

  3. Linux/MacOS/Unixの場合: ホームフォルダ (~) に .pg_service.conf という名前のファイルを作成します。

  4. 接続パラメータを定義する:

ファイル内で、PostgreSQLデータベースの接続パラメータを以下の書式で指定します:

[SERVICE_NAME]
host=your_host_or_ip
port=your_port
dbname=your_database_name
user=your_username
password=your_password

プレースホルダー (your_host_or_ipyour_portyour_database_nameyour_usernameyour_password) を実際の接続情報に置き換えて、ファイルを保存します。

パラメータ
パラメータ

Windows用の追加設定手順

  1. 環境変数の設定: QGISがpg_service.confを認識するようにするには、その場所を指す環境変数を作成します:

  2. 「このPC」または「マイコンピュータ」>「プロパティ」>「詳細システム設定」>「環境変数」に移動します。

  3. 新しい変数を追加する:
    • 変数名: PGSERVICEFILE
    • 変数の値: C:\Users\<YourUsername>\AppData\Roaming\postgresql\pg_service.conf (または pg_service.confのファイルパス).

Alternatively, you can set environment variables directly in QGIS via Settings > Options > System > Environment. Refer to QGIS System Settings for details.

QGISシステム環境変数
QGISシステム環境変数

  1. Test the Connection in QGIS: Open QGIS and set up a new PostgreSQL connection using the service name defined in pg_service.conf (e.g., [MY_QGIS_DB]) in the connection details. QGIS will read configuration from pg_service.conf automatically.

  2. QGISを開きます。

  3. 「レイヤー」 > 「レイヤーを追加」 > 「PostGISレイヤーを追加…」 に進みます。
  4. 「新規のPostGIS接続の作成」で、ドロップダウンメニューから「サービス」を選択します。
  5. 「サービス」フィールドにpg_service.confのサービス名(例:[NINJA_DB])を入力する。
  6. 「OK」をクリックすると、pg_service.confの設定を使ってPostgreSQLデータベースに接続します。

接続のテストをする
接続のテストをする

  1. Add Parameter to QFieldCloud Secrets: Navigate to the project's secrets page and copy the service directly from .pg_service.conf to the secret. Follow Secrets for guidance.

シークレットキーを追加する
シークレットキーを追加する