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.
-
設定ファイルを作成する:
-
Windowsの場合:
pg_service.conf
という名前のファイルを作成し、使いやすい場所に保存します。 -
Linux/MacOS/Unixの場合: ホームフォルダ (
~
) に.pg_service.conf
という名前のファイルを作成します。 -
接続パラメータを定義する:
ファイル内で、PostgreSQLデータベースの接続パラメータを以下の書式で指定します:
[SERVICE_NAME]
host=your_host_or_ip
port=your_port
dbname=your_database_name
user=your_username
password=your_password
プレースホルダー (your_host_or_ip
、your_port
、your_database_name
、your_username
、your_password
) を実際の接続情報に置き換えて、ファイルを保存します。
Windows用の追加設定手順¶
-
環境変数の設定: QGISが
pg_service.conf
を認識するようにするには、その場所を指す環境変数を作成します: -
「このPC」または「マイコンピュータ」>「プロパティ」>「詳細システム設定」>「環境変数」に移動します。
- 新しい変数を追加する:
- 変数名:
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.
-
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 frompg_service.conf
automatically. -
QGISを開きます。
- 「レイヤー」 > 「レイヤーを追加」 > 「PostGISレイヤーを追加…」 に進みます。
- 「新規のPostGIS接続の作成」で、ドロップダウンメニューから「サービス」を選択します。
- 「サービス」フィールドに
pg_service.conf
のサービス名(例:[NINJA_DB]
)を入力する。 - 「OK」をクリックすると、
pg_service.conf
の設定を使ってPostgreSQLデータベースに接続します。
- 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.